Пример #1
0
 public static function Update($ID, $arFields)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID == 1 || $ID == 2) {
         return False;
     }
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CBlogUserGroup::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     }
     $strUpdate = $DB->PrepareUpdate("b_blog_user_group", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strlen($strUpdate) > 0) {
             $strUpdate .= ", ";
         }
         $strUpdate .= $key . "=" . $value . " ";
     }
     if (strlen($strUpdate) > 0) {
         $strSql = "UPDATE b_blog_user_group SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
         $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         unset($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_" . $ID]);
         return $ID;
     }
     return False;
 }
Пример #2
0
 function CheckFields($ACTION, &$arFields, $ID = 0)
 {
     if ((is_set($arFields, "BLOG_ID") || $ACTION == "ADD") && IntVal($arFields["BLOG_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GUGP_EMPTY_BLOG_ID"), "EMPTY_BLOG_ID");
         return false;
     } elseif (is_set($arFields, "BLOG_ID")) {
         $arResult = CBlog::GetByID($arFields["BLOG_ID"]);
         if (!$arResult) {
             $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["BLOG_ID"], GetMessage("BLG_GUGP_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
             return false;
         }
     }
     if ((is_set($arFields, "USER_GROUP_ID") || $ACTION == "ADD") && IntVal($arFields["USER_GROUP_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GUGP_EMPTY_USER_GROUP_ID"), "EMPTY_USER_GROUP_ID");
         return false;
     } elseif (is_set($arFields, "USER_GROUP_ID")) {
         $arResult = CBlogUserGroup::GetByID($arFields["USER_GROUP_ID"]);
         if (!$arResult) {
             $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["USER_GROUP_ID"], GetMessage("BLG_GUGP_ERROR_NO_USER_GROUP")), "ERROR_NO_USER_GROUP");
             return false;
         }
     }
     if ((is_set($arFields, "PERMS_TYPE") || $ACTION == "ADD") && $arFields["PERMS_TYPE"] != BLOG_PERMS_POST && $arFields["PERMS_TYPE"] != BLOG_PERMS_COMMENT) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GUGP_EMPTY_PERMS_TYPE"), "EMPTY_PERMS_TYPE");
         return false;
     }
     if ((is_set($arFields, "PERMS") || $ACTION == "ADD") && strlen($arFields["PERMS"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GUGP_EMPTY_PERMS"), "EMPTY_PERMS");
         return false;
     } elseif (is_set($arFields, "PERMS")) {
         $arAvailPerms = array_keys($GLOBALS["AR_BLOG_PERMS"]);
         if (!in_array($arFields["PERMS"], $arAvailPerms)) {
             $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["PERMS"], GetMessage("BLG_GUGP_ERROR_NO_PERMS")), "ERROR_NO_PERMS");
             return false;
         }
     }
     if ((is_set($arFields, "AUTOSET") || $ACTION == "ADD") && $arFields["AUTOSET"] != "Y" && $arFields["AUTOSET"] != "N") {
         $arFields["AUTOSET"] = "N";
     }
     return True;
 }
Пример #3
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;
	}
Пример #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;
	}
Пример #5
0
									<td><?php 
            echo GetMessage("BLOG_REG_USERS");
            ?>
</td>
									<td><?php 
            echo ShowSelectPerms('p', 2, $arUGperms_p[2]);
            ?>
</td>
									<td><?php 
            echo ShowSelectPerms('c', 2, $arUGperms_c[2]);
            ?>
</td>
								</tr>
								
						<?php 
            $res = CBlogUserGroup::GetList(array(), $arFilter = array("BLOG_ID" => $BLOG_ID));
            while ($aUGroup = $res->Fetch()) {
                print "\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>" . htmlspecialchars($aUGroup['NAME']) . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . ShowSelectPerms('p', $aUGroup['ID'], $arUGperms_p[$aUGroup['ID']]) . "</td>\n\t\t\t\t\t\t\t\t\t<td>" . ShowSelectPerms('c', $aUGroup['ID'], $arUGperms_c[$aUGroup['ID']]) . "</td>\n\t\t\t\t\t\t\t\t</tr>";
            }
            ?>
							</table>
							</div>
					</td>
				</tr>

			<?php 
            if (COption::GetOptionString("blog", "enable_trackback", "N") == "Y" && $arBlog["ALLOW_TRACKBACK"] == "Y") {
                ?>
				<tr>
					<td class="blogtablehead" valign=top align=right nowrap>
					<font class="blogheadtext">
Пример #6
0
 function OnSearchReindex($NS = array(), $oCallback = NULL, $callback_method = "")
 {
     global $DB;
     $arResult = array();
     //CBlogSearch::Trace('OnSearchReindex', 'NS', $NS);
     if ($NS["MODULE"] == "blog" && strlen($NS["ID"]) > 0) {
         $category = substr($NS["ID"], 0, 1);
         $id = intval(substr($NS["ID"], 1));
     } else {
         $category = 'B';
         //start with blogs
         $id = 0;
         //very first id
     }
     //CBlogSearch::Trace('OnSearchReindex', 'category+id', array("CATEGORY"=>$category,"ID"=>$id));
     //Reindex blogs
     if ($category == 'B') {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tb.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t,b.REAL_URL\n\t\t\t\t\t,b.URL\n\t\t\t\t\t," . $DB->DateToCharFunction("b.DATE_UPDATE") . " as DATE_UPDATE\n\t\t\t\t\t,b.NAME\n\t\t\t\t\t,b.DESCRIPTION\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,b.SOCNET_GROUP_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\tFROM\n\t\t\t\t\tb_blog b\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)\n\t\t\t\tWHERE\n\t\t\t\t\tb.ACTIVE = 'Y'\n\t\t\t\t\tAND b.SEARCH_INDEX = 'Y'\n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? "AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND b.ID > " . $id . "\n\t\t\t\tORDER BY\n\t\t\t\t\tb.ID\n\t\t\t";
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             if ($ar["USE_SOCNET"] == "Y") {
                 $Result = array("ID" => "B" . $ar["ID"], "BODY" => "", "TITLE" => "");
             } else {
                 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
                 $arSite = array($ar["SITE_ID"] => CBlog::PreparePath($ar["URL"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]));
                 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
                 $Result = array("ID" => "B" . $ar["ID"], "LAST_MODIFIED" => $ar["DATE_UPDATE"], "TITLE" => $ar["NAME"], "BODY" => blogTextParser::killAllTags($ar["DESCRIPTION"]), "SITE_ID" => $arSite, "PARAM1" => "BLOG", "PARAM2" => $ar["OWNER_ID"], "PERMISSIONS" => array(2));
                 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
             }
             if ($oCallback) {
                 $res = call_user_func(array($oCallback, $callback_method), $Result);
                 if (!$res) {
                     return $Result["ID"];
                 }
             } else {
                 $arResult[] = $Result;
             }
         }
         //all blogs indexed so let's start index posts
         $category = 'P';
         $id = 0;
     }
     if ($category == 'P') {
         $arUser2Blog = array();
         if (COption::GetOptionString("blog", "socNetNewPerms", "N") == "N") {
             $dbB = CBlog::GetList(array(), array("USE_SOCNET" => "Y", "!OWNER_ID" => false), false, false, array("ID", "OWNER_ID", "USE_SOCNET", "GROUP_ID"));
             while ($arB = $dbB->Fetch()) {
                 $arUser2Blog[$arB["OWNER_ID"]][$arB["GROUP_ID"]] = $arB["ID"];
             }
         }
         $bSonet = false;
         if (IsModuleInstalled("socialnetwork")) {
             $bSonet = true;
         }
         $parserBlog = new blogTextParser(false, "/bitrix/images/blog/smile/");
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tbp.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t,b.REAL_URL\n\t\t\t\t\t,b.URL\n\t\t\t\t\t," . $DB->DateToCharFunction("bp.DATE_PUBLISH") . " as DATE_PUBLISH\n\t\t\t\t\t,bp.TITLE\n\t\t\t\t\t,bp.DETAIL_TEXT\n\t\t\t\t\t,bp.BLOG_ID\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,bp.CATEGORY_ID\n\t\t\t\t\t,b.SOCNET_GROUP_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\t\t,b.GROUP_ID\n\t\t\t\t\t,bp.PATH\n\t\t\t\t\t,bp.MICRO\n\t\t\t\t\t,bp.PUBLISH_STATUS\n\t\t\t\t\t,bp.AUTHOR_ID " . ($bSonet ? ", BSL.ID as SLID" : "") . " FROM\n\t\t\t\t\tb_blog_post bp\n\t\t\t\t\tINNER JOIN b_blog b ON (bp.BLOG_ID = b.ID)\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID) " . ($bSonet ? "LEFT JOIN b_sonet_log BSL ON (BSL.EVENT_ID in ('blog_post', 'blog_post_micro') AND BSL.SOURCE_ID = bp.ID) " : "") . " WHERE\n\t\t\t\t\tbp.DATE_PUBLISH <= " . $DB->CurrentTimeFunction() . "\n\t\t\t\t\tAND b.ACTIVE = 'Y'\n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? "AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND bp.ID > " . $id . "\n\t\t\t\t\t\n\t\t\t\tORDER BY\n\t\t\t\t\tbp.ID\n\t\t\t";
         /*		AND bp.PUBLISH_STATUS = '".$DB->ForSQL(BLOG_PUBLISH_STATUS_PUBLISH)."'*/
         //AND b.SEARCH_INDEX = 'Y'
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             //Check permissions
             $tag = "";
             if ($ar["USE_SOCNET"] != "Y") {
                 $PostPerms = CBlogUserGroup::GetGroupPerms(1, $ar["BLOG_ID"], $ar["ID"], BLOG_PERMS_POST);
                 if ($PostPerms < BLOG_PERMS_READ) {
                     continue;
                 }
             }
             //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
             if (strlen($ar["PATH"]) > 0) {
                 $arSite = array($ar["SITE_ID"] => str_replace("#post_id#", $ar["ID"], $ar["PATH"]));
             } else {
                 $arSite = array($ar["SITE_ID"] => CBlogPost::PreparePath($ar["URL"], $ar["ID"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]));
             }
             if (strlen($ar["CATEGORY_ID"]) > 0) {
                 $arC = explode(",", $ar["CATEGORY_ID"]);
                 $tag = "";
                 $arTag = array();
                 foreach ($arC as $v) {
                     $arCategory = CBlogCategory::GetByID($v);
                     $arTag[] = $arCategory["NAME"];
                 }
                 $tag = implode(",", $arTag);
             }
             //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
             $Result = array("ID" => "P" . $ar["ID"], "LAST_MODIFIED" => $ar["DATE_PUBLISH"], "TITLE" => blogTextParser::killAllTags($ar["TITLE"]), "BODY" => blogTextParser::killAllTags($ar["DETAIL_TEXT"]), "SITE_ID" => $arSite, "PARAM1" => "POST", "PARAM2" => $ar["BLOG_ID"], "PERMISSIONS" => array(2), "TAGS" => $tag, "USER_ID" => $ar["AUTHOR_ID"], "ENTITY_TYPE_ID" => "BLOG_POST", "ENTITY_ID" => $ar["ID"]);
             if ($ar["USE_SOCNET"] == "Y" && CModule::IncludeModule("socialnetwork")) {
                 $arF = array();
                 if (COption::GetOptionString("blog", "socNetNewPerms", "N") == "N") {
                     if (IntVal($ar["SOCNET_GROUP_ID"]) > 0) {
                         $newBlogId = 0;
                         if (IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]) > 0) {
                             $newBlogId = IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]);
                         } else {
                             $arFields = array("=DATE_UPDATE" => $DB->CurrentTimeFunction(), "GROUP_ID" => $ar["GROUP_ID"], "ACTIVE" => "Y", "ENABLE_COMMENTS" => "Y", "ENABLE_IMG_VERIF" => "Y", "EMAIL_NOTIFY" => "Y", "ENABLE_RSS" => "Y", "ALLOW_HTML" => "N", "ENABLE_TRACKBACK" => "N", "SEARCH_INDEX" => "Y", "USE_SOCNET" => "Y", "=DATE_CREATE" => $DB->CurrentTimeFunction(), "PERMS_POST" => array(1 => "I", 2 => "I"), "PERMS_COMMENT" => array(1 => "P", 2 => "P"));
                             $bRights = false;
                             $rsUser = CUser::GetByID($ar["AUTHOR_ID"]);
                             $arUser = $rsUser->Fetch();
                             if (strlen($arUser["NAME"] . "" . $arUser["LAST_NAME"]) <= 0) {
                                 $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["LOGIN"];
                             } else {
                                 $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["NAME"] . " " . $arUser["LAST_NAME"];
                             }
                             $arFields["URL"] = str_replace(" ", "_", $arUser["LOGIN"]) . "-blog-" . $ar["SITE_ID"];
                             $arFields["OWNER_ID"] = $ar["AUTHOR_ID"];
                             $urlCheck = preg_replace("/[^a-zA-Z0-9_-]/is", "", $arFields["URL"]);
                             if ($urlCheck != $arFields["URL"]) {
                                 $arFields["URL"] = "u" . $arUser["ID"] . "-blog-" . $ar["SITE_ID"];
                             }
                             if (CBlog::GetByUrl($arFields["URL"])) {
                                 $uind = 0;
                                 do {
                                     $uind++;
                                     $arFields["URL"] = $arFields["URL"] . $uind;
                                 } while (CBlog::GetByUrl($arFields["URL"]));
                             }
                             $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ar["AUTHOR_ID"], "blog", "view_post");
                             if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL) {
                                 $bRights = true;
                             }
                             $blogID = CBlog::Add($arFields);
                             if ($bRights) {
                                 CBlog::AddSocnetRead($blogID);
                             }
                             $newBlogId = $blogID;
                             $arUser2Blog[$arFields["OWNER_ID"]][$arFields["GROUP_ID"]] = $newBlogId;
                         }
                         if (intVal($newBlogId) > 0) {
                             $arF = array("BLOG_ID" => $newBlogId, "SOCNET_RIGHTS" => array("SG" . $ar["SOCNET_GROUP_ID"]));
                         }
                         if (IntVal($ar["SLID"]) > 0) {
                             CSocNetLog::Delete($ar["SLID"]);
                             $ar["SLID"] = 0;
                         }
                         $arSites = array();
                         $rsGroupSite = CSocNetGroup::GetSite($ar["SOCNET_GROUP_ID"]);
                         while ($arGroupSite = $rsGroupSite->Fetch()) {
                             $arSites[] = $arGroupSite["LID"];
                         }
                     } else {
                         $newBlogId = 0;
                         if ($ar["OWNER_ID"] != $ar["AUTHOR_ID"]) {
                             if (IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]) > 0) {
                                 $newBlogId = IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]);
                             } else {
                                 $arFields = array("=DATE_UPDATE" => $DB->CurrentTimeFunction(), "GROUP_ID" => $ar["GROUP_ID"], "ACTIVE" => "Y", "ENABLE_COMMENTS" => "Y", "ENABLE_IMG_VERIF" => "Y", "EMAIL_NOTIFY" => "Y", "ENABLE_RSS" => "Y", "ALLOW_HTML" => "N", "ENABLE_TRACKBACK" => "N", "SEARCH_INDEX" => "Y", "USE_SOCNET" => "Y", "=DATE_CREATE" => $DB->CurrentTimeFunction(), "PERMS_POST" => array(1 => "I", 2 => "I"), "PERMS_COMMENT" => array(1 => "P", 2 => "P"));
                                 $bRights = false;
                                 $rsUser = CUser::GetByID($ar["AUTHOR_ID"]);
                                 $arUser = $rsUser->Fetch();
                                 if (strlen($arUser["NAME"] . "" . $arUser["LAST_NAME"]) <= 0) {
                                     $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["LOGIN"];
                                 } else {
                                     $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["NAME"] . " " . $arUser["LAST_NAME"];
                                 }
                                 $arFields["URL"] = str_replace(" ", "_", $arUser["LOGIN"]) . "-blog-" . $ar["SITE_ID"];
                                 $arFields["OWNER_ID"] = $ar["AUTHOR_ID"];
                                 $urlCheck = preg_replace("/[^a-zA-Z0-9_-]/is", "", $arFields["URL"]);
                                 if ($urlCheck != $arFields["URL"]) {
                                     $arFields["URL"] = "u" . $arUser["ID"] . "-blog-" . $ar["SITE_ID"];
                                 }
                                 if (CBlog::GetByUrl($arFields["URL"])) {
                                     $uind = 0;
                                     do {
                                         $uind++;
                                         $arFields["URL"] = $arFields["URL"] . $uind;
                                     } while (CBlog::GetByUrl($arFields["URL"]));
                                 }
                                 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ar["AUTHOR_ID"], "blog", "view_post");
                                 if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL) {
                                     $bRights = true;
                                 }
                                 $blogID = CBlog::Add($arFields);
                                 if ($bRights) {
                                     CBlog::AddSocnetRead($blogID);
                                 }
                                 $newBlogId = $blogID;
                                 $arUser2Blog[$arFields["OWNER_ID"]][$arFields["GROUP_ID"]] = $newBlogId;
                             }
                             if (IntVal($ar["SLID"]) > 0) {
                                 CSocNetLog::Delete($ar["SLID"]);
                                 $ar["SLID"] = 0;
                             }
                         }
                         $arF = array("SOCNET_RIGHTS" => array());
                         if (intVal($newBlogId) > 0) {
                             $arF["BLOG_ID"] = $newBlogId;
                         }
                         $arSites = array($ar["SITE_ID"]);
                     }
                     if (!empty($arF)) {
                         if (IntVal($arF["BLOG_ID"]) > 0) {
                             $Result["PARAM2"] = $ar["BLOG_ID"];
                             $sqlR = "UPDATE b_blog_post SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                             $sqlR = "UPDATE b_blog_post_category SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE POST_ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                             $sqlR = "UPDATE b_blog_image SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE POST_ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                             $sqlR = "UPDATE b_blog_comment SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE POST_ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                         $sqlR = "SELECT * FROM b_blog_socnet_rights where POST_ID=" . IntVal($ar["ID"]);
                         $dbBB = $DB->Query($sqlR);
                         if (!$dbBB->Fetch()) {
                             $arF["SC_PERM"] = CBlogPost::UpdateSocNetPerms($ar["ID"], $arF["SOCNET_RIGHTS"], array("AUTHOR_ID" => $ar["AUTHOR_ID"]));
                         }
                         if (IntVal($arF["BLOG_ID"]) > 0 && $ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH) {
                             $dbComment = CBlogComment::GetList(array(), array("POST_ID" => $ar["ID"]), false, false, array("ID", "POST_ID", "BLOG_ID", "PATH"));
                             if ($arComment = $dbComment->Fetch()) {
                                 $arParamsComment = array("BLOG_ID" => $arF["BLOG_ID"], "POST_ID" => $ar["ID"], "SITE_ID" => $ar["SITE_ID"], "PATH" => $arPostSite[$arGroup["SITE_ID"]] . "?commentId=#comment_id###comment_id#", "USE_SOCNET" => "Y");
                                 CBlogComment::_IndexPostComments($arParamsComment);
                             }
                         }
                     }
                 }
                 if ($ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH) {
                     if (empty($arF["SC_PERM"])) {
                         $arF["SC_PERM"] = CBlogPost::GetSocNetPermsCode($ar["ID"]);
                     }
                     $Result["PERMISSIONS"] = $arF["SC_PERM"];
                     if (IntVal($ar["SLID"]) <= 0) {
                         $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "TABLE" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
                         $text4message = $parserBlog->convert($ar["DETAIL_TEXT"], false, array(), $arAllow, array("isSonetLog" => true));
                         $arSoFields = array("EVENT_ID" => "blog_post", "=LOG_DATE" => $DB->CharToDateFunction($ar["DATE_PUBLISH"], "FULL", SITE_ID), "LOG_UPDATE" => $DB->CharToDateFunction($ar["DATE_PUBLISH"], "FULL", SITE_ID), "TITLE_TEMPLATE" => "#USER_NAME# add post", "TITLE" => $ar["TITLE"], "MESSAGE" => $text4message, "MODULE_ID" => "blog", "CALLBACK_FUNC" => false, "SOURCE_ID" => $ar["ID"], "ENABLE_COMMENTS" => "N", "ENTITY_TYPE" => SONET_ENTITY_USER, "ENTITY_ID" => $ar["AUTHOR_ID"], "USER_ID" => $ar["AUTHOR_ID"], "URL" => $arSite[$ar["SITE_ID"]], "SITE_ID" => $arSites);
                         $logID = CSocNetLog::Add($arSoFields, false);
                         if (intval($logID) > 0) {
                             $socnetPerms = $arF["SC_PERM"];
                             if (!in_array("U" . $ar["AUTHOR_ID"], $socnetPerms)) {
                                 $socnetPerms[] = "U" . $ar["AUTHOR_ID"];
                             }
                             $socnetPerms[] = "SA";
                             // socnet admin
                             CSocNetLog::Update($logID, array("TMP_ID" => $logID, "=LOG_UPDATE" => $arSoFields["LOG_UPDATE"]));
                             CSocNetLogRights::DeleteByLogID($logID);
                             CSocNetLogRights::Add($logID, $socnetPerms);
                         }
                     } else {
                         $socnetPerms = $arF["SC_PERM"];
                         if (!in_array("U" . $ar["AUTHOR_ID"], $socnetPerms)) {
                             $socnetPerms[] = "U" . $ar["AUTHOR_ID"];
                         }
                         $socnetPerms[] = "SA";
                         // socnet admin
                         CSocNetLogRights::DeleteByLogID($ar["SLID"]);
                         CSocNetLogRights::Add($ar["SLID"], $socnetPerms);
                     }
                 }
             }
             if ($ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $ar["SEARCH_INDEX"] == "Y") {
                 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
                 if ($oCallback) {
                     $res = call_user_func(array($oCallback, $callback_method), $Result);
                     if (!$res) {
                         return $Result["ID"];
                     }
                 } else {
                     $arResult[] = $Result;
                 }
             }
         }
         //all blog posts indexed so let's start index users
         $category = 'C';
         $id = 0;
         COption::SetOptionString("blog", "socNetNewPerms", "Y");
     }
     if ($category == 'C') {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tbc.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t,bp.ID as POST_ID\n\t\t\t\t\t,b.URL\n\t\t\t\t\t,bp.TITLE as POST_TITLE\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,b.SOCNET_GROUP_ID\n\t\t\t\t\t,bc.TITLE\n\t\t\t\t\t,bc.POST_TEXT\n\t\t\t\t\t,bc.POST_ID\n\t\t\t\t\t,bc.BLOG_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\t\t,bc.PATH\n\t\t\t\t\t," . $DB->DateToCharFunction("bc.DATE_CREATE") . " as DATE_CREATE\n\t\t\t\t\t,bc.AUTHOR_ID\n\t\t\t\tFROM\n\t\t\t\t\tb_blog_comment bc\n\t\t\t\t\tINNER JOIN b_blog_post bp ON (bp.ID = bc.POST_ID)\n\t\t\t\t\tINNER JOIN b_blog b ON (bc.BLOG_ID = b.ID)\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)\n\t\t\t\tWHERE\n\t\t\t\t\tbc.ID > " . $id . " \n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? " AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND b.SEARCH_INDEX = 'Y'\n\t\t\t\tORDER BY\n\t\t\t\t\tbc.ID\n\t\t\t";
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             //Check permissions
             $tag = "";
             $PostPerms = CBlogUserGroup::GetGroupPerms(1, $ar["BLOG_ID"], $ar["POST_ID"], BLOG_PERMS_POST);
             if ($PostPerms < BLOG_PERMS_READ) {
                 continue;
             }
             //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
             if (strlen($ar["PATH"]) > 0) {
                 $arSite = array($ar["SITE_ID"] => str_replace("#comment_id#", $ar["ID"], $ar["PATH"]));
             } else {
                 $arSite = array($ar["SITE_ID"] => CBlogPost::PreparePath($ar["URL"], $ar["POST_ID"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]));
             }
             $Result = array("ID" => "C" . $ar["ID"], "SITE_ID" => $arSite, "LAST_MODIFIED" => $ar["DATE_CREATE"], "PARAM1" => "COMMENT", "PARAM2" => $ar["BLOG_ID"] . "|" . $ar["POST_ID"], "PERMISSIONS" => array(2), "TITLE" => $ar["TITLE"], "BODY" => blogTextParser::killAllTags($ar["POST_TEXT"]), "INDEX_TITLE" => false, "USER_ID" => IntVal($ar["AUTHOR_ID"]) > 0 ? $ar["AUTHOR_ID"] : false, "ENTITY_TYPE_ID" => "BLOG_COMMENT", "ENTITY_ID" => $ar["ID"]);
             if ($ar["USE_SOCNET"] == "Y") {
                 $arSp = CBlogComment::GetSocNetCommentPerms($ar["POST_ID"]);
                 if (is_array($arSp)) {
                     $Result["PERMISSIONS"] = $arSp;
                 }
             }
             if (strlen($ar["TITLE"]) <= 0) {
                 $Result["TITLE"] = substr($Result["BODY"], 0, 100);
             }
             if ($oCallback) {
                 $res = call_user_func(array($oCallback, $callback_method), $Result);
                 if (!$res) {
                     return $Result["ID"];
                 }
             } else {
                 $arResult[] = $Result;
             }
         }
         //all blog posts indexed so let's start index users
         $category = 'U';
         $id = 0;
     }
     if ($category == 'U') {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tbu.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t," . $DB->DateToCharFunction("bu.LAST_VISIT") . " as LAST_VISIT\n\t\t\t\t\t," . $DB->DateToCharFunction("u.DATE_REGISTER") . " as DATE_REGISTER\n\t\t\t\t\t,bu.ALIAS\n\t\t\t\t\t,bu.DESCRIPTION\n\t\t\t\t\t,bu.INTERESTS\n\t\t\t\t\t,u.NAME\n\t\t\t\t\t,u.LAST_NAME\n\t\t\t\t\t,u.LOGIN\n\t\t\t\t\t,bu.USER_ID\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\tFROM\n\t\t\t\t\tb_blog_user bu\n\t\t\t\t\tINNER JOIN b_user u  ON (u.ID = bu.USER_ID)\n\t\t\t\t\tINNER JOIN b_blog b ON (u.ID = b.OWNER_ID)\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)\n\t\t\t\tWHERE\n\t\t\t\t\tb.ACTIVE = 'Y'\n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? "AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND bu.ID > " . $id . "\n\t\t\t\t\tAND b.SEARCH_INDEX = 'Y'\n\t\t\t\tORDER BY\n\t\t\t\t\tbu.ID\n\t\t\t";
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             if ($ar["USE_SOCNET"] == "Y") {
                 $Result = array("ID" => "U" . $ar["ID"], "BODY" => "", "TITLE" => "");
             } else {
                 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
                 $arSite = array($ar["SITE_ID"] => CBlogUser::PreparePath($ar["USER_ID"], $ar["SITE_ID"]));
                 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
                 $Result = array("ID" => "U" . $ar["ID"], "LAST_MODIFIED" => $ar["LAST_VISIT"], "TITLE" => CBlogUser::GetUserName($ar["ALIAS"], $ar["NAME"], $ar["LAST_NAME"], $ar["LOGIN"]), "BODY" => blogTextParser::killAllTags($ar["DESCRIPTION"] . " " . $ar["INTERESTS"]), "SITE_ID" => $arSite, "PARAM1" => "USER", "PARAM2" => $ar["ID"], "PERMISSIONS" => array(2));
                 if (strlen($Result["LAST_MODIFIED"]) <= 0) {
                     $Result["LAST_MODIFIED"] = $ar["DATE_REGISTER"];
                 }
             }
             //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
             if ($oCallback) {
                 $res = call_user_func(array($oCallback, $callback_method), $Result);
                 if (!$res) {
                     return $Result["ID"];
                 }
             } else {
                 $arResult[] = $Result;
             }
         }
     }
     if ($oCallback) {
         return false;
     }
     return $arResult;
 }
Пример #7
0
         $arResult["Candidate"] = array();
         while ($arUsers = $dbUsers->GetNext()) {
             $arUsers["urlToUser"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arUsers["USER_ID"]));
             $arUsers["NameFormated"] = CBlogUser::GetUserName($arUsers["BLOG_USER_ALIAS"], $arUsers["USER_NAME"], $arUsers["USER_LAST_NAME"], $arUsers["USER_LOGIN"]);
             $arUsers["urlToEdit"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER_SETTINGS_EDIT"], array("user_id" => $arUsers["USER_ID"], "blog" => $arBlog["URL"]));
             $arUsers["urlToDelete"] = htmlspecialcharsex($APPLICATION->GetCurPageParam("del_id=" . $arUsers["USER_ID"] . '&' . bitrix_sessid_get(), array("del_id", "sessid")));
             $arResult["Candidate"][] = $arUsers;
         }
         $dbUsers = CBlogUser::GetList($arOrderBy, array("GROUP_BLOG_ID" => $arBlog["ID"]), array("ID", "USER_ID", "ALIAS", "USER_LOGIN", "USER_NAME", "USER_LAST_NAME"));
         $arResult["Users"] = array();
         while ($arUsers = $dbUsers->GetNext()) {
             $arUsers["urlToUser"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arUsers["USER_ID"]));
             $arUsers["NameFormated"] = CBlogUser::GetUserName($arUsers["BLOG_USER_ALIAS"], $arUsers["USER_NAME"], $arUsers["USER_LAST_NAME"], $arUsers["USER_LOGIN"]);
             $arUsers["urlToEdit"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER_SETTINGS_EDIT"], array("user_id" => $arUsers["USER_ID"], "blog" => $arBlog["URL"]));
             $arUsers["urlToDelete"] = htmlspecialcharsex($APPLICATION->GetCurPageParam("del_id=" . $arUsers["USER_ID"] . '&' . bitrix_sessid_get(), array("del_id", "sessid")));
             $dbUserGroups = CBlogUserGroup::GetList(array(), array("USER2GROUP_USER_ID" => $arUsers["USER_ID"], "BLOG_ID" => $arBlog["ID"]), false, false, array("ID", "NAME"));
             $bNeedComa = False;
             while ($arUserGroups = $dbUserGroups->GetNext()) {
                 if ($bNeedComa) {
                     $arUsers["groupsFormated"] .= ", ";
                 }
                 $arUsers["groups"][] = $arUserGroups;
                 $arUsers["groupsFormated"] .= $arUserGroups["NAME"];
                 $bNeedComa = True;
             }
             $arResult["Users"][] = $arUsers;
         }
     } else {
         $arResult["FATAL_ERROR"] = GetMessage("B_B_US_NO_RIGHT");
     }
 } else {
Пример #8
0
 function AddToUserGroup($ID, $blogID, $arGroups = array(), $joinStatus = "Y", $selectType = BLOG_BY_BLOG_USER_ID, $action = BLOG_CHANGE)
 {
     global $DB;
     $ID = IntVal($ID);
     $blogID = IntVal($blogID);
     if (!is_array($arGroups)) {
         $arGroups = array($arGroups);
     }
     $joinStatus = $joinStatus == "Y" ? "Y" : "N";
     $selectType = $selectType == BLOG_BY_USER_ID ? BLOG_BY_USER_ID : BLOG_BY_BLOG_USER_ID;
     $action = $action == BLOG_ADD ? BLOG_ADD : BLOG_CHANGE;
     $bSuccess = True;
     $arResult = CBlog::GetByID($blogID);
     if (!$arResult) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $blogID, GetMessage("BLG_GU_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
         $bSuccess = False;
     }
     if ($bSuccess) {
         $arUser = CBlogUser::GetByID($ID, $selectType);
         $dbResult = CUser::GetByID($arUser["USER_ID"]);
         if (!$dbResult->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GU_ERROR_NO_USER_ID"), "ERROR_NO_USER_ID");
             $bSuccess = False;
         }
     }
     if ($bSuccess) {
         if ($action == BLOG_CHANGE) {
             $DB->Query("DELETE FROM b_blog_user2user_group " . "WHERE USER_ID = " . IntVal($arUser["USER_ID"]) . " " . "\tAND BLOG_ID = " . $blogID . " ");
         }
         if (count($arGroups) > 0) {
             array_walk($arGroups, create_function("&\$item", "\$item=IntVal(\$item);"));
             $dbUserGroups = CBlogUserGroup::GetList(array(), array("ID" => $arGroups, "BLOG_ID" => $blogID), false, false, array("ID"));
             $arGroups = array();
             while ($arUserGroup = $dbUserGroups->Fetch()) {
                 $arGroups[] = IntVal($arUserGroup["ID"]);
             }
             if ($action == BLOG_ADD) {
                 $arCurrentGroups = CBlogUser::GetUserGroups($ID, $blogID, "", $selectType);
             }
             foreach ($arGroups as $val) {
                 if ($val != 1 && $val != 2) {
                     if ($action == BLOG_CHANGE || $action == BLOG_ADD && !in_array($val, $arCurrentGroups)) {
                         $DB->Query("INSERT INTO b_blog_user2user_group (USER_ID, BLOG_ID, USER_GROUP_ID) " . "VALUES (" . IntVal($arUser["USER_ID"]) . ", " . $blogID . ", " . IntVal($val) . ")");
                     }
                 }
             }
         }
         unset($GLOBALS["BLOG_USER"]["BLOG_USER2GROUP_CACHE_" . $arUser["ID"]]);
         unset($GLOBALS["BLOG_USER"]["BLOG_USER2GROUP1_CACHE_" . $arUser["USER_ID"]]);
     }
     return $bSuccess;
 }
Пример #9
0
                        }
                    }
                    if (strlen($arResult["ERROR_MESSAGE"]) <= 0) {
                        LocalRedirect($_POST["BACK_URL"]);
                    }
                }
                if (strlen($_POST["BACK_URL"]) > 0) {
                    $arResult["BACK_URL"] = htmlspecialcharsbx($_POST["BACK_URL"]);
                } else {
                    $arResult["BACK_URL"] = htmlspecialcharsbx($APPLICATION->GetCurPageParam());
                }
                $res = CBlogUserGroup::GetList(array("NAME" => "ASC"), array("BLOG_ID" => $arBlog["ID"]), array("ID", "NAME", "BLOG_ID", "COUNT" => "USER2GROUP_ID"));
                while ($arGroup = $res->Fetch()) {
                    $arSumGroup[$arGroup["ID"]] = $arGroup["CNT"];
                }
                $res = CBlogUserGroup::GetList($arOrder = array("NAME" => "ASC"), $arFilter = array("BLOG_ID" => $arBlog["ID"]));
                while ($arGroupCount = $res->GetNext()) {
                    $arGroupCount['CNT'] = IntVal($arSumGroup[$arGroupCount["ID"]]);
                    $arGroupCnt[] = $arGroupCount;
                }
                $arResult["USER_GROUP"] = $arGroupCnt;
            } else {
                $arResult["FATAL_ERROR_MESSAGE"] = GetMessage("BLOG_ERR_NO_RIGHTS");
            }
        } else {
            $arResult["FATAL_ERROR_MESSAGE"] = GetMessage("BLOG_ERR_NO_BLOG");
        }
    } else {
        $arResult["FATAL_ERROR_MESSAGE"] = GetMessage("BLOG_ERR_NO_BLOG");
    }
} else {
Пример #10
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;
 }
Пример #11
0
            echo " selected";
        }
        ?>
><?php 
        echo htmlspecialcharsex($val);
        ?>
</option><?php 
    }
}
?>
			</select>
		</td>
	</tr>
	<?php 
if (IntVal($ID) > 0) {
    $dbGroups = CBlogUserGroup::GetList(array("NAME" => "ASC"), array("BLOG_ID" => $ID));
    while ($arGroup = $dbGroups->Fetch()) {
        ?>
			<tr>
				<td><?php 
        echo htmlspecialcharsbx($arGroup["NAME"]);
        ?>
:</td>
				<td>
					<select name="PERMS_C[<?php 
        echo IntVal($arGroup["ID"]);
        ?>
]">
					<?php 
        reset($GLOBALS["AR_BLOG_PERMS"]);
        while (list($key, $val) = each($GLOBALS["AR_BLOG_PERMS"])) {
Пример #12
0
     if ($arBlogGroup["ID"] == $arResult["BLOG"]["GROUP_ID"]) {
         $arBlogGroup["SELECTED"] = "Y";
     }
     $arBlogGroupTmp[] = $arBlogGroup;
 }
 $arResult["GROUP"] = $arBlogGroupTmp;
 $arResult["AUTO_GROUPS"] = array();
 if (!empty($arBlog)) {
     $arResult["AUTO_GROUPS"] = unserialize($arBlog["AUTO_GROUPS"]);
 }
 if (!empty($arBlog)) {
     $res = CBlogUserGroup::GetList(array("NAME" => "ASC"), array("BLOG_ID" => $arBlog["ID"]), array("ID", "NAME", "BLOG_ID", "COUNT" => "USER2GROUP_ID"));
     while ($arGroup = $res->Fetch()) {
         $arSumGroup[$arGroup["ID"]] = $arGroup["CNT"];
     }
     $res = CBlogUserGroup::GetList(array("ID" => "ASC"), array("BLOG_ID" => $arBlog["ID"]));
     $arUGroupTmp = array();
     while ($arUGroup = $res->GetNext()) {
         if (is_array($arResult["AUTO_GROUPS"]) && in_array($arUGroup["ID"], $arResult["AUTO_GROUPS"])) {
             $arUGroup["CHECKED"] = "Y";
         }
         $arUGroup["CNT"] = IntVal($arSumGroup[$arUGroup["ID"]]);
         $arUGroupTmp[] = $arUGroup;
     }
     $arResult["USER_GROUP"] = $arUGroupTmp;
 } else {
     $arResult["USER_GROUP"][] = array("ID" => 0, "NAME" => GetMessage('BLOG_FRIENDS'), "CNT" => 0);
 }
 $arResult["BLOG_POST_PERMS"] = $GLOBALS["AR_BLOG_POST_PERMS"];
 $arResult["BLOG_COMMENT_PERMS"] = $GLOBALS["AR_BLOG_COMMENT_PERMS"];
 if (!$USER->IsAdmin() && $blogModulePermissions < "W") {
Пример #13
0
                     if (empty($arBlogUser)) {
                         CBlogUser::Add(array("USER_ID" => $arUser["ID"], "=LAST_VISIT" => $DB->GetNowFunction(), "=DATE_REG" => $DB->GetNowFunction(), "ALLOW_POST" => "Y"));
                     }
                     CBlogUser::AddToUserGroup($arUser["ID"], $arBlog["ID"], $GLOBALS["add2groups"], "", BLOG_BY_USER_ID, BLOG_CHANGE);
                     $dbCandidate = CBlogCandidate::GetList(array(), array("BLOG_ID" => $arBlog["ID"], "USER_ID" => $arUser["ID"]));
                     if ($arCandidate = $dbCandidate->Fetch()) {
                         CBlogCandidate::Delete($arCandidate["ID"]);
                     }
                     LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER_SETTINGS"], array("blog" => $arBlog["URL"])));
                 }
                 $arResult["ERROR_MESSAGE"] = $errorMessage;
                 $arResult["OK_MESSAGE"] = $okMessage;
                 $arResult["userName"] = CBlogUser::GetUserName($arBlogUser["ALIAS"], $arUser["NAME"], $arUser["LAST_NAME"], $arUser["LOGIN"]);
                 $arResult["urlToUser"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arUser["ID"]));
                 $arResult["arUserGroups"] = CBlogUser::GetUserGroups($arUser["ID"], $arBlog["ID"], "Y", BLOG_BY_USER_ID);
                 $dbBlogGroups = CBlogUserGroup::GetList(array("NAME" => "ASC"), array("BLOG_ID" => $arBlog["ID"]), false, false, array("ID", "NAME"));
                 while ($arBlogGroups = $dbBlogGroups->GetNext()) {
                     $arResult["Groups"][] = $arBlogGroups;
                 }
             } else {
                 $arResult["FATAL_ERROR"] = GetMessage("B_B_US_NO_RIGHT");
             }
         } else {
             $arResult["FATAL_ERROR"] = GetMessage("B_B_US_NO_BLOG");
         }
     } else {
         $arResult["FATAL_ERROR"] = GetMessage("B_B_US_NO_BLOG");
     }
 } else {
     $arResult["FATAL_ERROR"] = GetMessage("B_B_US_NO_BLOG");
 }
Пример #14
0
 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;
 }
Пример #15
0
 function SetGroupPerms($ID, $blogID, $postID = 0, $permission = BLOG_PERMS_DENY, $permsType = BLOG_PERMS_POST)
 {
     global $DB;
     $ID = IntVal($ID);
     $blogID = IntVal($blogID);
     $postID = IntVal($postID);
     $arAvailPerms = array_keys($GLOBALS["AR_BLOG_PERMS"]);
     if (!in_array($permission, $arAvailPerms)) {
         $permission = $arAvailPerms[0];
     }
     $permsType = $permsType == BLOG_PERMS_COMMENT ? BLOG_PERMS_COMMENT : BLOG_PERMS_POST;
     $bSuccess = True;
     $arUserGroup = CBlogUserGroup::GetByID($ID);
     if (!$arUserGroup) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("BLG_GUG_ERROR_NO_USER_GROUP")), "ERROR_NO_USER_GROUP");
         $bSuccess = False;
     }
     if ($bSuccess) {
         $arBlog = CBlog::GetByID($blogID);
         if (!$arBlog) {
             $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $blogID, GetMessage("BLG_GUG_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
             $bSuccess = False;
         }
     }
     if ($bSuccess) {
         if ($postID > 0) {
             $arPost = CBlogPost::GetByID($postID);
             if (!$arPost) {
                 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $postID, GetMessage("BLG_GUG_ERROR_NO_POST")), "ERROR_NO_POST");
                 $bSuccess = False;
             }
         }
     }
     if ($bSuccess) {
         $oldGroupPerms = CBlogUserGroup::GetGroupPerms(1, $blogID, 0, BLOG_PERMS_POST);
         $DB->StartTransaction();
         $currentPerms = CBlogUserGroup::GetGroupPerms($ID, $blogID, $postID, $permsType);
         if ($currentPerms) {
             if ($currentPerms != $permission) {
                 if ($postID > 0) {
                     $DB->Query("UPDATE b_blog_user_group_perms SET " . "\tPERMS = '" . $DB->ForSql($permission) . "' " . "WHERE BLOG_ID = " . $blogID . " " . "\tAND POST_ID = " . $postID . " " . "\tAND USER_GROUP_ID = " . $ID . "" . "\tAND PERMS_TYPE = '" . $DB->ForSql($permsType) . "'");
                 } else {
                     $DB->Query("UPDATE b_blog_user_group_perms SET " . "\tPERMS = '" . $DB->ForSql($permission) . "' " . "WHERE BLOG_ID = " . $blogID . " " . "\tAND USER_GROUP_ID = " . $ID . " " . "\tAND PERMS_TYPE = '" . $DB->ForSql($permsType) . "'" . "\tAND POST_ID IS NULL ");
                 }
             }
         } else {
             if ($postID > 0) {
                 $DB->Query("INSERT INTO b_blog_user_group_perms (BLOG_ID, USER_GROUP_ID, PERMS_TYPE, POST_ID, PERMS) " . "VALUES (" . $blogID . ", " . $ID . ", '" . $DB->ForSql($permsType) . "', " . $postID . ", '" . $DB->ForSql($permission) . "') ");
             } else {
                 $DB->Query("INSERT INTO b_blog_user_group_perms (BLOG_ID, USER_GROUP_ID, PERMS_TYPE, POST_ID, PERMS) " . "VALUES (" . $blogID . ", " . $ID . ", '" . $DB->ForSql($permsType) . "', null, '" . $DB->ForSql($permission) . "') ");
             }
         }
         $DB->Commit();
         unset($GLOBALS["BLOG_USER_GROUP"]["BLOG_GROUP_PERMS_CACHE_" . $blogID . "_" . $postID . "_" . $permsType . "_" . $ID]);
         unset($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_PERMS_CACHE_" . $blogID . "_" . $postID . "_" . $permsType]);
     }
     if ($bSuccess) {
         if (CModule::IncludeModule("search")) {
             $newGroupPerms = CBlogUserGroup::GetGroupPerms(1, $blogID, 0, BLOG_PERMS_POST);
             if ($oldGroupPerms >= BLOG_PERMS_READ && $newGroupPerms < BLOG_PERMS_READ) {
                 CSearch::DeleteIndex("blog", false, $blogID);
             } elseif ($oldGroupPerms < BLOG_PERMS_READ && $newGroupPerms >= BLOG_PERMS_READ) {
             }
         }
     }
     return $bSuccess;
 }
Пример #16
0
 }
 $groups = $groupID = CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_1")));
 $groups .= ",";
 $groups .= CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_2")));
 $groups .= ",";
 $groups .= CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_3")));
 $groups .= ",";
 $groups .= CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_4")));
 $groups .= ",";
 $groups .= CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_5")));
 $groups .= ",";
 $groups .= CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_6")));
 $groups .= ",";
 $groups .= CBlogGroup::Add(array("SITE_ID" => $siteID, "NAME" => GetMessage("BLOG_DEMO_GROUP_7")));
 $blogID = CBlog::Add(array("NAME" => GetMessage("BLOG_DEMO_BLOG_NAME"), "DESCRIPTION" => GetMessage("BLOG_DEMO_BLOG_NAME"), "GROUP_ID" => $groupID, "ENABLE_IMG_VERIF" => 'Y', "EMAIL_NOTIFY" => 'Y', "ENABLE_RSS" => "Y", "ALLOW_HTML" => "Y", "URL" => "admin-blg", "ACTIVE" => "Y", "=DATE_CREATE" => $DB->GetNowFunction(), "=DATE_UPDATE" => $DB->GetNowFunction(), "OWNER_ID" => 1, "PERMS_POST" => array("1" => BLOG_PERMS_READ, "2" => BLOG_PERMS_READ), "PERMS_COMMENT" => array("1" => BLOG_PERMS_WRITE, "2" => BLOG_PERMS_WRITE)));
 $friends = CBlogUserGroup::Add(array("NAME" => GetMessage("BLOG_DEMO_FRIENDS"), "BLOG_ID" => $blogID));
 CBlogUserGroupPerms::Add(array("BLOG_ID" => $blogID, "USER_GROUP_ID" => $friends, "PERMS_TYPE" => "P", "PERMS" => "I", "AUTOSET" => "N"));
 CBlogUserGroupPerms::Add(array("BLOG_ID" => $blogID, "USER_GROUP_ID" => $friends, "PERMS_TYPE" => "C", "PERMS" => "P", "AUTOSET" => "N"));
 $categoryID[] = CBlogCategory::Add(array("BLOG_ID" => $blogID, "NAME" => GetMessage("BLOG_DEMO_CATEGORY_1")));
 $categoryID[] = CBlogCategory::Add(array("BLOG_ID" => $blogID, "NAME" => GetMessage("BLOG_DEMO_CATEGORY_2")));
 $postID = CBlogPost::Add(array("TITLE" => GetMessage("BLOG_DEMO_MESSAGE_TITLE_1"), "DETAIL_TEXT" => GetMessage("BLOG_DEMO_MESSAGE_BODY_1"), "DETAIL_TEXT_TYPE" => "text", "BLOG_ID" => $blogID, "AUTHOR_ID" => 1, "=DATE_CREATE" => $DB->GetNowFunction(), "=DATE_PUBLISH" => $DB->GetNowFunction(), "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH, "ENABLE_TRACKBACK" => 'N', "ENABLE_COMMENTS" => 'Y', "CATEGORY_ID" => implode(",", $categoryID), "PERMS_P" => array(1 => BLOG_PERMS_READ, 2 => BLOG_PERMS_READ), "PERMS_C" => array(1 => BLOG_PERMS_WRITE, 2 => BLOG_PERMS_WRITE)));
 foreach ($categoryID as $v) {
     CBlogPostCategory::Add(array("BLOG_ID" => $blogID, "POST_ID" => $postID, "CATEGORY_ID" => $v));
 }
 $arImage = CFile::MakeFileArray(dirname(__FILE__) . '/images/' . GetMessage("BLOG_DEMO_IMG"));
 $arImage["MODULE_ID"] = "blog";
 $arFields = array("BLOG_ID" => $blogID, "POST_ID" => $postID, "USER_ID" => 1, "=TIMESTAMP_X" => $DB->GetNowFunction(), "TITLE" => GetMessage("BLOG_DEMO_IMG_TITLE"), "IMAGE_SIZE" => $arImage["size"], "FILE_ID" => $arImage);
 CBlogImage::Add($arFields);
 CBlogComment::Add(array("TITLE" => GetMessage("BLOG_DEMO_COMMENT_TITLE"), "POST_TEXT" => GetMessage("BLOG_DEMO_COMMENT_BODY"), "BLOG_ID" => $blogID, "POST_ID" => $postID, "PARENT_ID" => 0, "AUTHOR_ID" => 1, "DATE_CREATE" => ConvertTimeStamp(false, "FULL"), "AUTHOR_IP" => "192.168.0.108"));
 CBlogSitePath::Add(array("SITE_ID" => $siteID, "PATH" => "/communication/blog/#blog#/", "TYPE" => "B"));
 CBlogSitePath::Add(array("SITE_ID" => $siteID, "PATH" => "/communication/blog/#blog#/#post_id#.php", "TYPE" => "P"));