123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
- {
- public function tag()
- {
- return 'actmod';
- }
- public function types()
- {
- return array();
- }
- public function verbs()
- {
- return array(ActivityVerb::DELETE);
- }
- public function onBeforePluginCheckSchema()
- {
- Deleted_notice::beforeSchemaUpdate();
- return true;
- }
- public function onCheckSchema()
- {
- $schema = Schema::get();
- $schema->ensureTable('deleted_notice', Deleted_notice::schemaDef());
- return true;
- }
- public function onGetNoticeSqlTimestamp($id, &$timestamp)
- {
- try {
- $deleted = Deleted_notice::getByID($id);
- $timestamp = $deleted->act_created;
- } catch (NoResultException $e) {
- return true;
- }
-
- return false;
- }
- public function onIsNoticeDeleted($id, &$deleted)
- {
- try {
- $found = Deleted_notice::getByID($id);
- $deleted = ($found instanceof Deleted_notice);
- } catch (NoResultException $e) {
- $deleted = false;
- }
-
- return !$deleted;
- }
- protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
-
- return _m('TITLE', 'Notice moderation');
- }
- protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
-
- }
- protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
- switch (true) {
- case ActivityUtils::compareVerbs($verb, array(ActivityVerb::DELETE)):
-
- $target->deleteAs($scoped);
- break;
- default:
- throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.');
- }
- }
- public function deleteRelated(Notice $notice)
- {
-
- }
- public function onDeleteNoticeAsProfile(Notice $stored, Profile $actor, &$result) {
-
-
- if (false === Deleted_notice::addNew($stored, $actor)) {
-
-
- return true;
- }
-
-
-
- return false;
- }
-
- protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
- {
-
- return true;
- }
-
-
-
- public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
- {
- if (!$this->isMyNotice($stored)) {
- return true;
- }
- common_debug('Extending activity '.$stored->id.' with '.get_called_class());
- $this->extendActivity($stored, $act, $scoped);
- return false;
- }
-
-
- public function onStartNoticeSave(Notice $stored)
- {
-
-
-
- if (!ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::DELETE))) {
- return true;
- }
- try {
- $target = Notice::getByUri($stored->uri);
- } catch (NoResultException $e) {
- throw new AlreadyFulfilledException('Notice URI not found, so we have nothing to delete.');
- }
- $actor = $stored->getProfile();
- $owner = $target->getProfile();
- if ($owner->hasRole(Profile_role::DELETED)) {
-
-
-
-
-
- return true;
- }
-
-
- if (!$actor->sameAs($owner) && !$actor->hasRight(Right::DELETEOTHERSNOTICE)) {
- throw new AuthorizationException(_('You are not allowed to delete another user\'s notice.'));
- }
-
-
- $props = array('uri', 'profile_id', 'conversation', 'reply_to', 'created', 'repeat_of', 'object_type', 'is_local', 'scope');
- foreach($props as $prop) {
- $stored->$prop = $target->$prop;
- }
-
- try {
- $deleted = Deleted_notice::getByKeys( ['uri' => $stored->getUri()] );
- return $deleted;
- } catch (NoResultException $e) {
- $deleted = new Deleted_notice();
- $deleted->id = $target->getID();
- $deleted->profile_id = $actor->getID();
- $deleted->uri = $stored->getUri();
- $deleted->act_created = $stored->created;
- $deleted->created = common_sql_now();
-
- $result = $deleted->insert();
- }
-
- $target->delete();
- return true;
- }
- public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
- {
- Deleted_notice::extendActivity($stored, $act, $scoped);
- }
- public function activityObjectFromNotice(Notice $notice)
- {
- $object = Deleted_notice::fromStored($notice);
- return $object->asActivityObject();
- }
- protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
- if (!$scoped instanceof Profile || !($scoped->sameAs($target->getProfile()) || $scoped->hasRight(Right::DELETEOTHERSNOTICE))) {
- throw new AuthorizationException(_('You are not allowed to delete other user\'s notices'));
- }
- return DeletenoticeForm($action, array('notice'=>$target));
- }
- }
|