$collection) { if ($key < 1) { continue; } $siteId = Site::query()->where('domain', trim($collection[0]))->value('id'); if (!empty($siteId)) { $socialIds = []; $faceBookResult = strstr($collection[1], 'facebook'); if (!empty($faceBookResult)) { $result = $this->getSocialId($siteId, 'FACEBOOKPAGE'); if (!empty($result)) { $socialIds[] = $result; } } $linKeDinResult = strstr($collection[1], 'linkedin'); if (!empty($linKeDinResult)) { $result = $this->getSocialId($siteId, 'LINKEDINCOMPANY'); if (!empty($result)) { $socialIds[] = $result; } } $twitterResult = strstr($collection[1], 'twitter'); if (!empty($twitterResult)) { $result = $this->getSocialId($siteId, 'TWITTER'); if (!empty($result)) { $socialIds[] = $result; } } $pinResult = strstr($collection[1], 'pin') ?? 0; if (!empty($pinResult)) { $result = $this->getSocialId($siteId, 'PINTEREST'); if (!empty($result)) { $socialIds[] = $result; } } $t = $collection[3]; $n = intval(($t - 25569) * 3600 * 24); $date = gmdate('Y-m-d H:i:s', $n); $lens = mb_strlen($collection[2]); if ($lens > 1000) { $content = mb_substr($collection[2], 0, 997 - $lens) . '...'; } else { $content = $collection[2]; } $array = [ 'site_id' => $siteId, 'remote_content_id' => 0, 'content' => $content ?? $collection[2], 'url' => $collection[1], 'publish_at' => $date, 'social_ids' => \GuzzleHttp\json_encode($socialIds), 'type' => 1, 'created_at' => date('Y-m-d H:i:s'), ]; $updateList[] = $array; } } HootsuiteHistory::query()->insert($updateList); } public function getSocialId($siteId, $type) { $hootSuiteUser = HootsuiteUser::query()->where(['site_id' => $siteId])->first(); $socialProfiles = $hootSuiteUser->social_profiles ?? []; foreach ($socialProfiles as $kk => $vv) { if ($vv['type'] == $type) { return $vv['id']; } } return 0; } }