Example #1
0
                $arResult["urlToFriends"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER_FRIENDS"], array("user_id" => $user_id));
                $arResult["urlToOwnNewPost"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_POST_EDIT"], array("blog" => $arOwnBlog["URL"], "post_id" => "new"));
                $arResult["urlToOwnBlogEdit"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG_EDIT"], array("blog" => $arOwnBlog["URL"]));
            }
        } else {
            unset($arOwnBlog);
        }
    } else {
        unset($arOwnBlog);
    }
}
if (strlen($arParams["BLOG_URL"]) > 0) {
    if ($arOwnBlog["URL"] != $arParams["BLOG_URL"]) {
        $arBlog = CBlog::GetByUrl($arParams["BLOG_URL"], $arParams["GROUP_ID"]);
        if ($arBlog["ACTIVE"] == "Y") {
            $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
            if ($arGroup["SITE_ID"] == SITE_ID) {
                $arResult["Blog"] = $arBlog;
                $arResult["urlToCurrentBlog"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG"], array("blog" => $arParams["BLOG_URL"]));
            } else {
                unset($arBlog);
            }
        } else {
            unset($arBlog);
        }
    } elseif (!empty($arOwnBlog)) {
        $arBlog = $arOwnBlog;
    }
    if (!empty($arBlog)) {
        if (IntVal($user_id) > 0) {
            $perm = CBlog::GetBlogUserPostPerms($arBlog["ID"], $user_id);
Example #2
0
	function Update($ID, $arFields, $bSearchIndex = true)
	{
		global $DB;

		$ID = IntVal($ID);
		if(strlen($arFields["PATH"]) > 0)
			$arFields["PATH"] = str_replace("#post_id#", $ID, $arFields["PATH"]);

		$arFields1 = array();
		foreach ($arFields as $key => $value)
		{
			if (substr($key, 0, 1) == "=")
			{
				$arFields1[substr($key, 1)] = $value;
				unset($arFields[$key]);
			}
		}

		if (!CBlogPost::CheckFields("UPDATE", $arFields, $ID))
			return false;
		elseif(!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("BLOG_POST", $ID, $arFields))
			return false;

		foreach(GetModuleEvents("blog", "OnBeforePostUpdate", true) as $arEvent)
		{
			if (ExecuteModuleEventEx($arEvent, Array($ID, &$arFields))===false)
				return false;
		}

		$arOldPost = CBlogPost::GetByID($ID);

		if(is_array($arFields["ATTACH_IMG"]))
		{
			if (
				!array_key_exists("MODULE_ID", $arFields["ATTACH_IMG"])
				|| strlen($arFields["ATTACH_IMG"]["MODULE_ID"]) <= 0
			)
				$arFields["ATTACH_IMG"]["MODULE_ID"] = "blog";

			$prefix = "blog";
			if(strlen($arFields["URL"]) > 0)
				$prefix .= "/".$arFields["URL"];
			CFile::SaveForDB($arFields, "ATTACH_IMG", $prefix);
		}

		$strUpdate = $DB->PrepareUpdate("b_blog_post", $arFields);

		foreach ($arFields1 as $key => $value)
		{
			if (strlen($strUpdate) > 0)
				$strUpdate .= ", ";
			$strUpdate .= $key."=".$value." ";
		}

		if (strlen($strUpdate) > 0)
		{
			$oldPostPerms = CBlogUserGroup::GetGroupPerms(1, $arOldPost["BLOG_ID"], $ID, BLOG_PERMS_POST);

			$strSql =
				"UPDATE b_blog_post SET ".
				"	".$strUpdate." ".
				"WHERE ID = ".$ID." ";
			$DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__);

			unset($GLOBALS["BLOG_POST"]["BLOG_POST_CACHE_".$ID]);

			foreach(GetModuleEvents("blog", "OnBeforePostUserFieldUpdate", true) as $arEvent)
				ExecuteModuleEventEx($arEvent, Array("BLOG_POST", $ID, $arFields));

			$GLOBALS["USER_FIELD_MANAGER"]->Update("BLOG_POST", $ID, $arFields);
		}
		else
		{
			$ID = False;
		}

		if ($ID)
		{
			$arNewPost = CBlogPost::GetByID($ID);
			if($arNewPost["PUBLISH_STATUS"] != $arOldPost["PUBLISH_STATUS"]  || $arNewPost["BLOG_ID"] != $arOldPost["BLOG_ID"])
				CBlog::SetStat($arNewPost["BLOG_ID"]);

			if ($arNewPost["BLOG_ID"] != $arOldPost["BLOG_ID"])
				CBlog::SetStat($arOldPost["BLOG_ID"]);

			if (is_set($arFields, "PERMS_POST"))
				CBlogPost::SetPostPerms($ID, $arFields["PERMS_POST"], BLOG_PERMS_POST);
			if (is_set($arFields, "PERMS_COMMENT"))
				CBlogPost::SetPostPerms($ID, $arFields["PERMS_COMMENT"], BLOG_PERMS_COMMENT);

			if(array_key_exists("SOCNET_RIGHTS", $arFields))
			{
				$arFields["SC_PERM_OLD"] = CBlogPost::GetSocNetPermsCode($ID);
				$arFields["SC_PERM"] = CBlogPost::UpdateSocNetPerms($ID, $arFields["SOCNET_RIGHTS"], $arNewPost);
			}

			foreach(GetModuleEvents("blog", "OnPostUpdate", true) as $arEvent)
				ExecuteModuleEventEx($arEvent, Array($ID, &$arFields));

			if ($bSearchIndex && CModule::IncludeModule("search"))
			{
				$newPostPerms = CBlogUserGroup::GetGroupPerms(1, $arNewPost["BLOG_ID"], $ID, BLOG_PERMS_POST);
				$arBlog = CBlog::GetByID($arNewPost["BLOG_ID"]);

				if (
					$arOldPost["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH &&
					$oldPostPerms >= BLOG_PERMS_READ
					&& (
						$arNewPost["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH ||
						$newPostPerms < BLOG_PERMS_READ
						)
					|| $arBlog["SEARCH_INDEX"] != "Y"
					)
				{
					CSearch::Index("blog", "P".$ID,
						array(
							"TITLE" => "",
							"BODY" => ""
						)
					);
					CSearch::DeleteIndex("blog", false, "COMMENT", $arBlog["ID"]."|".$ID);
				}
				elseif (
					$arNewPost["DATE_PUBLISHED"] == "Y"
					&& $arNewPost["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH
					&& $newPostPerms >= BLOG_PERMS_READ
					&& $arBlog["SEARCH_INDEX"] == "Y"
					)
				{
					$tag = "";
					$arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
					if(strlen($arFields["PATH"]) > 0)
					{
						$arPostSite = array($arGroup["SITE_ID"] => $arFields["PATH"]);
					}
					elseif(strlen($arNewPost["PATH"]) > 0)
					{
						$arNewPost["PATH"] = (
							strlen($arNewPost["CODE"]) > 0 
								? str_replace("#post_id#", $arNewPost["CODE"], $arNewPost["PATH"]) 
								: str_replace("#post_id#", $ID, $arNewPost["PATH"])
						);
						$arPostSite = array($arGroup["SITE_ID"] => $arNewPost["PATH"]);
					}
					else
					{
						$arPostSite = array(
							$arGroup["SITE_ID"] => CBlogPost::PreparePath(
									$arBlog["URL"],
									$arNewPost["ID"],
									$arGroup["SITE_ID"],
									false,
									$arBlog["OWNER_ID"],
									$arBlog["SOCNET_GROUP_ID"]
								)
						);
					}

					if (
						$arBlog["USE_SOCNET"] == "Y" 
						&& CModule::IncludeModule("extranet")
					)
					{
						$arPostSiteExt = CExtranet::GetSitesByLogDestinations($arFields["SC_PERM"]);
						foreach($arPostSiteExt as $lid)
						{
							if (!array_key_exists($lid, $arPostSite))
							{
								$arPostSite[$lid] = str_replace(
									array("#user_id#", "#post_id#"), 
									array($arBlog["OWNER_ID"], $arNewPost["ID"]), 
									COption::GetOptionString("socialnetwork", "userblogpost_page", false, $lid)
								);
							}
						}
					}

					if(strlen($arNewPost["CATEGORY_ID"])>0)
					{
						$arC = explode(",", $arNewPost["CATEGORY_ID"]);
						$arTag = Array();
						foreach($arC as $v)
						{
							$arCategory = CBlogCategory::GetByID($v);
							$arTag[] = $arCategory["NAME"];
						}
						$tag =  implode(",", $arTag);
					}

					$searchContent = blogTextParser::killAllTags($arNewPost["DETAIL_TEXT"]);
					$searchContent .= "\r\n" . $GLOBALS["USER_FIELD_MANAGER"]->OnSearchIndex("BLOG_POST", $arNewPost["ID"]);

					$authorName = "";
					if(IntVal($arNewPost["AUTHOR_ID"]) > 0)
					{
						$dbUser = CUser::GetByID($arNewPost["AUTHOR_ID"]);
						if($arUser = $dbUser->Fetch())
						{
							$arTmpUser = array(
									"NAME" => $arUser["NAME"],
									"LAST_NAME" => $arUser["LAST_NAME"],
									"SECOND_NAME" => $arUser["SECOND_NAME"],
									"LOGIN" => $arUser["LOGIN"],
								);
							$authorName = CUser::FormatName(CSite::GetNameFormat(), $arTmpUser, false, false);
							if(strlen($authorName) > 0)
								$searchContent .= "\r\n".$authorName;
						}
					}

					$arSearchIndex = array(
						"SITE_ID" => $arPostSite,
						"LAST_MODIFIED" => $arNewPost["DATE_PUBLISH"],
						"PARAM1" => "POST",
						"PARAM2" => $arNewPost["BLOG_ID"],
						"PARAM3" => $arNewPost["ID"],
						"PERMISSIONS" => array(2),
						"TITLE" => $arNewPost["TITLE"],
						"BODY" => $searchContent,
						"TAGS" => $tag,
						"USER_ID" => $arNewPost["AUTHOR_ID"],
						"ENTITY_TYPE_ID" => "BLOG_POST",
						"ENTITY_ID" => $arNewPost["ID"],
					);

					$bIndexComment = false;
					if($arBlog["USE_SOCNET"] == "Y")
					{
						if(!empty($arFields["SC_PERM"]))
						{
							$arSearchIndex["PERMISSIONS"] = $arFields["SC_PERM"];
							if($arFields["SC_PERM"] != $arFields["SC_PERM_OLD"])
								$bIndexComment = true;
						}
						else
							$arSearchIndex["PERMISSIONS"] = CBlogPost::GetSocnetPermsCode($ID);

						if(!in_array("U".$arNewPost["AUTHOR_ID"], $arSearchIndex["PERMISSIONS"]))
							$arSearchIndex["PERMISSIONS"][] = "U".$arNewPost["AUTHOR_ID"];

						if(is_array($arSearchIndex["PERMISSIONS"]))
						{
							$sgId = array();
							foreach($arSearchIndex["PERMISSIONS"] as $perm)
							{
								if(strpos($perm, "SG") !== false)
								{
									$sgIdTmp = str_replace("SG", "", substr($perm, 0, strpos($perm, "_")));
									if(!in_array($sgIdTmp, $sgId) && IntVal($sgIdTmp) > 0)
										$sgId[] = $sgIdTmp;
								}
							}

							if(!empty($sgId))
							{
								$arSearchIndex["PARAMS"] = array(
									"socnet_group" => $sgId,
									"entity" => "socnet_group",
								);
							}
						}

						// get mentions and grats
						$arMentionedUserID = CBlogPost::GetMentionedUserID($arNewPost);
						if (!empty($arMentionedUserID))
						{
							if (!isset($arSearchIndex["PARAMS"]))
							{
								$arSearchIndex["PARAMS"] = array();
							}
							$arSearchIndex["PARAMS"]["mentioned_user_id"] = $arMentionedUserID;
						}
					}

					CSearch::Index("blog", "P".$ID, $arSearchIndex, True);

					if(($arOldPost["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH && $arNewPost["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH) || $bIndexComment) //index comments
					{
						$arParamsComment = Array(
							"BLOG_ID" => $arBlog["ID"],
							"POST_ID" => $ID,
							"SITE_ID" => $arGroup["SITE_ID"],
							"PATH" => $arPostSite[$arGroup["SITE_ID"]]."?commentId=#comment_id###comment_id#",
							"BLOG_URL" => $arBlog["URL"],
							"OWNER_ID" => $arBlog["OWNER_ID"],
							"SOCNET_GROUP_ID" => $arBlog["SOCNET_GROUP_ID"],
							"USE_SOCNET" => $arBlog["USE_SOCNET"],
						);

						CBlogComment::_IndexPostComments($arParamsComment);
					}
				}
			}
		}

		BXClearCache(true, '/blog/socnet_post/gen/'.$ID);

		return $ID;
	}
Example #3
0
}
$arParams["PATH_TO_BLOG"] = trim($arParams["PATH_TO_BLOG"]);
if (strlen($arParams["PATH_TO_BLOG"]) <= 0) {
    $arParams["PATH_TO_BLOG"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=blog&" . $arParams["BLOG_VAR"] . "=#blog#");
}
$arParams["PATH_TO_POST"] = trim($arParams["PATH_TO_POST"]);
if (strlen($arParams["PATH_TO_POST"]) <= 0) {
    $arParams["PATH_TO_POST"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=post&" . $arParams["BLOG_VAR"] . "=#blog#&" . $arParams["POST_VAR"] . "=#post_id#");
}
$arParams["PATH_TO_USER"] = trim($arParams["PATH_TO_USER"]);
if (strlen($arParams["PATH_TO_USER"]) <= 0) {
    $arParams["PATH_TO_USER"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=user&" . $arParams["USER_VAR"] . "=#user_id#");
}
$arParams["DATE_TIME_FORMAT"] = trim(empty($arParams["DATE_TIME_FORMAT"]) ? $DB->DateFormatToPHP(CSite::GetDateFormat("FULL")) : $arParams["DATE_TIME_FORMAT"]);
if (empty($arParams["GROUP_ID"]) || !empty($arParams["GROUP_ID"]) && in_array($arParams["ID"], $arParams["GROUP_ID"]) || $bShowAll) {
    $arGroup = CBlogGroup::GetByID($arParams["ID"]);
    if (!empty($arGroup) || $bShowAll) {
        $arGroup = CBlogTools::htmlspecialcharsExArray($arGroup);
        $arResult["GROUP"] = $arGroup;
        if ($arParams["SET_TITLE"] == "Y") {
            if ($bShowAll) {
                $APPLICATION->SetTitle(GetMessage("B_B_GR_TITLE"));
            } else {
                $APPLICATION->SetTitle(GetMessage("B_B_GR_TITLE_NAME", array("#group#" => $arGroup["NAME"])));
            }
        }
        $cache = new CPHPCache();
        $cache_id = "blog_groups_" . serialize($arParams) . "_" . CDBResult::NavStringForCache($arParams["BLOG_COUNT"]);
        if (($tzOffset = CTimeZone::GetOffset()) != 0) {
            $cache_id .= "_" . $tzOffset;
        }
Example #4
0
	public static function Update($ID, $arFields, $bSearchIndex = true)
	{
		global $DB;

		$ID = IntVal($ID);
		
		if(strlen($arFields["PATH"]) > 0)
			$arFields["PATH"] = str_replace("#comment_id#", $ID, $arFields["PATH"]);

		$arFields1 = array();
		foreach ($arFields as $key => $value)
		{
			if (substr($key, 0, 1) == "=")
			{
				$arFields1[substr($key, 1)] = $value;
				unset($arFields[$key]);
			}
		}

		if (!CBlogComment::CheckFields("UPDATE", $arFields, $ID))
			return false;
		elseif(!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("BLOG_COMMENT", $ID, $arFields))
			return false;

		foreach(GetModuleEvents("blog", "OnBeforeCommentUpdate", true) as $arEvent)
		{
			if (ExecuteModuleEventEx($arEvent, Array($ID, &$arFields))===false)
				return false;
		}

		$strUpdate = $DB->PrepareUpdate("b_blog_comment", $arFields);

		foreach ($arFields1 as $key => $value)
		{
			if (strlen($strUpdate) > 0)
				$strUpdate .= ", ";
			$strUpdate .= $key."=".$value." ";
		}

		if (strlen($strUpdate) > 0)
		{
			if(is_set($arFields["PUBLISH_STATUS"]) && strlen($arFields["PUBLISH_STATUS"]) > 0)
			{
				$arComment = CBlogComment::GetByID($ID);
				if($arComment["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $arFields["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH)
					CBlogPost::Update($arComment["POST_ID"], array("=NUM_COMMENTS" => "NUM_COMMENTS - 1"));
				elseif($arComment["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH && $arFields["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH)
					CBlogPost::Update($arComment["POST_ID"], array("=NUM_COMMENTS" => "NUM_COMMENTS + 1"));
			}
			
			$strSql =
				"UPDATE b_blog_comment SET ".
				"	".$strUpdate." ".
				"WHERE ID = ".$ID." ";
			$DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__);
			unset($GLOBALS["BLOG_COMMENT"]["BLOG_COMMENT_CACHE_".$ID]);
			
			$GLOBALS["USER_FIELD_MANAGER"]->Update("BLOG_COMMENT", $ID, $arFields);

			$arComment = CBlogComment::GetByID($ID);			
			$arBlog = CBlog::GetByID($arComment["BLOG_ID"]);
			if($arBlog["USE_SOCNET"] == "Y")
				$arFields["SC_PERM"] = CBlogComment::GetSocNetCommentPerms($arComment["POST_ID"]);

			foreach(GetModuleEvents("blog", "OnCommentUpdate", true) as $arEvent)
				ExecuteModuleEventEx($arEvent, Array($ID, &$arFields));
			
			if ($bSearchIndex && CModule::IncludeModule("search"))
			{
				$newPostPerms = CBlogUserGroup::GetGroupPerms(1, $arComment["BLOG_ID"], $arComment["POST_ID"], BLOG_PERMS_POST);
				
				if ($arBlog["SEARCH_INDEX"] != "Y" || $arComment["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH)
				{
					CSearch::Index("blog", "C".$ID,
						array(
							"TITLE" => "",
							"BODY" => ""
						)
					);
				}
				else
				{
					$arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);

					if(strlen($arFields["PATH"]) > 0)
					{
						$arFields["PATH"] = str_replace("#comment_id#", $ID, $arFields["PATH"]);
						$arPostSite = array($arGroup["SITE_ID"] => $arFields["PATH"]);
					}
					elseif(strlen($arComment["PATH"]) > 0)
					{
						$arComment["PATH"] = str_replace("#comment_id#", $ID, $arComment["PATH"]);
						$arPostSite = array($arGroup["SITE_ID"] => $arComment["PATH"]);
					}
					else
					{
						$arPostSite = array(
							$arGroup["SITE_ID"] => CBlogPost::PreparePath(
									$arBlog["URL"],
									$arComment["POST_ID"],
									$arGroup["SITE_ID"],
									false,
									$arBlog["OWNER_ID"],
									$arBlog["SOCNET_GROUP_ID"]
								)
						);
					}

					$searchContent = blogTextParser::killAllTags($arComment["POST_TEXT"]);
					$searchContent .= "\r\n" . $GLOBALS["USER_FIELD_MANAGER"]->OnSearchIndex("BLOG_COMMENT", $arComment["ID"]);

					$arSearchIndex = array(
						"SITE_ID" => $arPostSite,
						"LAST_MODIFIED" => $arComment["DATE_CREATE"],
						"PARAM1" => "COMMENT",
						"PARAM2" => $arComment["BLOG_ID"]."|".$arComment["POST_ID"],
						"PERMISSIONS" => array(2),
						"TITLE" => $arComment["TITLE"],
						"BODY" => $searchContent,
						"USER_ID" => (IntVal($arComment["AUTHOR_ID"]) > 0) ? $arComment["AUTHOR_ID"] : false,
						"ENTITY_TYPE_ID" => "BLOG_COMMENT",
						"ENTITY_ID" => $arComment["ID"],
					);

					if($arBlog["USE_SOCNET"] == "Y")
					{
						if(is_array($arFields["SC_PERM"]))
						{
							$arSearchIndex["PERMISSIONS"] = $arFields["SC_PERM"];
							$sgId = array();
							foreach($arFields["SC_PERM"] as $perm)
							{
								if(strpos($perm, "SG") !== false)
								{
									$sgIdTmp = str_replace("SG", "", substr($perm, 0, strpos($perm, "_")));
									if(!in_array($sgIdTmp, $sgId) && IntVal($sgIdTmp) > 0)
										$sgId[] = $sgIdTmp;
								}
							}

							if(!empty($sgId))
							{
								$arSearchIndex["PARAMS"] = array(
									"socnet_group" => $sgId,
									"entity" => "socnet_group",
								);
							}
							if(!in_array("U".$arComment["AUTHOR_ID"], $arSearchIndex["PERMISSIONS"]))
								$arSearchIndex["PERMISSIONS"][] = "U".$arComment["AUTHOR_ID"];
						}
					}

					if(strlen($arComment["TITLE"]) <= 0)
					{
						//$arPost = CBlogPost::GetByID($arComment["POST_ID"]);
						$arSearchIndex["TITLE"] = substr($arSearchIndex["BODY"], 0, 100);
					}

					CSearch::Index("blog", "C".$ID, $arSearchIndex, True);
				}
			}

			return $ID;
		}

		return False;
	}
Example #5
0
	public static function BuildRSS($postID, $blogID, $type = "RSS2.0", $numPosts = 10, $arPathTemplate = Array())
	{
		$blogID = IntVal($blogID);
		$postID = IntVal($postID);
		if($blogID <= 0)
			return false;
		if($postID <= 0)
			return false;
		$numPosts = IntVal($numPosts);
		$type = strtolower(preg_replace("/[^a-zA-Z0-9.]/is", "", $type));
		if ($type != "rss.92" && $type != "atom.03")
			$type = "rss2.0";

		$rssText = False;

		$arBlog = CBlog::GetByID($blogID);
		if ($arBlog && $arBlog["ACTIVE"] == "Y" && $arBlog["ENABLE_RSS"] == "Y")
		{
			$arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
			if($arGroup["SITE_ID"] == SITE_ID)
			{
				$arPost = CBlogPost::GetByID($postID);
				if(!empty($arPost) && $arPost["BLOG_ID"] == $arBlog["ID"] && $arPost["ENABLE_COMMENTS"] == "Y")
				{
					$now = date("r");
					$nowISO = date("Y-m-d\TH:i:s").substr(date("O"), 0, 3).":".substr(date("O"), -2, 2);

					$serverName = "";
					$charset = "";
					$language = "";
					$dbSite = CSite::GetList(($b = "sort"), ($o = "asc"), array("LID" => SITE_ID));
					if ($arSite = $dbSite->Fetch())
					{
						$serverName = $arSite["SERVER_NAME"];
						$charset = $arSite["CHARSET"];
						$language = $arSite["LANGUAGE_ID"];
					}

					if (strlen($serverName) <= 0)
					{
						if (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0)
							$serverName = SITE_SERVER_NAME;
						else
							$serverName = COption::GetOptionString("main", "server_name", "");
					}

					if (strlen($charset) <= 0)
					{
						if (defined("SITE_CHARSET") && strlen(SITE_CHARSET) > 0)
							$charset = SITE_CHARSET;
						else
							$charset = "windows-1251";
					}

					if(strlen($arPathTemplate["PATH_TO_BLOG"])>0)
						$blogURL = htmlspecialcharsbx("http://".$serverName.CComponentEngine::MakePathFromTemplate($arPathTemplate["PATH_TO_BLOG"], array("blog" => $arBlog["URL"], "user_id" => $arBlog["OWNER_ID"], "group_id" => $arBlog["SOCNET_GROUP_ID"])));
					else
						$blogURL = htmlspecialcharsbx("http://".$serverName.CBlog::PreparePath($arBlog["URL"], $arGroup["SITE_ID"]));

					if(strlen($arPathTemplate["PATH_TO_POST"])>0)
						$url = htmlspecialcharsbx("http://".$serverName.CComponentEngine::MakePathFromTemplate($arPathTemplate["PATH_TO_POST"], array("blog" => $arBlog["URL"], "post_id" => CBlogPost::GetPostID($arPost["ID"], $arPost["CODE"], $arPathTemplate["ALLOW_POST_CODE"]), "user_id" => $arBlog["OWNER_ID"], "group_id" => $arBlog["SOCNET_GROUP_ID"])));
					else
						$url = htmlspecialcharsbx("http://".$serverName.CBlogPost::PreparePath($arBlog["URL"], $arPost["ID"], $arGroup["SITE_ID"]));

					$dbUser = CUser::GetByID($arPost["AUTHOR_ID"]);
					$arUser = $dbUser->Fetch();

					if($arPathTemplate["USE_SOCNET"] == "Y")
					{
						$blogName = GetMessage("BLG_GCM_RSS_TITLE_SOCNET", Array("#AUTHOR_NAME#" => htmlspecialcharsEx($arUser["NAME"]." ".$arUser["LAST_NAME"]), "#POST_TITLE#" => htmlspecialcharsEx($arPost["TITLE"])));
					}
					else
					{
						$blogName = GetMessage("BLG_GCM_RSS_TITLE", Array("#BLOG_NAME#" => htmlspecialcharsEx($arBlog["NAME"]), "#POST_TITLE#" => htmlspecialcharsEx($arPost["TITLE"])));
					}

					$rssText = "";
					if ($type == "rss.92")
					{
						$rssText .= "<"."?xml version=\"1.0\" encoding=\"".$charset."\"?".">\n\n";
						$rssText .= "<rss version=\".92\">\n";
						$rssText .= " <channel>\n";
						$rssText .= "	<title>".$blogName."</title>\n";
						$rssText .= "	<description>".$blogName."</description>\n";
						$rssText .= "	<link>".$url."</link>\n";
						$rssText .= "	<language>".$language."</language>\n";
						$rssText .= "	<docs>http://backend.userland.com/rss092</docs>\n";
						$rssText .= "\n";
					}
					elseif ($type == "rss2.0")
					{
						$rssText .= "<"."?xml version=\"1.0\" encoding=\"".$charset."\"?".">\n\n";
						$rssText .= "<rss version=\"2.0\">\n";
						$rssText .= " <channel>\n";
						$rssText .= "	<title>".$blogName."</title>\n";
						$rssText .= "	<description>".$blogName."</description>\n";
						//$rssText .= "	<guid>".$url."</guid>\n";
						$rssText .= "	<link>".$url."</link>\n";
						$rssText .= "	<language>".$language."</language>\n";
						$rssText .= "	<docs>http://backend.userland.com/rss2</docs>\n";
						$rssText .= "	<pubDate>".$now."</pubDate>\n";
						$rssText .= "\n";
					}
					elseif ($type == "atom.03")
					{
						$atomID = "tag:".htmlspecialcharsbx($serverName).",".date("Y-m-d").":".$postID;

						$rssText .= "<"."?xml version=\"1.0\" encoding=\"".$charset."\"?".">\n\n";
						$rssText .= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\" xml:lang=\"".$language."\">\n";
						$rssText .= "  <title>".$blogName."</title>\n";
						$rssText .= "  <tagline>".$url."</tagline>\n";
						$rssText .= "  <id>".$atomID."</id>\n";
						$rssText .= "  <link rel=\"alternate\" type=\"text/html\" href=\"".$url."\" />\n";
						$rssText .= "  <modified>".$nowISO."</modified>\n";

						$BlogUser = CBlogUser::GetByID($arPost["AUTHOR_ID"], BLOG_BY_USER_ID);
						$authorP = htmlspecialcharsex(CBlogUser::GetUserName($BlogUser["ALIAS"], $arUser["NAME"], $arUser["LAST_NAME"], $arUser["LOGIN"], $arUser["SECOND_NAME"]));
						if(strLen($arPathTemplate["PATH_TO_USER"])>0)
							$authorURLP = htmlspecialcharsbx("http://".$serverName.CComponentEngine::MakePathFromTemplate($arPathTemplate["PATH_TO_USER"], array("user_id"=>$arPost["AUTHOR_ID"])));
						else
							$authorURLP = "http://".$serverName.CBlogUser::PreparePath($arPost["AUTHOR_ID"], $arGroup["SITE_ID"]);

						$rssText .= "  <author>\n";
						$rssText .= "  		<name>".$authorP."</name>\n";
						$rssText .= "  		<uri>".$authorURLP."</uri>\n";
						$rssText .= "  </author>\n";

						$rssText .= "\n";
					}

					$user_id = $GLOBALS["USER"]->GetID();
					if($arPathTemplate["USE_SOCNET"] == "Y")
					{
						$postPerm = CBlogPost::GetSocNetPostPerms($postID);
						if($postPerm > BLOG_PERMS_DENY)
							$postPerm = CBlogComment::GetSocNetUserPerms($postID, $arPost["AUTHOR_ID"]);
					}
					else
						$postPerm = CBlogPost::GetBlogUserCommentPerms($postID, IntVal($user_id));

					if($postPerm >= BLOG_PERMS_READ)
					{
						$parser = new blogTextParser();
						$arParserParams = Array(
							"imageWidth" => $arPathTemplate["IMAGE_MAX_WIDTH"],
							"imageHeight" => $arPathTemplate["IMAGE_MAX_HEIGHT"],
						);

						CTimeZone::Disable();
						$dbComments = CBlogComment::GetList(
							array("DATE_CREATE" => "DESC"),
							array(
								//"BLOG_ID" => $blogID,
								"POST_ID" => $postID,
								"PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH,
							),
							false,
							array("nTopCount" => $numPosts),
							array("ID", "TITLE", "DATE_CREATE", "POST_TEXT", "AUTHOR_EMAIL", "AUTHOR_ID", "AUTHOR_NAME", "USER_LOGIN", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_NAME", "BLOG_USER_ALIAS")
						);
						CTimeZone::Enable();
						$arImages = Array();
						$dbImages = CBlogImage::GetList(Array(), Array("BLOG_ID" => $blogID, "POST_ID" => $postID, "IS_COMMENT" => "Y", "!COMMENT_ID" => false));
						while($arI = $dbImages->Fetch())
							$arImages[$arI["ID"]] = $arI["FILE_ID"];

						while ($arComments = $dbComments->Fetch())
						{
							$arDate = ParseDateTime($arComments["DATE_CREATE"], CSite::GetDateFormat("FULL", $arGroup["SITE_ID"]));
							$date = date("r", mktime($arDate["HH"], $arDate["MI"], $arDate["SS"], $arDate["MM"], $arDate["DD"], $arDate["YYYY"]));

							if(strpos($url, "?") !== false)
								$url1 = $url."&amp;";
							else
								$url1 = $url."?";
							$url1 .= "commentId=".$arComments["ID"]."#".$arComments["ID"];

							$authorURL = "";
							if(IntVal($arComments["AUTHOR_ID"]) > 0)
							{
								$author = CBlogUser::GetUserName($arComments["BLOG_USER_ALIAS"], $arComments["USER_NAME"], $arComments["USER_LAST_NAME"], $arComments["USER_LOGIN"], $arComments["USER_SECOND_NAME"]);
								if(strLen($arPathTemplate["PATH_TO_USER"])>0)
									$authorURL = htmlspecialcharsbx("http://".$serverName.CComponentEngine::MakePathFromTemplate($arPathTemplate["PATH_TO_USER"], array("user_id"=>$arComments["AUTHOR_ID"])));
								else
									$authorURL = htmlspecialcharsbx("http://".$serverName.CBlogUser::PreparePath($arComments["AUTHOR_ID"], $arGroup["SITE_ID"]));
							}
							else
								$author = $arComments["AUTHOR_NAME"];
							$arAllow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "VIDEO" => "Y", "TABLE" => "Y", "CUT_ANCHOR" => "N");
							if($arPathTemplate["NO_URL_IN_COMMENTS"] == "L" || (IntVal($arComments["AUTHOR_ID"]) <= 0  && $arPathTemplate["NO_URL_IN_COMMENTS"] == "A"))
								$arAllow["CUT_ANCHOR"] = "Y";

							if($arPathTemplate["NO_URL_IN_COMMENTS_AUTHORITY_CHECK"] == "Y" && $arAllow["CUT_ANCHOR"] != "Y" && IntVal($arComments["AUTHOR_ID"]) > 0)
							{
								$authorityRatingId = CRatings::GetAuthorityRating();
								$arRatingResult = CRatings::GetRatingResult($authorityRatingId, $arComments["AUTHOR_ID"]);
								if($arRatingResult["CURRENT_VALUE"] < $arPathTemplate["NO_URL_IN_COMMENTS_AUTHORITY"])
									$arAllow["CUT_ANCHOR"] = "Y";
							}

							$text = $parser->convert_to_rss($arComments["POST_TEXT"], $arImages, $arAllow, false, $arParserParams);

							$title = GetMessage("BLG_GCM_COMMENT_TITLE", Array("#POST_TITLE#" => htmlspecialcharsEx($arPost["TITLE"]), "#COMMENT_AUTHOR#" => htmlspecialcharsEx($author)));
							/*$title = str_replace(
								array("&", "<", ">", "\""),
								array("&amp;", "&lt;", "&gt;", "&quot;"),
								$title);
							*/
							//$text1 = HTMLToTxt($text, "", Array("\&nbsp;"), 60);
							$text = "<![CDATA[".$text."]]>";


							if ($type == "rss.92")
							{
								$rssText .= "    <item>\n";
								$rssText .= "      <title>".$title."</title>\n";
								$rssText .= "      <description>".$text."</description>\n";
								$rssText .= "      <link>".$url1."</link>\n";
								$rssText .= "    </item>\n";
								$rssText .= "\n";
							}
							elseif ($type == "rss2.0")
							{
								$rssText .= "    <item>\n";
								$rssText .= "      <title>".$title."</title>\n";
								$rssText .= "      <description>".$text."</description>\n";
								$rssText .= "      <link>".$url1."</link>\n";
								$rssText .= "      <guid>".$url1."</guid>\n";
								$rssText .= "      <pubDate>".$date."</pubDate>\n";
								$rssText .= "    </item>\n";
								$rssText .= "\n";
							}
							elseif ($type == "atom.03")
							{
								$atomID = "tag:".htmlspecialcharsbx($serverName).":".$arBlog["URL"]."/".$arPost["ID"];

								$timeISO = mktime($arDate["HH"], $arDate["MI"], $arDate["SS"], $arDate["MM"], $arDate["DD"], $arDate["YYYY"]);
								$dateISO = date("Y-m-d\TH:i:s", $timeISO).substr(date("O", $timeISO), 0, 3).":".substr(date("O", $timeISO), -2, 2);

								$rssText .= "<entry>\n";
								$rssText .= "  <title type=\"text/html\">".$title."</title>\n";
								$rssText .= "  <link rel=\"alternate\" type=\"text/html\" href=\"".$url1."\"/>\n";
								$rssText .= "  <issued>".$dateISO."</issued>\n";
								$rssText .= "  <modified>".$nowISO."</modified>\n";
								$rssText .= "  <id>".$atomID."</id>\n";
								$rssText .= "  <content type=\"text/html\" mode=\"escaped\" xml:lang=\"".$language."\" xml:base=\"".$blogURL."\">\n";
								$rssText .= $text."\n";
								$rssText .= "  </content>\n";
								$rssText .= "  <author>\n";
								$rssText .= "    <name>".htmlspecialcharsex($author)."</name>\n";
								if(strlen($authorURL) > 0)
									$rssText .= "    <uri>".$authorURL."</uri>\n";
								$rssText .= "  </author>\n";
								$rssText .= "</entry>\n";
								$rssText .= "\n";
							}
						}
					}

					if ($type == "rss.92")
						$rssText .= "  </channel>\n</rss>";
					elseif ($type == "rss2.0")
						$rssText .= "  </channel>\n</rss>";
					elseif ($type == "atom.03")
						$rssText .= "\n\n</feed>";
				}
			}
		}

		return $rssText;
	}
Example #6
0
);
*/
if (CModule::IncludeModule("blog")) {
    $ID = IntVal($ID);
    $BLOGS_COUNT = intval($BLOGS_COUNT) > 0 ? IntVal($BLOGS_COUNT) : 20;
    $COUNT = array("nPageSize" => intval($BLOGS_COUNT), "bShowAll" => false);
    $SORT_BY1 = isset($SORT_BY1) ? $SORT_BY1 : "LAST_POST_DATE";
    $SORT_ORDER1 = isset($SORT_ORDER1) ? $SORT_ORDER1 : "DESC";
    $SORT_BY2 = isset($SORT_BY2) ? $SORT_BY2 : "NAME";
    $SORT_ORDER2 = isset($SORT_ORDER2) ? $SORT_ORDER2 : "ASC";
    $SORT = array($SORT_BY1 => $SORT_ORDER1, $SORT_BY2 => $SORT_ORDER2);
    $CACHE_TIME = intval($CACHE_TIME);
    $is404 = $is404 == 'N' ? false : true;
    $arFilter = array("SITE_ID" => SITE_ID, "GROUP_ID" => $ID, "ACTIVE" => "Y");
    $arSelectFields = array("ID", "NAME", "DESCRIPTION", "URL", "SITE_ID", "DATE_CREATE", "DATE_UPDATE", "ACTIVE", "OWNER_ID", "OWNER_LOGIN", "OWNER_NAME", "OWNER_LAST_NAME", "LAST_POST_DATE", "LAST_POST_ID", "BLOG_USER_AVATAR", "BLOG_USER_ALIAS");
    if ($arGroup = CBlogGroup::GetByID($ID)) {
        $APPLICATION->SetTitle($arGroup["NAME"]);
        //формируем кэш
        $cache = new CPHPCache();
        $cache_id = "blog_groups_" . serialize($arParams) . "_" . CDBResult::NavStringForCache($BLOGS_COUNT);
        $cache_path = "/" . SITE_ID . "/blog/groups/" . $ID . "/";
        if ($CACHE_TIME > 0 && $cache->InitCache($CACHE_TIME, $cache_id, $cache_path)) {
            $cache->Output();
        } else {
            if ($CACHE_TIME > 0) {
                $cache->StartDataCache($CACHE_TIME, $cache_id, $cache_path);
            }
            $dbBlogs = CBlog::GetList($SORT, $arFilter, false, $COUNT, $arSelectFields);
            if ($arBlogs = $dbBlogs->NavNext(false)) {
                //$dbBlogs->NavPrint(GetMessage("B_B_GR_TITLE"));
                do {
Example #7
0
    ShowError(GetMessage("BLOG_MODULE_NOT_INSTALL"));
    return;
}
$arParams["BLOG_URL"] = preg_replace("/[^a-zA-Z0-9_-]/is", "", Trim($arParams["BLOG_URL"]));
if (!array_key_exists("PATH_TO_BLOG_CATEGORY", $arParams) || !is_string($arParams["PATH_TO_BLOG_CATEGORY"])) {
    $arParams["PATH_TO_BLOG_CATEGORY"] = "";
}
//0 no limit
$arParams["TAGS_COUNT"] = intval($arParams["TAGS_COUNT"]);
$obCache = new CPHPCache();
$cache_id = md5(serialize(array($arParams["BLOG_URL"], $arParams["TAGS_COUNT"], $arParams["PATH_TO_BLOG_CATEGORY"])));
$cache_path = '/' . SITE_ID . '/idea/tags/';
if (!$obCache->StartDataCache(60 * 60 * 24, $cache_id, $cache_path)) {
    $arResult = $obCache->GetVars();
} else {
    if (($arBlog = CBlog::GetByUrl($arParams["BLOG_URL"])) && $arBlog["ACTIVE"] == "Y" && ($arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"])) && $arGroup["SITE_ID"] == SITE_ID) {
        $arResult = array("BLOG" => $arBlog, "CATEGORY" => array());
        $toCnt = array();
        $res = CBlogCategory::GetList(array("NAME" => "ASC"), array("BLOG_ID" => $arBlog["ID"]));
        while ($arCategory = $res->GetNext()) {
            $arSumCat["C" . $arCategory["ID"]] = array("ID" => $arCategory["ID"], "NAME" => $arCategory["NAME"]);
            $toCnt[] = $arCategory['ID'];
        }
        $resCnt = CBlogPostCategory::GetList(array(), array("BLOG_ID" => $arBlog["ID"], "CATEGORY_ID" => $toCnt), array("CATEGORY_ID"), $arParams["TAGS_COUNT"] > 0 ? array("nTopCount" => $arParams["TAGS_COUNT"]) : false, array("ID", "BLOG_ID", "CATEGORY_ID", "NAME"));
        if (($arCategoryCount = $resCnt->Fetch()) && $arCategoryCount) {
            $cntMin = $cntMax = $arCategoryCount['CNT'];
            $arRes = array();
            do {
                $arRes["C" . $arCategoryCount["CATEGORY_ID"]] = array("CNT" => $arCategoryCount['CNT'], "URL" => CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG_CATEGORY"], array("category_id" => $arCategoryCount["CATEGORY_ID"])));
                $cntMin = min($cntMin, $arCategoryCount['CNT']);
                $cntMax = max($cntMax, $arCategoryCount['CNT']);
Example #8
0
 public static function GetPing($blogUrl, $postID, $arParams = array())
 {
     global $DB;
     $blogUrl = Trim($blogUrl);
     $postID = IntVal($postID);
     $bSuccess = True;
     $arPost = CBlogPost::GetByID($postID);
     if (!$arPost) {
         CBlogTrackback::SendPingResponce(1, "Invalid target post");
         $bSuccess = False;
     }
     if ($bSuccess) {
         if ($arPost["ENABLE_TRACKBACK"] != "Y" || COption::GetOptionString("blog", "enable_trackback", "Y") != "Y") {
             CBlogTrackback::SendPingResponce(1, "Trackbacks disabled");
             $bSuccess = False;
         }
     }
     if ($bSuccess) {
         $arBlog = CBlog::GetByID($arPost["BLOG_ID"]);
         if (!$arBlog || $arBlog["URL"] != $blogUrl) {
             CBlogTrackback::SendPingResponce(1, "Invalid target blog");
             $bSuccess = False;
         }
     }
     if ($bSuccess) {
         if (!isset($arParams["title"]) || strlen($arParams["title"]) <= 0 || !isset($arParams["url"]) || strlen($arParams["url"]) <= 0) {
             CBlogTrackback::SendPingResponce(1, "Missing required fields");
             $bSuccess = False;
         }
     }
     if ($bSuccess) {
         if (!isset($arParams["excerpt"])) {
             $arParams["excerpt"] = $arParams["title"];
         }
         if (!isset($arParams["blog_name"])) {
             $arParams["blog_name"] = "";
         }
     }
     if ($bSuccess) {
         $serverCharset = "";
         $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
         $dbSite = CSite::GetList($b = "sort", $o = "asc", array("LID" => $arGroup["SITE_ID"]));
         if ($arSite = $dbSite->Fetch()) {
             $serverCharset = $arSite["CHARSET"];
         }
         if (strlen($serverCharset) <= 0) {
             if (defined("SITE_CHARSET") && strlen(SITE_CHARSET) > 0) {
                 $serverCharset = SITE_CHARSET;
             } else {
                 $serverCharset = "windows-1251";
             }
         }
         preg_match("/charset=(\")*(.*?)(\")*(;|\$)/", $_SERVER["CONTENT_TYPE"], $charset);
         $charset = preg_replace("#[^[:space:]a-zA-Z0-9\\-]#is", "", $charset[2]);
         if (strlen($charset) <= 0) {
             $charset = "utf-8";
         }
         if ($charset != $serverCharset) {
             $arParams["title"] = $GLOBALS["APPLICATION"]->ConvertCharset($arParams["title"], $charset, $serverCharset);
             $arParams["url"] = $GLOBALS["APPLICATION"]->ConvertCharset($arParams["url"], $charset, $serverCharset);
             $arParams["excerpt"] = $GLOBALS["APPLICATION"]->ConvertCharset($arParams["excerpt"], $charset, $serverCharset);
             $arParams["blog_name"] = $GLOBALS["APPLICATION"]->ConvertCharset($arParams["blog_name"], $charset, $serverCharset);
         }
         $arFields = array("TITLE" => $arParams["title"], "URL" => $arParams["url"], "PREVIEW_TEXT" => $arParams["excerpt"], "BLOG_NAME" => $arParams["blog_name"], "=POST_DATE" => $DB->CurrentTimeFunction(), "BLOG_ID" => $arPost["BLOG_ID"], "POST_ID" => $arPost["ID"]);
         $dbTrackback = CBlogTrackback::GetList(array(), array("BLOG_ID" => $arPost["BLOG_ID"], "POST_ID" => $arPost["ID"], "URL" => $arParams["url"]));
         if ($arTrackback = $dbTrackback->Fetch()) {
             if (!CBlogTrackback::Update($arTrackback["ID"], $arFields)) {
                 if ($ex = $GLOBALS["APPLICATION"]->GetException()) {
                     $errorMessage = $ex->GetString() . ".<br>";
                 } else {
                     $errorMessage = "Unknown error" . ".<br>";
                 }
                 CBlogTrackback::SendPingResponce(1, $errorMessage);
             }
         } else {
             if (!CBlogTrackback::Add($arFields)) {
                 if ($ex = $GLOBALS["APPLICATION"]->GetException()) {
                     $errorMessage = $ex->GetString() . ".<br>";
                 } else {
                     $errorMessage = "Unknown error" . ".<br>";
                 }
                 CBlogTrackback::SendPingResponce(1, $errorMessage);
             }
         }
         CBlogTrackback::SendPingResponce(0, "Ping accepted");
     }
     return $bSuccess;
 }
Example #9
0
 function Update($ID, $arFields)
 {
     global $DB;
     $ID = IntVal($ID);
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CBlogUser::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     }
     $strUpdate = $DB->PrepareUpdate("b_blog_user", $arFields, "blog/avatar");
     foreach ($arFields1 as $key => $value) {
         if (strlen($strUpdate) > 0) {
             $strUpdate .= ", ";
         }
         $strUpdate .= $key . "=" . $value . " ";
     }
     if (strlen($strUpdate) > 0) {
         $arUser = CBlogUser::GetByID($ID, BLOG_BY_BLOG_USER_ID);
         $strSql = "UPDATE b_blog_user SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
         $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         unset($GLOBALS["BLOG_USER_CACHE_" . $ID]);
         unset($GLOBALS["BLOG_USER1_CACHE_" . $arUser["USER_ID"]]);
     } else {
         $ID = false;
     }
     if ($ID && !(count($arFields1) == 1 && strlen($arFields1["LAST_VISIT"]) > 0)) {
         if (CModule::IncludeModule("search")) {
             $arBlogUser = CBlogUser::GetByID($ID);
             $dbUser = CUser::GetByID($arBlogUser["USER_ID"]);
             $arUser = $dbUser->Fetch();
             $arBlog = CBlog::GetByOwnerID($arBlogUser["USER_ID"]);
             if ($arBlog) {
                 $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
                 $arPostSite = array($arGroup["SITE_ID"] => CBlogUser::PreparePath($arBlogUser["USER_ID"], $arGroup["SITE_ID"]));
             } else {
                 $arPostSite = array(SITE_ID => CBlogUser::PreparePath($arBlogUser["USER_ID"], SITE_ID));
             }
             if (strlen($arBlogUser["LAST_VISIT"]) <= 0) {
                 $arBlogUser["LAST_VISIT"] = ConvertTimeStamp(false, "FULL", false);
             }
             $arSearchIndex = array("SITE_ID" => $arPostSite, "LAST_MODIFIED" => $arBlogUser["LAST_VISIT"], "PARAM1" => "USER", "PARAM2" => $arBlogUser["USER_ID"], "PERMISSIONS" => array(2), "TITLE" => CBlogUser::GetUserName($arBlogUser["ALIAS"], $arUser["NAME"], $arUser["LAST_NAME"], $arUser["LOGIN"]), "BODY" => blogTextParser::killAllTags($arBlogUser["INTERESTS"] . " " . $arBlogUser["DESCRIPTION"]));
             CSearch::Index("blog", "U" . $ID, $arSearchIndex);
         }
     }
     return $ID;
 }
Example #10
0
             CBlog::DeleteSocnetRead($ID);
         }
     }
 }
 if (!$result) {
     $bVarsFromForm = true;
     if ($ex = $APPLICATION->GetException()) {
         $errorMessage .= $ex->GetString() . "<br />";
     } else {
         $errorMessage .= GetMessage("BLBE_SAVE_ERROR") . "<br />";
     }
 }
 if (strlen($errorMessage) <= 0) {
     if (!empty($arBlogOld)) {
         if ($arBlogOld["GROUP_ID"] != $arFields["GROUP_ID"]) {
             $arBlogGroupCur = CBlogGroup::GetByID($arFields["GROUP_ID"]);
             if ($arBlogOld["GROUP_SITE_ID"] != $arBlogGroupCur["SITE_ID"]) {
                 BXClearCache(True, "/" . $arBlogGroupCur["SITE_ID"] . "/blog/");
                 BXClearCache(True, "/" . SITE_ID . "/blog/last_messages/");
                 BXClearCache(True, "/" . SITE_ID . "/blog/commented_posts/");
                 BXClearCache(True, "/" . SITE_ID . "/blog/popular_posts/");
                 BXClearCache(True, "/" . SITE_ID . "/blog/last_comments/");
                 BXClearCache(True, "/" . SITE_ID . "/blog/popular_blogs/");
                 BXClearCache(True, "/" . SITE_ID . "/blog/new_blogs/");
             }
         }
         BXClearCache(True, "/" . $arBlogOld["GROUP_SITE_ID"] . "/blog/");
     }
     if (strlen($apply) <= 0) {
         LocalRedirect("/bitrix/admin/blog_blog.php?lang=" . LANG . GetFilterParams("filter_", false));
     } else {
Example #11
0
 function Update($ID, $arFields)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID <= 0) {
         return false;
     }
     if (strlen($arFields["PATH"]) > 0) {
         $path = $arFields["PATH"];
         unset($arFields["PATH"]);
     }
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CBlog::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     } elseif (!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("BLOG_BLOG", $ID, $arFields)) {
         return false;
     }
     $db_events = GetModuleEvents("blog", "OnBeforeBlogUpdate");
     while ($arEvent = $db_events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields)) === false) {
             return false;
         }
     }
     $arBlogOld = CBlog::GetByID($ID);
     $strUpdate = $DB->PrepareUpdate("b_blog", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strlen($strUpdate) > 0) {
             $strUpdate .= ", ";
         }
         $strUpdate .= $key . "=" . $value . " ";
     }
     if (strlen($strUpdate) > 0) {
         $strSql = "UPDATE b_blog SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
         $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         unset($GLOBALS["BLOG"]["BLOG_CACHE_" . $ID]);
         unset($GLOBALS["BLOG"]["BLOG4OWNER_CACHE_" . $arBlogOld["OWNER_ID"]]);
         unset($GLOBALS["BLOG"]["BLOG4OWNERGROUP_CACHE_" . $arBlogOld["SOCNET_GROUP_ID"]]);
         $events = GetModuleEvents("blog", "OnBlogUpdate");
         while ($arEvent = $events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($ID, &$arFields));
         }
         if (is_set($arFields, "PERMS_POST")) {
             CBlog::SetBlogPerms($ID, $arFields["PERMS_POST"], BLOG_PERMS_POST);
         }
         if (is_set($arFields, "PERMS_COMMENT")) {
             CBlog::SetBlogPerms($ID, $arFields["PERMS_COMMENT"], BLOG_PERMS_COMMENT);
         }
         $GLOBALS["USER_FIELD_MANAGER"]->Update("BLOG_BLOG", $ID, $arFields);
     } else {
         $ID = False;
     }
     if ($ID && (is_set($arFields, "NAME") || is_set($arFields, "DESCRIPTION"))) {
         if (CModule::IncludeModule("search")) {
             $arBlog = CBlog::GetByID($ID);
             if ($arBlogOld["ACTIVE"] == "Y" && $arBlog["ACTIVE"] != "Y" || $arBlogOld["SEARCH_INDEX"] == "Y" && $arBlog["SEARCH_INDEX"] != "Y") {
                 CSearch::DeleteIndex("blog", false, "COMMENT", $ID . "|%");
                 CSearch::DeleteIndex("blog", false, "POST", $ID);
                 CSearch::DeleteIndex("blog", "B" . $ID);
             } elseif ($arBlog["ACTIVE"] == "Y" && $arBlog["SEARCH_INDEX"] == "Y") {
                 if ($arBlog["USE_SOCNET"] == "Y") {
                     CSearch::DeleteIndex("blog", "B" . $ID);
                 } else {
                     $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
                     if (strlen($path) > 0) {
                         $path = str_replace("#blog_url#", $arBlog["URL"], $path);
                         $arPostSite = array($arGroup["SITE_ID"] => $path);
                     } else {
                         $arPostSite = array($arGroup["SITE_ID"] => CBlog::PreparePath($arBlog["URL"], $arGroup["SITE_ID"], false, $arBlog["OWNER_ID"], $arBlog["SOCNET_GROUP_ID"]));
                     }
                     $arSearchIndex = array("SITE_ID" => $arPostSite, "LAST_MODIFIED" => $arBlog["DATE_UPDATE"], "PARAM1" => "BLOG", "PARAM2" => $arBlog["OWNER_ID"], "PERMISSIONS" => array(2), "TITLE" => $arBlog["NAME"], "BODY" => strlen($arBlog["DESCRIPTION"]) > 0 ? $arBlog["DESCRIPTION"] : $arBlog["NAME"]);
                     CSearch::Index("blog", "B" . $ID, $arSearchIndex);
                 }
             }
         }
     }
     return $ID;
 }
Example #12
0
         }
         $arSites[] = $ar_sites;
     }
     if (empty($arFields["SITE_ID"])) {
         $arFields["SITE_ID"] = $arSites[0]["LID"];
     }
     $BLOG_GROUP_ID = CBlogGroup::Add($arFields);
     if ($BLOG_GROUP_ID <= 0) {
         $bVarsFromForm = true;
         if ($ex = $APPLICATION->GetException()) {
             $strWarning .= $ex->GetString() . ". <br />";
         } else {
             $strWarning .= "Error creating blog group.  <br />";
         }
     } else {
         $arBlogGroupTmp = CBlogGroup::GetByID($BLOG_GROUP_ID);
         BXClearCache(True, "/" . $arBlogGroupTmp["SITE_ID"] . "/blog/blog_groups/");
         $_REQUEST["create_blog_group"] = "N";
         $_REQUEST["blog_group_id"] = $BLOG_GROUP_ID;
         $_REQUEST["blog_group_name"] = "";
     }
 }
 if (!$bVarsFromForm) {
     $arFields = array("ACTIVE" => "N", "NAME" => $_REQUEST["blog_name"], "DESCRIPTION" => $_REQUEST["blog_description"], "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "URL" => $_REQUEST["blog_url"], "OWNER_ID" => $GLOBALS["USER"]->GetId(), "GROUP_ID" => $_REQUEST["blog_group_id"], "ENABLE_COMMENTS" => "Y", "ENABLE_IMG_VERIF" => "Y", "EMAIL_NOTIFY" => "N", "ENABLE_RSS" => "N", "ALLOW_HTML" => "N", "PERMS_POST" => array("1" => "I", "2" => "I"), "PERMS_COMMENT" => array("1" => "P", "2" => "P"));
     $ID = CBlog::Add($arFields);
     if (intVal($ID) <= 0) {
         $bVarsFromForm = true;
         if ($ex = $APPLICATION->GetException()) {
             $strWarning .= $ex->GetString() . "<br />";
         } else {
             $strWarning .= "Error creating blog. <br />";
Example #13
0
 function Update($ID, $arFields)
 {
     global $DB;
     $ID = IntVal($ID);
     if (strlen($arFields["PATH"]) > 0) {
         $arFields["PATH"] = str_replace("#post_id#", $ID, $arFields["PATH"]);
     }
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CBlogPost::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     } elseif (!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("BLOG_POST", $ID, $arFields)) {
         return false;
     }
     $db_events = GetModuleEvents("blog", "OnBeforePostUpdate");
     while ($arEvent = $db_events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields)) === false) {
             return false;
         }
     }
     $arOldPost = CBlogPost::GetByID($ID);
     if (is_array($arFields["ATTACH_IMG"])) {
         if (!array_key_exists("MODULE_ID", $arFields["ATTACH_IMG"]) || strlen($arFields["ATTACH_IMG"]["MODULE_ID"]) <= 0) {
             $arFields["ATTACH_IMG"]["MODULE_ID"] = "blog";
         }
         $prefix = "blog";
         if (strlen($arFields["URL"]) > 0) {
             $prefix .= "/" . $arFields["URL"];
         }
         CFile::SaveForDB($arFields, "ATTACH_IMG", $prefix);
     }
     $strUpdate = $DB->PrepareUpdate("b_blog_post", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strlen($strUpdate) > 0) {
             $strUpdate .= ", ";
         }
         $strUpdate .= $key . "=" . $value . " ";
     }
     if (strlen($strUpdate) > 0) {
         $oldPostPerms = CBlogUserGroup::GetGroupPerms(1, $arOldPost["BLOG_ID"], $ID, BLOG_PERMS_POST);
         $strSql = "UPDATE b_blog_post SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
         $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         unset($GLOBALS["BLOG_POST"]["BLOG_POST_CACHE_" . $ID]);
         $GLOBALS["USER_FIELD_MANAGER"]->Update("BLOG_POST", $ID, $arFields);
     } else {
         $ID = False;
     }
     if ($ID) {
         $arNewPost = CBlogPost::GetByID($ID);
         if ($arNewPost["PUBLISH_STATUS"] != $arOldPost["PUBLISH_STATUS"] || $arNewPost["BLOG_ID"] != $arOldPost["BLOG_ID"]) {
             CBlog::SetStat($arNewPost["BLOG_ID"]);
         }
         if ($arNewPost["BLOG_ID"] != $arOldPost["BLOG_ID"]) {
             CBlog::SetStat($arOldPost["BLOG_ID"]);
         }
         if (is_set($arFields, "PERMS_POST")) {
             CBlogPost::SetPostPerms($ID, $arFields["PERMS_POST"], BLOG_PERMS_POST);
         }
         if (is_set($arFields, "PERMS_COMMENT")) {
             CBlogPost::SetPostPerms($ID, $arFields["PERMS_COMMENT"], BLOG_PERMS_COMMENT);
         }
         if (array_key_exists("SOCNET_RIGHTS", $arFields)) {
             $arFields["SC_PERM_OLD"] = CBlogPost::GetSocNetPermsCode($ID);
             $arFields["SC_PERM"] = CBlogPost::UpdateSocNetPerms($ID, $arFields["SOCNET_RIGHTS"], $arNewPost);
         }
         $db_events = GetModuleEvents("blog", "OnPostUpdate");
         while ($arEvent = $db_events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($ID, &$arFields));
         }
         if (CModule::IncludeModule("search")) {
             $newPostPerms = CBlogUserGroup::GetGroupPerms(1, $arNewPost["BLOG_ID"], $ID, BLOG_PERMS_POST);
             $arBlog = CBlog::GetByID($arNewPost["BLOG_ID"]);
             if ($arOldPost["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $oldPostPerms >= BLOG_PERMS_READ && ($arNewPost["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH || $newPostPerms < BLOG_PERMS_READ) || $arBlog["SEARCH_INDEX"] != "Y") {
                 CSearch::Index("blog", "P" . $ID, array("TITLE" => "", "BODY" => ""));
                 CSearch::DeleteIndex("blog", false, "COMMENT", $arBlog["ID"] . "|" . $ID);
             } elseif ($arNewPost["DATE_PUBLISHED"] == "Y" && $arNewPost["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $newPostPerms >= BLOG_PERMS_READ && $arBlog["SEARCH_INDEX"] == "Y") {
                 $tag = "";
                 $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
                 if (strlen($arFields["PATH"]) > 0) {
                     $arPostSite = array($arGroup["SITE_ID"] => $arFields["PATH"]);
                 } elseif (strlen($arNewPost["PATH"]) > 0) {
                     if (strlen($arNewPost["CODE"]) > 0) {
                         $arNewPost["PATH"] = str_replace("#post_id#", $arNewPost["CODE"], $arNewPost["PATH"]);
                     } else {
                         $arNewPost["PATH"] = str_replace("#post_id#", $ID, $arNewPost["PATH"]);
                     }
                     $arPostSite = array($arGroup["SITE_ID"] => $arNewPost["PATH"]);
                 } else {
                     $arPostSite = array($arGroup["SITE_ID"] => CBlogPost::PreparePath($arBlog["URL"], $arNewPost["ID"], $arGroup["SITE_ID"], false, $arBlog["OWNER_ID"], $arBlog["SOCNET_GROUP_ID"]));
                 }
                 if (strlen($arNewPost["CATEGORY_ID"]) > 0) {
                     $arC = explode(",", $arNewPost["CATEGORY_ID"]);
                     $arTag = array();
                     foreach ($arC as $v) {
                         $arCategory = CBlogCategory::GetByID($v);
                         $arTag[] = $arCategory["NAME"];
                     }
                     $tag = implode(",", $arTag);
                 }
                 $arSearchIndex = array("SITE_ID" => $arPostSite, "LAST_MODIFIED" => $arNewPost["DATE_PUBLISH"], "PARAM1" => "POST", "PARAM2" => $arNewPost["BLOG_ID"], "PARAM3" => $arNewPost["ID"], "PERMISSIONS" => array(2), "TITLE" => $arNewPost["TITLE"], "BODY" => blogTextParser::killAllTags($arNewPost["DETAIL_TEXT"]), "TAGS" => $tag, "USER_ID" => $arNewPost["AUTHOR_ID"], "ENTITY_TYPE_ID" => "BLOG_POST", "ENTITY_ID" => $arNewPost["ID"]);
                 $bIndexComment = false;
                 if ($arBlog["USE_SOCNET"] == "Y") {
                     if (!empty($arFields["SC_PERM"])) {
                         $arSearchIndex["PERMISSIONS"] = $arFields["SC_PERM"];
                         if ($arFields["SC_PERM"] != $arFields["SC_PERM_OLD"]) {
                             $bIndexComment = true;
                         }
                     } else {
                         $arSearchIndex["PERMISSIONS"] = CBlogPost::GetSocnetPermsCode($ID);
                     }
                 }
                 CSearch::Index("blog", "P" . $ID, $arSearchIndex, True);
                 if ($arOldPost["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH && $arNewPost["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH || $bIndexComment) {
                     $arParamsComment = array("BLOG_ID" => $arBlog["ID"], "POST_ID" => $ID, "SITE_ID" => $arGroup["SITE_ID"], "PATH" => $arPostSite[$arGroup["SITE_ID"]] . "?commentId=#comment_id###comment_id#", "BLOG_URL" => $arBlog["URL"], "OWNER_ID" => $arBlog["OWNER_ID"], "SOCNET_GROUP_ID" => $arBlog["SOCNET_GROUP_ID"], "USE_SOCNET" => $arBlog["USE_SOCNET"]);
                     CBlogComment::_IndexPostComments($arParamsComment);
                 }
             }
         }
     }
     return $ID;
 }
Example #14
0
 function BuildRSSAll($GroupId = 0, $type = "RSS .92", $numPosts = 10, $siteID = SITE_ID, $postTemplate = "", $userTemplate = "", $arAvBlog = array(), $arPathTemplates = array(), $arGroupID = array(), $bUserSocNet = "N")
 {
     $GroupId = IntVal($GroupId);
     $numPosts = IntVal($numPosts);
     $user_id = IntVal($GLOBALS["USER"]->GetID());
     $type = strtolower(preg_replace("/[^a-zA-Z0-9.]/is", "", $type));
     if ($type != "rss2.0" && $type != "atom.03") {
         $type = "rss.92";
     }
     $rssText = False;
     $groupIdArray = array();
     $arGroup = array();
     if ($GroupId > 0) {
         if (!empty($arGroupID) && in_array($GroupId, $arGroupID) || empty($arGroupID)) {
             $arGroup = CBlogGroup::GetByID($GroupId);
         }
     }
     $now = date("r");
     $nowISO = date("Y-m-d\\TH:i:s") . substr(date("O"), 0, 3) . ":" . substr(date("O"), -2, 2);
     $serverName = "";
     $charset = "";
     $language = "";
     $dbSite = CSite::GetList($b = "sort", $o = "asc", array("LID" => SITE_ID));
     if ($arSite = $dbSite->Fetch()) {
         $serverName = $arSite["SERVER_NAME"];
         $charset = $arSite["CHARSET"];
         $language = $arSite["LANGUAGE_ID"];
     }
     if (strlen($serverName) <= 0) {
         if (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0) {
             $serverName = SITE_SERVER_NAME;
         } else {
             $serverName = COption::GetOptionString("main", "server_name", "");
         }
     }
     if (strlen($charset) <= 0) {
         if (defined("SITE_CHARSET") && strlen(SITE_CHARSET) > 0) {
             $charset = SITE_CHARSET;
         } else {
             $charset = "windows-1251";
         }
     }
     $blogURL = "http://" . $serverName;
     if ($GroupId > 0) {
         $blogName = GetMessage("BLG_RSS_ALL_GROUP_TITLE") . " \"" . htmlspecialcharsbx($arGroup["NAME"]) . "\" (" . $serverName . ")";
     } else {
         $blogName = GetMessage("BLG_RSS_ALL_TITLE") . " \"" . htmlspecialcharsbx($arSite["NAME"]) . "\" (" . $serverName . ")";
     }
     $rssText = "";
     if ($type == "rss.92") {
         $rssText .= "<" . "?xml version=\"1.0\" encoding=\"" . $charset . "\"?" . ">\n\n";
         $rssText .= "<rss version=\".92\">\n";
         $rssText .= " <channel>\n";
         $rssText .= "\t<title>" . $blogName . "</title>\n";
         $rssText .= "\t<link>" . $blogURL . "</link>\n";
         $rssText .= "\t<guid>" . $blogURL . "</guid>\n";
         $rssText .= "\t<language>" . $language . "</language>\n";
         $rssText .= "\t<docs>http://backend.userland.com/rss092</docs>\n";
         $rssText .= "\n";
     } elseif ($type == "rss2.0") {
         $rssText .= "<" . "?xml version=\"1.0\" encoding=\"" . $charset . "\"?" . ">\n\n";
         $rssText .= "<rss version=\"2.0\">\n";
         $rssText .= " <channel>\n";
         $rssText .= "\t<title>" . $blogName . "</title>\n";
         $rssText .= "\t<description>" . $blogName . "</description>\n";
         $rssText .= "\t<link>" . $blogURL . "</link>\n";
         $rssText .= "\t<language>" . $language . "</language>\n";
         $rssText .= "\t<docs>http://backend.userland.com/rss2</docs>\n";
         $rssText .= "\t<pubDate>" . $now . "</pubDate>\n";
         $rssText .= "\n";
     } elseif ($type == "atom.03") {
         $atomID = "tag:" . htmlspecialcharsbx($serverName) . "," . date("Y-m-d");
         $rssText .= "<" . "?xml version=\"1.0\" encoding=\"" . $charset . "\"?" . ">\n\n";
         $rssText .= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\" xml:lang=\"" . $language . "\">\n";
         $rssText .= "  <title>" . $blogName . "</title>\n";
         $rssText .= "  <tagline>" . $blogURL . "</tagline>\n";
         $rssText .= "  <id>" . $atomID . "</id>\n";
         $rssText .= "  <link rel=\"alternate\" type=\"text/html\" href=\"" . $blogURL . "\" />\n";
         $rssText .= "  <copyright>Copyright (c) " . $blogURL . "</copyright>\n";
         $rssText .= "  <modified>" . $nowISO . "</modified>\n";
         $rssText .= "\n";
     }
     $parser = new blogTextParser();
     $arParserParams = array("imageWidth" => $arPathTemplates["IMAGE_MAX_WIDTH"], "imageHeight" => $arPathTemplates["IMAGE_MAX_HEIGHT"]);
     $arFilter = array("<=DATE_PUBLISH" => ConvertTimeStamp(false, "FULL", false), "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH, "BLOG_ENABLE_RSS" => "Y", "MICRO" => "N");
     $arSelFields = array("ID", "TITLE", "DETAIL_TEXT", "DATE_PUBLISH", "AUTHOR_ID", "BLOG_USER_ALIAS", "BLOG_ID", "DETAIL_TEXT_TYPE", "BLOG_URL", "BLOG_OWNER_ID", "BLOG_SOCNET_GROUP_ID", "BLOG_GROUP_SITE_ID", "CODE", "PATH");
     if (!empty($arGroup)) {
         $arFilter["BLOG_GROUP_ID"] = $arGroup["ID"];
     } elseif (count($arGroupID) > 0) {
         $arFilter["BLOG_GROUP_ID"] = $arGroupID;
     }
     if (count($arAvBlog) > 0) {
         $arFilter["BLOG_ID"] = $arAvBlog;
     }
     if ($siteID !== false) {
         $arFilter["BLOG_GROUP_SITE_ID"] = $siteID;
     }
     if ($bUserSocNet == "Y") {
         $arFilter["BLOG_USE_SOCNET"] = "Y";
         $arFilter["FOR_USER"] = $user_id;
         unset($arFilter["MICRO"]);
     }
     CTimeZone::Disable();
     $dbPosts = CBlogPost::GetList(array("DATE_PUBLISH" => "DESC"), $arFilter, false, array("nTopCount" => $numPosts), $arSelFields);
     CTimeZone::Enable();
     while ($arPost = $dbPosts->Fetch()) {
         $perms = CBlogPost::GetBlogUserPostPerms($arPost["ID"], $GLOBALS["USER"]->IsAuthorized() ? $GLOBALS["USER"]->GetID() : 0);
         if ($perms < BLOG_PERMS_READ) {
             continue;
         }
         $dbUser = CUser::GetByID($arPost["AUTHOR_ID"]);
         $arUser = $dbUser->Fetch();
         $author = CBlogUser::GetUserName($arPost["BLOG_USER_ALIAS"], $arUser["NAME"], $arUser["LAST_NAME"], $arUser["LOGIN"], $arUser["SECOND_NAME"]);
         $title = str_replace(array("&", "<", ">", "\""), array("&amp;", "&lt;", "&gt;", "&quot;"), $author . ": " . $arPost["TITLE"]);
         $arImages = array();
         $res = CBlogImage::GetList(array("ID" => "ASC"), array("POST_ID" => $arPost["ID"], "BLOG_ID" => $arPost["BLOG_ID"], "IS_COMMENT" => "N"));
         while ($arImage = $res->Fetch()) {
             $arImages[$arImage['ID']] = $arImage['FILE_ID'];
         }
         $arDate = ParseDateTime($arPost["DATE_PUBLISH"], CSite::GetDateFormat("FULL", $arPost["BLOG_GROUP_SITE_ID"]));
         $date = date("r", mktime($arDate["HH"], $arDate["MI"], $arDate["SS"], $arDate["MM"], $arDate["DD"], $arDate["YYYY"]));
         if (strlen($arPost["PATH"]) > 0) {
             $url = htmlspecialcharsbx("http://" . $serverName . str_replace("#post_id#", CBlogPost::GetPostID($arPost["ID"], $arPost["CODE"], $arParams["ALLOW_POST_CODE"]), $arPost["PATH"]));
         } elseif (!empty($arPathTemplates)) {
             if (IntVal($arPost["BLOG_SOCNET_GROUP_ID"]) > 0 && strlen($arPathTemplates["GROUP_BLOG_POST"]) > 0) {
                 $url = htmlspecialcharsbx("http://" . $serverName . CComponentEngine::MakePathFromTemplate($arPathTemplates["GROUP_BLOG_POST"], array("blog" => $arPost["BLOG_URL"], "post_id" => CBlogPost::GetPostID($arPost["ID"], $arPost["CODE"], $arPathTemplates["ALLOW_POST_CODE"]), "user_id" => $arPost["BLOG_OWNER_ID"], "group_id" => $arPost["BLOG_SOCNET_GROUP_ID"])));
             } else {
                 $url = htmlspecialcharsbx("http://" . $serverName . CComponentEngine::MakePathFromTemplate($arPathTemplates["BLOG_POST"], array("blog" => $arPost["BLOG_URL"], "post_id" => CBlogPost::GetPostID($arPost["ID"], $arPost["CODE"], $arPathTemplates["ALLOW_POST_CODE"]), "user_id" => $arPost["BLOG_OWNER_ID"], "group_id" => $arPost["BLOG_SOCNET_GROUP_ID"])));
             }
         } elseif (strLen($postTemplate) > 0) {
             $url = htmlspecialcharsbx("http://" . $serverName . CComponentEngine::MakePathFromTemplate($postTemplate, array("blog" => $arPost["BLOG_URL"], "post_id" => $arPost["ID"], "user_id" => $arPost["BLOG_OWNER_ID"], "group_id" => $arPost["BLOG_SOCNET_GROUP_ID"])));
         } else {
             $url = htmlspecialcharsbx("http://" . $serverName . CBlogPost::PreparePath(htmlspecialcharsbx($arPost["BLOG_URL"]), $arPost["ID"], $arPost["BLOG_GROUP_SITE_ID"]));
         }
         $category = htmlspecialcharsbx($arPost["CATEGORY_NAME"]);
         if (strlen($arPathTemplates["USER"]) > 0) {
             $authorURL = htmlspecialcharsbx("http://" . $serverName . CComponentEngine::MakePathFromTemplate($arPathTemplates["USER"], array("user_id" => $arPost["AUTHOR_ID"], "group_id" => $arPost["BLOG_SOCNET_GROUP_ID"])));
         } elseif (strLen($userTemplate) > 0) {
             $authorURL = htmlspecialcharsbx("http://" . $serverName . CComponentEngine::MakePathFromTemplate($userTemplate, array("user_id" => $arPost["AUTHOR_ID"], "group_id" => $arPost["BLOG_SOCNET_GROUP_ID"])));
         } else {
             $authorURL = htmlspecialcharsbx("http://" . $serverName . CBlogUser::PreparePath($arPost["AUTHOR_ID"], $arPost["BLOG_GROUP_SITE_ID"]));
         }
         if ($arPost["DETAIL_TEXT_TYPE"] == "html") {
             $text = $parser->convert_to_rss($arPost["DETAIL_TEXT"], $arImages, array("HTML" => "Y", "ANCHOR" => "Y", "IMG" => "Y", "SMILES" => "Y", "NL2BR" => "N", "QUOTE" => "Y", "CODE" => "Y"), true, $arParserParams);
         } else {
             $text = $parser->convert_to_rss($arPost["DETAIL_TEXT"], $arImages, false, true, $arParserParams);
         }
         if ($bUserSocNet != "Y") {
             $text .= "<br /><a href=\"" . $url . "\">" . GetMessage("BLG_GB_RSS_DETAIL") . "</a>";
         }
         $text = "<![CDATA[" . $text . "]]>";
         if ($type == "rss.92") {
             $rssText .= "    <item>\n";
             $rssText .= "      <title>" . $title . "</title>\n";
             $rssText .= "      <description>" . $text . "</description>\n";
             $rssText .= "      <link>" . $url . "</link>\n";
             $rssText .= "    </item>\n";
             $rssText .= "\n";
         } elseif ($type == "rss2.0") {
             $rssText .= "    <item>\n";
             $rssText .= "      <title>" . $title . "</title>\n";
             $rssText .= "      <description>" . $text . "</description>\n";
             $rssText .= "      <link>" . $url . "</link>\n";
             $rssText .= "      <guid>" . $url . "</guid>\n";
             $rssText .= "      <pubDate>" . $date . "</pubDate>\n";
             if (strlen($category) > 0) {
                 $rssText .= "      <category>" . $category . "</category>\n";
             }
             $rssText .= "    </item>\n";
             $rssText .= "\n";
         } elseif ($type == "atom.03") {
             $atomID = "tag:" . htmlspecialcharsbx($serverName) . ":" . $arBlog["URL"] . "/" . $arPost["ID"];
             $timeISO = mktime($arDate["HH"], $arDate["MI"], $arDate["SS"], $arDate["MM"], $arDate["DD"], $arDate["YYYY"]);
             $dateISO = date("Y-m-d\\TH:i:s", $timeISO) . substr(date("O", $timeISO), 0, 3) . ":" . substr(date("O", $timeISO), -2, 2);
             $titleRel = htmlspecialcharsbx($arPost["TITLE"]);
             $rssText .= "<entry>\n";
             $rssText .= "  <title type=\"text/html\">" . $title . "</title>\n";
             $rssText .= "  <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
             $rssText .= "  <issued>" . $dateISO . "</issued>\n";
             $rssText .= "  <modified>" . $nowISO . "</modified>\n";
             $rssText .= "  <id>" . $atomID . "</id>\n";
             $rssText .= "  <content type=\"text/html\" mode=\"escaped\" xml:lang=\"" . $language . "\" xml:base=\"" . $blogURL . "\">\n";
             $rssText .= $text . "\n";
             $rssText .= "  </content>\n";
             $rssText .= "  <link rel=\"related\" type=\"text/html\" href=\"" . $url . "\" title=\"" . $titleRel . "\"/>\n";
             $rssText .= "  <author>\n";
             $rssText .= "    <name>" . htmlspecialcharsbx($author) . "</name>\n";
             $rssText .= "    <url>" . $authorURL . "</url>\n";
             $rssText .= "  </author>\n";
             $rssText .= "</entry>\n";
             $rssText .= "\n";
         }
     }
     if ($type == "rss.92") {
         $rssText .= "  </channel>\n</rss>";
     } elseif ($type == "rss2.0") {
         $rssText .= "  </channel>\n</rss>";
     } elseif ($type == "atom.03") {
         $rssText .= "\n\n</feed>";
     }
     return $rssText;
 }
 function Update($ID, $arFields)
 {
     global $DB;
     $ID = IntVal($ID);
     if (strlen($arFields["PATH"]) > 0) {
         $arFields["PATH"] = str_replace("#comment_id#", $ID, $arFields["PATH"]);
     }
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CBlogComment::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     } elseif (!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("BLOG_COMMENT", $ID, $arFields)) {
         return false;
     }
     $db_events = GetModuleEvents("blog", "OnBeforeCommentUpdate");
     while ($arEvent = $db_events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields)) === false) {
             return false;
         }
     }
     $strUpdate = $DB->PrepareUpdate("b_blog_comment", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strlen($strUpdate) > 0) {
             $strUpdate .= ", ";
         }
         $strUpdate .= $key . "=" . $value . " ";
     }
     if (strlen($strUpdate) > 0) {
         if (is_set($arFields["PUBLISH_STATUS"]) && strlen($arFields["PUBLISH_STATUS"]) > 0) {
             $arComment = CBlogComment::GetByID($ID);
             if ($arComment["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $arFields["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH) {
                 CBlogPost::Update($arComment["POST_ID"], array("=NUM_COMMENTS" => "NUM_COMMENTS - 1"));
             } elseif ($arComment["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH && $arFields["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH) {
                 CBlogPost::Update($arComment["POST_ID"], array("=NUM_COMMENTS" => "NUM_COMMENTS + 1"));
             }
         }
         $strSql = "UPDATE b_blog_comment SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
         $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         unset($GLOBALS["BLOG_COMMENT"]["BLOG_COMMENT_CACHE_" . $ID]);
         $GLOBALS["USER_FIELD_MANAGER"]->Update("BLOG_COMMENT", $ID, $arFields);
         $arComment = CBlogComment::GetByID($ID);
         $arBlog = CBlog::GetByID($arComment["BLOG_ID"]);
         if ($arBlog["USE_SOCNET"] == "Y") {
             $arFields["SC_PERM"] = CBlogComment::GetSocNetCommentPerms($arComment["POST_ID"]);
         }
         $db_events = GetModuleEvents("blog", "OnCommentUpdate");
         while ($arEvent = $db_events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($ID, &$arFields));
         }
         if (CModule::IncludeModule("search")) {
             $newPostPerms = CBlogUserGroup::GetGroupPerms(1, $arComment["BLOG_ID"], $arComment["POST_ID"], BLOG_PERMS_POST);
             if ($arBlog["SEARCH_INDEX"] != "Y" || $arComment["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH) {
                 CSearch::Index("blog", "C" . $ID, array("TITLE" => "", "BODY" => ""));
             } else {
                 $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
                 if (strlen($arFields["PATH"]) > 0) {
                     $arFields["PATH"] = str_replace("#comment_id#", $ID, $arFields["PATH"]);
                     $arPostSite = array($arGroup["SITE_ID"] => $arFields["PATH"]);
                 } elseif (strlen($arComment["PATH"]) > 0) {
                     $arComment["PATH"] = str_replace("#comment_id#", $ID, $arComment["PATH"]);
                     $arPostSite = array($arGroup["SITE_ID"] => $arComment["PATH"]);
                 } else {
                     $arPostSite = array($arGroup["SITE_ID"] => CBlogPost::PreparePath($arBlog["URL"], $arComment["POST_ID"], $arGroup["SITE_ID"], false, $arBlog["OWNER_ID"], $arBlog["SOCNET_GROUP_ID"]));
                 }
                 $searchContent = blogTextParser::killAllTags($arComment["POST_TEXT"]);
                 $searchContent .= "\r\n" . $GLOBALS["USER_FIELD_MANAGER"]->OnSearchIndex("BLOG_COMMENT", $arComment["ID"]);
                 $authorName = "";
                 if (IntVal($arComment["AUTHOR_ID"]) > 0) {
                     $dbUser = CUser::GetByID($arComment["AUTHOR_ID"]);
                     if ($arUser = $dbUser->Fetch()) {
                         $arTmpUser = array("NAME" => $arUser["NAME"], "LAST_NAME" => $arUser["LAST_NAME"], "SECOND_NAME" => $arUser["SECOND_NAME"], "LOGIN" => $arUser["LOGIN"]);
                         $authorName = CUser::FormatName(CSite::GetNameFormat(), $arTmpUser, false, false);
                     }
                 } elseif (strlen($arComment["AUTHOR_NAME"]) > 0) {
                     $authorName = $arComment["AUTHOR_NAME"];
                 }
                 if (strlen($authorName) > 0) {
                     $searchContent .= "\r\n" . $authorName;
                 }
                 $arSearchIndex = array("SITE_ID" => $arPostSite, "LAST_MODIFIED" => $arComment["DATE_CREATE"], "PARAM1" => "COMMENT", "PARAM2" => $arComment["BLOG_ID"] . "|" . $arComment["POST_ID"], "PERMISSIONS" => array(2), "TITLE" => $arComment["TITLE"], "BODY" => $searchContent, "USER_ID" => IntVal($arComment["AUTHOR_ID"]) > 0 ? $arComment["AUTHOR_ID"] : false, "ENTITY_TYPE_ID" => "BLOG_COMMENT", "ENTITY_ID" => $arComment["ID"]);
                 if ($arBlog["USE_SOCNET"] == "Y") {
                     if (is_array($arFields["SC_PERM"])) {
                         $arSearchIndex["PERMISSIONS"] = $arFields["SC_PERM"];
                     }
                 }
                 if (strlen($arComment["TITLE"]) <= 0) {
                     //$arPost = CBlogPost::GetByID($arComment["POST_ID"]);
                     $arSearchIndex["TITLE"] = substr($arSearchIndex["BODY"], 0, 100);
                 }
                 CSearch::Index("blog", "C" . $ID, $arSearchIndex, True);
             }
         }
         return $ID;
     }
     return False;
 }
Example #16
0
    if ($_REQUEST['action_target'] == 'selected') {
        $arID = array();
        $dbResultList = CBlogGroup::GetList(array($by => $order), $arFilter, false, false, array("ID"));
        while ($arResult = $dbResultList->Fetch()) {
            $arID[] = $arResult['ID'];
        }
    }
    foreach ($arID as $ID) {
        if (strlen($ID) <= 0) {
            continue;
        }
        switch ($_REQUEST['action']) {
            case "delete":
                @set_time_limit(0);
                $DB->StartTransaction();
                $arBlogGroupTmp = CBlogGroup::GetByID($ID);
                if (!CBlogGroup::Delete($ID)) {
                    $DB->Rollback();
                    if ($ex = $APPLICATION->GetException()) {
                        $lAdmin->AddGroupError($ex->GetString(), $ID);
                    } else {
                        $lAdmin->AddGroupError(GetMessage("BLG_DELETE_ERROR"), $ID);
                    }
                }
                BXClearCache(True, "/" . $arBlogGroupTmp["SITE_ID"] . "/blog/");
                $DB->Commit();
                break;
        }
    }
}
$dbResultList = CBlogGroup::GetList(array($by => $order), $arFilter, false, false, array("ID", "SITE_ID", "NAME"));