Example #1
0
 function FormatEvent_Blog($arFields, $arParams, $bMail = false)
 {
     if ($bMail && strlen($arFields["MAIL_LANGUAGE_ID"]) > 0) {
         IncludeModuleLangFile(__FILE__, $arFields["MAIL_LANGUAGE_ID"]);
     }
     $arResult = array("EVENT" => $arFields, "CREATED_BY" => CSocNetLogTools::FormatEvent_GetCreatedBy($arFields, $arParams, $bMail), "ENTITY" => CSocNetLogTools::FormatEvent_GetEntity($arFields, $arParams, $bMail), "EVENT_FORMATTED" => array());
     $arResult["CREATED_BY"]["ACTION_TYPE"] = "wrote";
     if (!$bMail) {
         $arResult["AVATAR_SRC"] = CSocNetLogTools::FormatEvent_CreateAvatar($arFields, $arParams);
     }
     if ($bMail) {
         $title_tmp = GetMessage("SONET_GL_EVENT_TITLE_" . ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP ? "GROUP" : "USER") . "_BLOG_POST_MAIL");
         //if the title duplicates message, don't show it
         $arFields["TITLE"] = strpos($arFields["MESSAGE"], $arFields["TITLE"]) === 0 ? "" : ' "' . $arFields["TITLE"] . '"';
     } else {
         $title_tmp = GetMessage("SONET_GL_EVENT_TITLE_BLOG_POST");
     }
     $post_tmp = !$bMail && array_key_exists("URL", $arFields) && strlen($arFields["URL"]) > 0 ? '<a href="' . $arFields["URL"] . '">' . $arFields["TITLE"] . '</a>' : $arFields["TITLE"];
     $title = str_replace(array("#TITLE#", "#ENTITY#", "#CREATED_BY#"), array($post_tmp, $arResult["ENTITY"]["FORMATTED"], $bMail ? $arResult["CREATED_BY"]["FORMATTED"] : ""), $title_tmp);
     $title = trim(preg_replace('/\\s+/', ' ', $title));
     $arResult["EVENT_FORMATTED"] = array("TITLE" => $title, "TITLE_24" => GetMessage("SONET_GL_EVENT_TITLE_BLOG_POST_24"), "TITLE_24_2" => $arFields["TITLE"], "MESSAGE" => $bMail ? $arFields["TEXT_MESSAGE"] : $arFields["~MESSAGE"]);
     if (!$bMail) {
         if ($arParams["NEW_TEMPLATE"] != "Y" || $arFields["EVENT_ID"] == "idea") {
             if (CModule::IncludeModule("blog")) {
                 $parserLog = new blogTextParser(false, $arParams["PATH_TO_SMILE"]);
                 $arImages = array();
                 $arBlogPost = CBlogPost::GetByID($arFields["SOURCE_ID"]);
                 if ($arBlogPost["HAS_IMAGES"] != "N") {
                     $res = CBlogImage::GetList(array("ID" => "ASC"), array("POST_ID" => $arBlogPost['ID'], "IS_COMMENT" => "N"));
                     while ($arImage = $res->Fetch()) {
                         $arImages[$arImage['ID']] = $arImage['FILE_ID'];
                     }
                 }
             } else {
                 $parserLog = new logTextParser(false, $arParams["PATH_TO_SMILE"]);
             }
             $arAllow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "MULTIPLE_BR" => "N", "VIDEO" => "Y", "LOG_VIDEO" => "N", "SHORT_ANCHOR" => "Y");
             if (get_class($parserLog) == "blogTextParser") {
                 $arResult["EVENT_FORMATTED"]["MESSAGE"] = $parserLog->html_cut($parserLog->convert(htmlspecialcharsback($arResult["EVENT_FORMATTED"]["MESSAGE"]), true, $arImages, $arAllow), 10000);
             } else {
                 $arResult["EVENT_FORMATTED"]["MESSAGE"] = htmlspecialcharsbx($parserLog->convert(htmlspecialcharsback($arResult["EVENT_FORMATTED"]["MESSAGE"]), array(), $arAllow));
             }
             $arResult["EVENT_FORMATTED"]["MESSAGE"] = str_replace("#CUT#", '<br><a href="' . $arFields["URL"] . '">' . GetMessage("SONET_GL_EVENT_BLOG_MORE") . '</a>', $arResult["EVENT_FORMATTED"]["MESSAGE"]);
             $arResult["EVENT_FORMATTED"]["IS_MESSAGE_SHORT"] = CSocNetLogTools::FormatEvent_IsMessageShort($arResult["EVENT_FORMATTED"]["MESSAGE"], $arResult["EVENT_FORMATTED"]["SHORT_MESSAGE"]);
             if ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP) {
                 $arResult["EVENT_FORMATTED"]["DESTINATION"] = array(array("STYLE" => "sonetgroups", "TITLE" => $arResult["ENTITY"]["FORMATTED"]["NAME"], "URL" => $arResult["ENTITY"]["FORMATTED"]["URL"]));
             }
         }
         $dbRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arFields["ID"]));
         while ($arRight = $dbRight->Fetch()) {
             $arRights[] = $arRight["GROUP_CODE"];
         }
         if ($arParams["MOBILE"] == "Y") {
             $arResult["EVENT_FORMATTED"]["DESTINATION"] = CSocNetLogTools::FormatDestinationFromRights($arRights, array_merge($arParams, array("CREATED_BY" => $arFields["USER_ID"], "USE_ALL_DESTINATION" => true)), $iMoreCount);
             if (intval($iMoreCount) > 0) {
                 $arResult["EVENT_FORMATTED"]["DESTINATION_MORE"] = $iMoreCount;
             }
         } else {
             $arResult["EVENT_FORMATTED"]["DESTINATION_CODE"] = CSocNetLogTools::GetDestinationFromRights($arRights, array_merge($arParams, array("CREATED_BY" => $arFields["USER_ID"])));
         }
     } else {
         $url = CSocNetLogTools::FormatEvent_GetURL($arFields);
         if (strlen($url) > 0) {
             $arResult["EVENT_FORMATTED"]["URL"] = $url;
         }
     }
     $arResult["HAS_COMMENTS"] = intval($arFields["SOURCE_ID"]) > 0 ? "Y" : "N";
     if ($bMail && strlen($arFields["MAIL_LANGUAGE_ID"]) > 0) {
         IncludeModuleLangFile(__FILE__, LANGUAGE_ID);
     }
     return $arResult;
 }