function pleio_api_get_activity($group_id = 0, $offset = 0) { $offset = intval($offset); $group_id = intval($group_id); $joins = array(); $wheres = array(); if ($group_id) { $joins[] = sprintf(" JOIN %sentities e ON e.guid = rv.object_guid ", get_config("dbprefix")); } if ($group_id) { $wheres[] = " (e.container_guid = {$group_id} OR e.guid = {$group_id}) "; } $total = elgg_get_river(array("count" => true, "joins" => $joins, "wheres" => $wheres)); $rivers = elgg_get_river(array("offset" => $offset, "joins" => $joins, "wheres" => $wheres)); $list = array(); foreach ($rivers as $item) { $river = pleio_api_format_activity($item); if ($river) { $list[] = $river; } } return array("total" => $total, "list" => $list, "offset" => $offset); }
function pleio_api_push_handle_river_id($river_id, $apnsMessages = array(), $gcmMessages = array()) { list($river) = elgg_get_river(array("id" => $river_id, 'site_guid' => ELGG_ENTITIES_ANY_VALUE)); if ($river) { $users = pleio_api_users_with_access_device_token($river); if (sizeof($users)) { $subject = $river->getSubjectEntity(); $object = $river->getObjectEntity(); $subject_link = $subject->name; $object_link = $object->title ? $object->title : $object->name; $action = $river->action_type; $type = $river->type; $subtype = $river->subtype ? $river->subtype : 'default'; $m = "river:{$action}:{$type}:{$subtype}"; $item = pleio_api_format_activity($river); if ($item["s"]["name"] != $item["s"]["name"]) { $txt = trim(sprintf("%s %s %s", $item["s"]["name"], $item["m"], $item["o"]["name"])); } else { $txt = trim(sprintf("%s %s ", $item["s"]["name"], $item["m"])); } //$txt = elgg_echo ( $m, array ( $subject_link, $object_link ), 'nl' ); if ($object && $object->container_guid == $subject->guid) { unset($object->container_guid); } $gcmMessage = pleio_api_create_gcm_message($txt, $river->type, $object); $gcmRegistrationIds = array(); $gcmUserGuids = array(); // store user_guid to unregister token if needed foreach ($users as $to_guid => $info) { if (strpos($info["device"], "Android") !== false) { $gcmRegistrationIds[] = $info["device_token"]; $gcmUserGuids[] = $to_guid; } else { $apnsMessages[$to_guid] = pleio_api_create_apns_message($txt, $info["device_token"], $river->type, $object); } } if (sizeof($gcmRegistrationIds)) { $gcmMessages[] = array('registration_ids' => $gcmRegistrationIds, 'data' => $gcmMessage, 'user_guids' => $gcmUserGuids); } } } return array($apnsMessages, $gcmMessages); }