public static function notify($event, $type, $ids, $extraData) { if (!isset(Z_CONFIG::$SNS_TOPIC_STREAM_EVENTS)) { error_log('WARNING: Z_CONFIG::$SNS_TOPIC_STREAM_EVENTS not set ' . '-- skipping stream notifications'); return; } if ($type == "library") { switch ($event) { case "modify": $event = "topicUpdated"; break; case "delete": $event = "topicDeleted"; break; default: return; } $entries = []; foreach ($ids as $id) { $libraryID = $id; // For most libraries, get topic from URI if ($event != 'topicDeleted') { // Convert 'http://zotero.org/users/...' to '/users/...' $topic = str_replace(Zotero_URI::getBaseURI(), "/", Zotero_URI::getLibraryURI($libraryID)); } else { $topic = '/' . Zotero_Libraries::getType($libraryID) . "s/" . Zotero_Libraries::getLibraryTypeID($libraryID); } $message = ["event" => $event, "topic" => $topic]; if (!empty($extraData[$id])) { foreach ($extraData[$id] as $key => $val) { $message[$key] = $val; } } foreach (self::$messageReceivers as $receiver) { $receiver(Z_CONFIG::$SNS_TOPIC_STREAM_EVENTS, json_encode($message, JSON_UNESCAPED_SLASHES)); } } } else { if ($type == "apikey-library") { switch ($event) { case "add": $event = "topicAdded"; break; case "remove": $event = "topicRemoved"; break; default: return; } $entries = []; foreach ($ids as $id) { list($apiKey, $libraryID) = explode("-", $id); // Get topic from URI $topic = str_replace(Zotero_URI::getBaseURI(), "/", Zotero_URI::getLibraryURI($libraryID)); $message = ["event" => $event, "apiKey" => $apiKey, "topic" => $topic]; if (!empty($extraData[$id])) { foreach ($extraData[$id] as $key => $val) { $message[$key] = $val; } } self::send($message); } } } }