123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
- class EditMirrorAction extends BaseMirrorAction
- {
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->profile = $this->validateProfile($this->trimmed('profile'));
- $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id,
- 'subscribed' => $this->profile->id));
- if (!$this->mirror instanceof SubMirror) {
-
- $this->clientError(_m('Requested invalid profile to edit.'));
- }
- $this->style = $this->validateStyle($this->trimmed('style'));
-
-
- $this->delete = (bool)$this->arg('delete');
- return true;
- }
- protected function validateStyle($style)
- {
- $allowed = array('repeat', 'copy');
- if (in_array($style, $allowed)) {
- return $style;
- } else {
-
- $this->clientError(_m('Bad form data.'));
- }
- }
- protected function saveMirror()
- {
- $mirror = SubMirror::getMirror($this->user, $this->profile);
- if (!$mirror) {
-
- $this->clientError(_m('The mirror request failed, because no result was retrieved.'));
- }
- if ($this->delete) {
- $mirror->delete();
- $oprofile = Ostatus_profile::getKV('profile_id', $this->profile->id);
- if ($oprofile) {
- $oprofile->garbageCollect();
- }
- } else if ($this->style != $mirror->style) {
- $orig = clone($mirror);
- $mirror->style = $this->style;
- $mirror->modified = common_sql_now();
- $mirror->update($orig);
- }
- }
- }
|