public function removeAttachment() { if (empty($_GET['actionId'])) { throw new Redirect404Exception(); } $actionId = (int) $_GET['actionId']; $dto = $this->service->findActionById($actionId); $data = json_decode($dto->data, true); if ($data['attachment']['oembed']['type'] == 'photo') { OW::getEventManager()->call('base.attachment_delete_image', array('url' => $data['attachment']['oembed']['url'])); } unset($data['attachment']); $dto->data = json_encode($data); $this->service->saveAction($dto); exit; }
public function removeAttachment() { if (empty($_GET['actionId'])) { throw new Redirect404Exception(); } $actionId = (int) $_GET['actionId']; $dto = $this->service->findActionById($actionId); $data = json_decode($dto->data, true); if (!empty($data['attachmentId'])) { BOL_AttachmentService::getInstance()->deleteAttachmentByBundle("newsfeed", $data['attachmentId']); } unset($data['attachment']); $dto->data = json_encode($data); $this->service->saveAction($dto); exit; }
public function action(OW_Event $originalEvent) { $params = $this->extractEventParams($originalEvent); $this->validateParams($params, array('entityType', 'entityId')); $data = $originalEvent->getData(); $actionDto = null; $mergeTo = null; if (is_array($params['merge'])) { $actionDto = $data['actionDto'] = $this->service->findAction($params['merge']['entityType'], $params['merge']['entityId']); $mergeTo = $params['merge']; } else { $actionDto = $data['actionDto'] = $this->service->findAction($params['entityType'], $params['entityId']); } $event = new OW_Event('feed.on_entity_action', $params, $data); OW::getEventManager()->trigger($event); $params = $this->extractEventParams($event); $data = $this->extractEventData($event); if ($mergeTo !== null && ($mergeTo["entityType"] != $params['merge']["entityType"] || $mergeTo["entityId"] != $params['merge']["entityId"])) { $actionDto = $data['actionDto'] = $this->service->findAction($params['merge']['entityType'], $params['merge']['entityId']); $mergeTo = $params['merge']; } $actionDto = $data['actionDto'] = empty($data['actionDto']) ? $actionDto : $data['actionDto']; if ($actionDto !== null) { $action = $actionDto; $action->entityType = $params['entityType']; $action->entityId = $params['entityId']; $params['pluginKey'] = empty($params['pluginKey']) ? $action->pluginKey : $params['pluginKey']; $actionData = json_decode($action->data, true); $data = array_merge($actionData, $data); $event = new OW_Event('feed.on_entity_update', $params, $data); OW::getEventManager()->trigger($event); unset($data['actionDto']); $params = $this->extractEventParams($event); $data = $this->extractEventData($event); if ($params['replace']) { $this->service->removeAction($action->entityType, $action->entityId); $action->id = null; } $action->data = json_encode($data); if (empty($data["content"])) { $action->format = NEWSFEED_CLASS_FormatManager::FORMAT_EMPTY; } else { if (!empty($data["content"]["format"])) { $action->format = trim($data["content"]["format"]); } } $this->service->saveAction($action); $activityParams = array('pluginKey' => $params['pluginKey'], 'entityType' => $params['entityType'], 'entityId' => $params['entityId'], 'activityType' => NEWSFEED_BOL_Service::SYSTEM_ACTIVITY_CREATE, 'actionId' => $action->id); if (isset($params['visibility'])) { $activityParams['visibility'] = $params['visibility']; } if (isset($params['time'])) { $activityParams['time'] = $params['time']; } if (isset($params['postOnUserFeed'])) { $activityParams['postOnUserFeed'] = $params['postOnUserFeed']; } if (!empty($params['privacy'])) { $activityParams['privacy'] = $params['privacy']; } if (!empty($params['feedType']) && !empty($params['feedId'])) { $activityParams['feedType'] = $params['feedType']; $activityParams['feedId'] = $params['feedId']; } $temp = empty($data['ownerId']) ? $params['userId'] : $data['ownerId']; $userIds = !is_array($temp) ? array($temp) : $temp; foreach ($userIds as $userId) { $activityParams['userId'] = (int) $userId; $activityParams['activityId'] = (int) $userId; $activityEvent = new OW_Event('feed.activity', $activityParams); $this->activity($activityEvent); } } else { $_authorIdList = is_array($params['userId']) ? $params['userId'] : array($params['userId']); $authorIdList = array(); foreach ($_authorIdList as $uid) { $activityKey = "create.{$params['entityId']}:{$params['entityType']}.{$params['entityId']}:{$uid}"; if ($this->testActivity($activityKey)) { $authorIdList[] = $uid; } } if (empty($authorIdList)) { return; } $params["userId"] = count($authorIdList) == 1 ? $authorIdList[0] : $authorIdList; $event = new OW_Event('feed.on_entity_add', $params, $data); OW::getEventManager()->trigger($event); $params = $this->extractEventParams($event); $data = $this->extractEventData($event); if (empty($data['content']) && empty($data['string']) && empty($data['line'])) { return; } if (is_array($params['replace'])) { $this->service->removeAction($params['replace']['entityType'], $params['replace']['entityId']); } $action = new NEWSFEED_BOL_Action(); $action->entityType = $params['entityType']; $action->entityId = $params['entityId']; $action->pluginKey = $params['pluginKey']; if (empty($data["content"])) { $action->format = NEWSFEED_CLASS_FormatManager::FORMAT_EMPTY; } else { if (!empty($data["content"]["format"])) { $action->format = trim($data["content"]["format"]); } } $action->data = json_encode($data); $this->service->saveAction($action); $activityParams = array('pluginKey' => $params['pluginKey'], 'entityType' => $params['entityType'], 'entityId' => $params['entityId'], 'activityType' => NEWSFEED_BOL_Service::SYSTEM_ACTIVITY_CREATE, 'visibility' => (int) $params['visibility'], 'actionId' => $action->id, 'postOnUserFeed' => $params['postOnUserFeed'], 'subscribe' => isset($params['subscribe']) ? (bool) $params['subscribe'] : true, 'time' => empty($params['time']) ? time() : $params['time']); if (!empty($params['privacy'])) { $activityParams['privacy'] = $params['privacy']; } if (!empty($params['feedType']) && !empty($params['feedId'])) { $activityParams['feedType'] = $params['feedType']; $activityParams['feedId'] = $params['feedId']; } $temp = empty($data['ownerId']) ? $params['userId'] : $data['ownerId']; $userIds = !is_array($temp) ? array($temp) : $temp; foreach ($userIds as $userId) { $activityParams['userId'] = (int) $userId; $activityParams['activityId'] = (int) $userId; $activityEvent = new OW_Event('feed.activity', $activityParams); $this->activity($activityEvent); } } }