Exemple #1
0
 public static function getCommentByRequest($commentId, $postId, $action = false, $checkPerms = true, $checkAdminSession = true)
 {
     $commentId = intval($commentId);
     $postId = intval($postId);
     $arOrder = array();
     $rsLog = CSocNetLog::GetList(array(), array("ID" => $postId), false, false, array("EVENT_ID", "SOURCE_ID"));
     if ($arLog = $rsLog->Fetch()) {
         $arCommentEvent = CSocNetLogTools::FindLogCommentEventByLogEventID($arLog["EVENT_ID"]);
         $arFilter = array("EVENT_ID" => $arCommentEvent["EVENT_ID"]);
         if (isset($arCommentEvent["DELETE_CALLBACK"]) && $arCommentEvent["DELETE_CALLBACK"] != "NO_SOURCE") {
             $arFilter["SOURCE_ID"] = $commentId;
             // forum etc.
         } else {
             $arFilter["ID"] = $commentId;
             // socialnetwork
         }
         $dbRes = CSocNetLogComments::GetList($arOrder, $arFilter, false, false, array("ID", "EVENT_ID", "MESSAGE", "USER_ID", "SOURCE_ID", "LOG_SOURCE_ID", "UF_*"));
         if ($arRes = $dbRes->Fetch()) {
             if ($checkPerms) {
                 $bAllow = CSocNetLogComponent::canUserChangeComment(array("ACTION" => $action, "LOG_ID" => $postId, "LOG_EVENT_ID" => $arLog["EVENT_ID"], "LOG_SOURCE_ID" => $arLog["SOURCE_ID"], "COMMENT_ID" => $arRes["ID"], "COMMENT_USER_ID" => $arRes["USER_ID"], "CHECK_ADMIN_SESSION" => $checkAdminSession ? "Y" : "N"));
             } else {
                 $bAllow = true;
             }
             if (!$bAllow) {
                 $arRes = false;
             } else {
                 if ($action == "edit") {
                     $arUFMeta = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("SONET_COMMENT", 0, LANGUAGE_ID);
                     $arRes["UF"] = array();
                     foreach ($arUFMeta as $field_name => $arUF) {
                         if (array_key_exists($field_name, $arRes) && !empty($arRes[$field_name])) {
                             $arRes["UF"][$field_name] = $arUFMeta[$field_name];
                             $arRes["UF"][$field_name]["VALUE"] = $arRes[$field_name];
                             $arRes["UF"][$field_name]["ENTITY_VALUE_ID"] = $arRes["ID"];
                             unset($arRes[$field_name]);
                         }
                     }
                 }
             }
         }
         return $arRes;
     }
     return false;
 }
Exemple #2
0
             $update_log_id = $arRes["LOG_ID"];
             $update_user_id = $arRes["USER_ID"];
             $update_source_id = $arRes["SOURCE_ID"];
         }
     }
     if (intval($update_id) <= 0) {
         $rsRes = CSocNetLogComments::GetList(array(), array("ID" => $editCommentSourceID), false, false, array("ID", "USER_ID", "LOG_ID", "SOURCE_ID"));
         if ($arRes = $rsRes->Fetch()) {
             $update_id = $arRes["ID"];
             $update_log_id = $arRes["LOG_ID"];
             $update_user_id = $arRes["USER_ID"];
             $update_source_id = $arRes["SOURCE_ID"];
         }
     }
     if (intval($update_id) > 0) {
         $bAllowUpdate = CSocNetLogComponent::canUserChangeComment(array("ACTION" => "EDIT", "LOG_ID" => $update_log_id, "LOG_EVENT_ID" => $arLog["EVENT_ID"], "LOG_SOURCE_ID" => $arLog["SOURCE_ID"], "COMMENT_ID" => $update_id, "COMMENT_USER_ID" => $update_user_id));
     }
     if ($bAllowUpdate) {
         $commentIdres = CSocNetLogComments::Update($update_id, $arFields, true);
     } else {
         $commentIdres = array("MESSAGE" => GetMessage("SONET_LOG_COMMENT_NO_PERMISSIONS_UPDATE"));
     }
 } else {
     $commentIdres = CSocNetLogComments::Add($arFields, true, false);
 }
 if (!is_array($commentIdres) && intval($commentIdres) > 0) {
     if ($editCommentSourceID <= 0) {
         $db_events = GetModuleEvents("socialnetwork", "OnAfterSocNetLogEntryCommentAdd");
         while ($arEvent = $db_events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($arLog));
         }