Exemplo n.º 1
0
 function Request($server, $page, $port, $method, $namespace, $login, $password, $arParams)
 {
     if (!CModule::IncludeModule("webservice")) {
         return false;
     }
     global $APPLICATION;
     $client = new CSOAPClient($server, $page, $port);
     $client->setLogin($login);
     $client->setPassword($password);
     $request = new CSOAPRequest($method, $namespace, $arParams);
     $response = $client->send($request);
     if (is_object($response) && $response->isFault()) {
         if (XDI_XML_ERROR_DEBUG) {
             CXDImport::WriteToLog("ERROR: Incorrect webservice response. Raw response: " . $client->getRawResponse(), "RXML");
         }
         return false;
     } else {
         if (XDI_XML_DEBUG) {
             CXDImport::WriteToLog("Successfull webservice response. Raw response: " . $client->getRawResponse(), "RXML");
         }
         if (is_object($response)) {
             return $response->Value;
         } else {
             return false;
         }
     }
 }
Exemplo n.º 2
0
                $strParams = CharsetConverter::ConvertCharset($_POST["params"], CXDImport::DetectUTF8($_POST["params"]) ? "utf-8" : "windows-1251", SITE_CHARSET);
                if (is_array($strParams)) {
                    $strParams["SCHEME_ID"] = $arScheme["ID"];
                    $strParams = serialize($strParams);
                } else {
                    $strParams = (strlen($strParams) > 0 ? $strParams . "&" : "") . "SCHEME_ID=" . $arScheme["ID"];
                }
            }
            $arSonetFields = array("SITE_ID" => $arScheme["LID"], "ENTITY_TYPE" => $arScheme["ENTITY_TYPE"], "ENTITY_ID" => $arScheme["ENTITY_ID"], "EVENT_ID" => $arScheme["EVENT_ID"], "ENABLE_COMMENTS" => $arScheme["ENABLE_COMMENTS"], "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "TITLE_TEMPLATE" => false, "TITLE" => CharsetConverter::ConvertCharset($_POST["title"], CXDImport::DetectUTF8($_POST["title"]) ? "utf-8" : "windows-1251", SITE_CHARSET), "MESSAGE" => CharsetConverter::ConvertCharset($_POST["message"], CXDImport::DetectUTF8($_POST["message"]) ? "utf-8" : "windows-1251", SITE_CHARSET), "TEXT_MESSAGE" => CharsetConverter::ConvertCharset($_POST["text_message"], CXDImport::DetectUTF8($_POST["text_message"]) ? "utf-8" : "windows-1251", SITE_CHARSET), "URL" => CharsetConverter::ConvertCharset($_POST["url"], CXDImport::DetectUTF8($_POST["url"]) ? "utf-8" : "windows-1251", SITE_CHARSET), "PARAMS" => $strParams, "MODULE_ID" => false, "CALLBACK_FUNC" => false);
            $logID = CSocNetLog::Add($arSonetFields, false);
            if (intval($logID) > 0) {
                $arUpdateFields = array("TMP_ID" => $logID, "RATING_TYPE_ID" => "LOG_ENTRY", "RATING_ENTITY_ID" => $logID);
                CSocNetLog::Update($logID, $arUpdateFields);
                CXDILFScheme::SetSonetLogRights($logID, $arSonetFields["ENTITY_TYPE"], $arScheme["ENTITY_ID"], $arScheme["EVENT_ID"]);
                CSocNetLog::CounterIncrement($logID);
                if ($arScheme["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP && intval($arScheme["ENTITY_ID"]) > 0) {
                    $notify_title_tmp = str_replace(array("\r\n", "\n"), " ", $arScheme["NAME"]);
                    $notify_title = TruncateText($notify_title_tmp, 100);
                    $notify_title_out = TruncateText($notify_title_tmp, 255);
                    $arNotifyParams = array("LOG_ID" => $logID, "GROUP_ID" => intval($arScheme["ENTITY_ID"]), "NOTIFY_MESSAGE" => "", "URL" => "", "MESSAGE" => GetMessage("XLP_IM_ADD", array("#title#" => $notify_title)), "MESSAGE_OUT" => GetMessage("XLP_IM_ADD", array("#title#" => $notify_title_out)), "EXCLUDE_USERS" => array());
                    CSocNetSubscription::NotifyGroup($arNotifyParams);
                }
            }
        }
    } else {
        CXDImport::WriteToLog("ERROR: Incorrect hash: " . $_POST["hash"], "RPOST");
        echo "Incorrect hash!";
    }
} else {
    echo "Incorrect hash length!";
}
Exemplo n.º 3
0
 function CheckRequest()
 {
     global $DB;
     $result = "";
     if (!CModule::IncludeModule("socialnetwork")) {
         return $result;
     }
     $current_time = time();
     $time_of_exec = false;
     $rsScheme = CXDILFScheme::GetList(array(), array("ACTIVE" => "Y", "AUTO" => "Y"));
     while (($arScheme = $rsScheme->Fetch()) && $time_of_exec === false) {
         if ($arScheme["LAST_EXECUTED"] == '') {
             continue;
         }
         $last_executed = MakeTimeStamp(ConvertDateTime($arScheme["LAST_EXECUTED"], "DD.MM.YYYY HH:MI:SS"), "DD.MM.YYYY HH:MI:SS");
         if ($last_executed <= 0) {
             continue;
         }
         $arEventTmp = CSocNetLogTools::FindLogEventByID($arScheme["EVENT_ID"]);
         if (array_key_exists("REAL_EVENT_ID", $arEventTmp) && strlen($arEventTmp["REAL_EVENT_ID"]) > 0) {
             $arScheme["EVENT_ID"] = $arEventTmp["REAL_EVENT_ID"];
         }
         //parse schedule
         $arDoM = CXDImport::ParseDaysOfMonth($arScheme["DAYS_OF_MONTH"]);
         $arDoW = CXDImport::ParseDaysOfWeek($arScheme["DAYS_OF_WEEK"]);
         $arToD = CXDImport::ParseTimesOfDay($arScheme["TIMES_OF_DAY"]);
         if ($arToD) {
             sort($arToD, SORT_NUMERIC);
         }
         $arSDate = localtime($last_executed);
         //sdate = truncate(last_execute)
         $sdate = mktime(0, 0, 0, $arSDate[4] + 1, $arSDate[3], $arSDate[5] + 1900);
         while ($sdate < $current_time && $time_of_exec === false) {
             $arSDate = localtime($sdate);
             if ($arSDate[6] == 0) {
                 $arSDate[6] = 7;
             }
             //determine if date is good for execution
             if ($arDoM) {
                 $flag = array_search($arSDate[3], $arDoM);
                 if ($arDoW) {
                     $flag = array_search($arSDate[6], $arDoW);
                 }
             } elseif ($arDoW) {
                 $flag = array_search($arSDate[6], $arDoW);
             } else {
                 $flag = false;
             }
             if ($flag !== false && $arToD) {
                 foreach ($arToD as $intToD) {
                     if ($sdate + $intToD > $last_executed && $sdate + $intToD <= $current_time) {
                         $time_of_exec = $sdate + $intToD;
                         break;
                     }
                 }
             }
             $sdate = mktime(0, 0, 0, date("m", $sdate), date("d", $sdate) + 1, date("Y", $sdate));
             //next day
         }
         if ($time_of_exec !== false) {
             if ($arScheme["TYPE"] == "XML") {
                 $arParams = array();
                 if (strlen($arScheme["PARAMS"]) > 0) {
                     $arTmp = explode("&", $arScheme["PARAMS"]);
                     if (is_array($arTmp) && count($arTmp) > 0) {
                         foreach ($arTmp as $pair) {
                             list($key, $value) = explode("=", $pair);
                             $arParams[$key] = $value;
                         }
                     }
                 }
                 $arResponse = CXDILFSchemeXML::Request($arScheme["HOST"], $arScheme["PAGE"], $arScheme["PORT"], $arScheme["METHOD"], "http://" . $arScheme["HOST"], $arScheme["LOGIN"], $arScheme["PASSWORD"], $arParams);
                 if ($arResponse && is_array($arResponse)) {
                     if (XDI_DEBUG) {
                         CXDImport::WriteToLog("Successful webservice response, scheme ID: " . $arScheme["ID"], "RXML");
                     }
                     $entityName = $arScheme["NAME"];
                     if ($arScheme["EVENT_ID"] == "news") {
                         $rsIBlock = CIBlock::GetList(array("ID" => "ASC"), array("ACTIVE" => "Y", "TYPE" => "news", "ID" => $arScheme["ENTITY_ID"]));
                         if ($arIBlock = $rsIBlock->Fetch()) {
                             $entityName = $arIBlock["NAME"];
                         }
                     }
                     $arLogParams = array("ENTITY_NAME" => $entityName, "ENTITY_URL" => $arResponse["URL"]);
                     $arSonetFields = array("SITE_ID" => $arScheme["LID"], "ENTITY_TYPE" => $arScheme["ENTITY_TYPE"], "ENTITY_ID" => $arScheme["ENTITY_ID"], "EVENT_ID" => $arScheme["EVENT_ID"], "ENABLE_COMMENTS" => $arScheme["ENABLE_COMMENTS"], "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "TITLE_TEMPLATE" => $arResponse["TITLE"], "TITLE" => $arResponse["TITLE"], "MESSAGE" => $arResponse["MESSAGE"], "TEXT_MESSAGE" => $arResponse["TEXT_MESSAGE"], "URL" => $arResponse["URL"], "PARAMS" => serialize($arLogParams), "MODULE_ID" => false, "CALLBACK_FUNC" => false);
                     $logID = CSocNetLog::Add($arSonetFields, false);
                     if (intval($logID) > 0) {
                         $arUpdateFields = array("TMP_ID" => $logID, "RATING_TYPE_ID" => "LOG_ENTRY", "RATING_ENTITY_ID" => $logID);
                         CSocNetLog::Update($logID, $arUpdateFields);
                         CXDILFScheme::SetSonetLogRights($logID, $arScheme["ENTITY_TYPE"], $arScheme["ENTITY_ID"], $arScheme["EVENT_ID"]);
                         CSocNetLog::CounterIncrement($logID);
                         if ($arScheme["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP && intval($arScheme["ENTITY_ID"]) > 0) {
                             $notify_title_tmp = str_replace(array("\r\n", "\n"), " ", $arScheme["NAME"]);
                             $notify_title = TruncateText($notify_title_tmp, 100);
                             $notify_title_out = TruncateText($notify_title_tmp, 255);
                             $arNotifyParams = array("LOG_ID" => $logID, "GROUP_ID" => intval($arScheme["ENTITY_ID"]), "NOTIFY_MESSAGE" => "", "URL" => "", "MESSAGE" => GetMessage("LFP_CLASS_SCHEME_IM_ADD", array("#title#" => $notify_title)), "MESSAGE_OUT" => GetMessage("LFP_CLASS_SCHEME_IM_ADD", array("#title#" => $notify_title_out)), "EXCLUDE_USERS" => array());
                             CSocNetSubscription::NotifyGroup($arNotifyParams);
                         }
                     }
                 } else {
                     CXDImport::WriteToLog("ERROR: Incorrect webservice response. Scheme ID: " . $arScheme["ID"] . ", server: " . $arScheme["HOST"] . ", port: " . $arScheme["PORT"] . ", page: " . $arScheme["PAGE"] . ", method: " . $arScheme["METHOD"] . ", params: " . $arScheme["PARAMS"], "RXML");
                 }
             } elseif ($arScheme["TYPE"] == "RSS") {
                 $arResponse = CXDILFSchemeRSS::Request($arScheme["HOST"], $arScheme["PAGE"], $arScheme["PORT"], $arScheme["PARAMS"], $arScheme["URI"]);
                 if ($arResponse && is_array($arResponse) && array_key_exists("item", $arResponse) && is_array($arResponse["item"]) && count($arResponse["item"]) > 0) {
                     if (XDI_DEBUG) {
                         CXDImport::WriteToLog("Successful RSS response. Scheme ID: " . $arScheme["ID"], "RRSS");
                     }
                     foreach ($arResponse["item"] as $arItem) {
                         $checksum = md5(serialize($arItem));
                         $rsLogEvents = CSocNetLog::GetList(array(), array("SITE_ID" => $arScheme["LID"], "ENTITY_TYPE" => $arScheme["ENTITY_TYPE"], "ENTITY_ID" => $arScheme["ENTITY_ID"], "EVENT_ID" => $arScheme["EVENT_ID"], "EXTERNAL_ID" => $checksum), false, array("nTopCount" => 1));
                         $arLogEvent = $rsLogEvents->Fetch();
                         if (!$arLogEvent) {
                             $entityName = $arScheme["NAME"];
                             if ($arScheme["EVENT_ID"] == "news") {
                                 $rsIBlock = CIBlock::GetList(array("ID" => "ASC"), array("ACTIVE" => "Y", "TYPE" => "news", "ID" => $arScheme["ENTITY_ID"]));
                                 if ($arIBlock = $rsIBlock->Fetch()) {
                                     $entityName = $arIBlock["NAME"];
                                 }
                             }
                             $arLogParams = array("SCHEME_ID" => $arScheme["ID"], "ENTITY_NAME" => $entityName, "ENTITY_URL" => $arResponse["link"]);
                             if (strlen($arItem["pubDate"]) > 0) {
                                 $arLogParams["SOURCE_TIMESTAMP"] = strtotime($arItem["pubDate"]);
                             }
                             $description = preg_replace("#^(.*?)([\\s]*<br[\\s]*/>)+[\\s]*[\n]*[\\s]*\$#is", "\\1", $arItem["description"]);
                             $arSonetFields = array("SITE_ID" => $arScheme["LID"], "ENTITY_TYPE" => $arScheme["ENTITY_TYPE"], "ENTITY_ID" => $arScheme["ENTITY_ID"], "EVENT_ID" => $arScheme["EVENT_ID"], "ENABLE_COMMENTS" => $arScheme["ENABLE_COMMENTS"], "TITLE_TEMPLATE" => $arItem["title"], "TITLE" => $arItem["title"], "MESSAGE" => $description, "TEXT_MESSAGE" => "", "URL" => $arItem["link"], "PARAMS" => serialize($arLogParams), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "EXTERNAL_ID" => $checksum, "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction());
                             $logID = CSocNetLog::Add($arSonetFields, false);
                             if (intval($logID) > 0) {
                                 $arUpdateFields = array("TMP_ID" => $logID, "RATING_TYPE_ID" => "LOG_ENTRY", "RATING_ENTITY_ID" => $logID);
                                 CSocNetLog::Update($logID, $arUpdateFields);
                                 CXDILFScheme::SetSonetLogRights($logID, $arScheme["ENTITY_TYPE"], $arScheme["ENTITY_ID"], $arScheme["EVENT_ID"]);
                                 CSocNetLog::CounterIncrement($logID);
                                 if ($arScheme["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP && intval($arScheme["ENTITY_ID"]) > 0) {
                                     $notify_title_tmp = str_replace(array("\r\n", "\n"), " ", $arScheme["NAME"]);
                                     $notify_title = TruncateText($notify_title_tmp, 100);
                                     $notify_title_out = TruncateText($notify_title_tmp, 255);
                                     $arNotifyParams = array("LOG_ID" => $logID, "GROUP_ID" => intval($arScheme["ENTITY_ID"]), "NOTIFY_MESSAGE" => "", "URL" => "", "MESSAGE" => GetMessage("LFP_CLASS_SCHEME_IM_ADD", array("#title#" => $notify_title)), "MESSAGE_OUT" => GetMessage("LFP_CLASS_SCHEME_IM_ADD", array("#title#" => $notify_title_out)), "EXCLUDE_USERS" => array());
                                     CSocNetSubscription::NotifyGroup($arNotifyParams);
                                 }
                             }
                         } elseif (XDI_DEBUG) {
                             CXDImport::WriteToLog("RSS item is already in log. Scheme ID: " . $arScheme["ID"] . ", log ID: " . $arLogEvent["ID"], "RRSS");
                         }
                     }
                 } else {
                     CXDImport::WriteToLog("ERROR: Incorrect RSS response. Scheme ID: " . $arScheme["ID"] . ", server: " . $arScheme["HOST"] . ", port: " . $arScheme["PORT"] . ", page: " . $arScheme["PAGE"] . ", params: " . $arScheme["PARAMS"], "RRSS");
                 }
             }
             $strSql = "UPDATE b_xdi_lf_scheme SET LAST_EXECUTED=" . $DB->GetNowFunction() . " WHERE ID=" . intval($arScheme["ID"]);
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         $result = "CXDILFScheme::CheckRequest();";
     }
     return $result;
 }