summaryrefslogtreecommitdiff
path: root/plugins/SocialObject/NewSocialObjectAction.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SocialObject/NewSocialObjectAction.php')
-rw-r--r--plugins/SocialObject/NewSocialObjectAction.php210
1 files changed, 210 insertions, 0 deletions
diff --git a/plugins/SocialObject/NewSocialObjectAction.php b/plugins/SocialObject/NewSocialObjectAction.php
new file mode 100644
index 000000000..ad4e093d2
--- /dev/null
+++ b/plugins/SocialObject/NewSocialObjectAction.php
@@ -0,0 +1,210 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009, StatusNet, Inc.
+ *
+ * Base class for handling new social-objects
+ *
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category GNUSocial
+ * @package StatusNet
+ * @author Shashi Gowda <connect2shashi@gmail.com>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://daisycha.in
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+class NewSocialObjectAction extends NewnoticeAction
+{
+ private $slug=null;
+ private $dbclass=null;
+
+ function saveNewNotice($metadata=array())
+ {
+ $this->validate();
+
+ # summarize social-object data to be put in as notice content
+ # should be usable in xmpp, email etc.
+ $content = $this->getSummary();
+ $replyto = $this->getReplyTo();
+
+ $metadata['replies'] = $this->getMentions();
+ $metadata['urls'] = $this->getUrls();
+ $metadata['groups'] = $this->getGroups();
+ $metadata['tags'] = $this->getTags();
+
+ # this is largely copied from parent::saveNewNotice
+
+ $user = common_current_user();
+ assert($user); // XXX: maybe an error instead...
+
+ #If an ID of 0 is wrongly passed here, it will cause a database error,
+ #so override it...
+ if ($replyto == 0) {
+ $replyto = 'false';
+ }
+
+ $upload = null;
+ $upload = MediaFile::fromUpload('attach');
+
+ if (isset($upload)) {
+
+ $content_shortened .= ' ' . $upload->shortUrl();
+
+ if (Notice::contentTooLong($content_shortened)) {
+ $upload->delete();
+ $this->clientError(
+ sprintf(
+ _('Max notice size is %d chars, including attachment URL.'),
+ Notice::maxContent()
+ )
+ );
+ }
+ }
+
+ $options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
+
+ if ($user->shareLocation()) {
+ // use browser data if checked; otherwise profile data
+ if ($this->arg('notice_data-geo')) {
+ $locOptions = Notice::locationOptions($this->trimmed('lat'),
+ $this->trimmed('lon'),
+ $this->trimmed('location_id'),
+ $this->trimmed('location_ns'),
+ $user->getProfile());
+ } else {
+ $locOptions = Notice::locationOptions(null,
+ null,
+ null,
+ null,
+ $user->getProfile());
+ }
+
+ $options = array_merge($options, $locOptions, $metadata); ### $metadata too.
+ }
+
+ $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
+ $this->saveNew($notice); ### <-- save me.
+
+ if (isset($upload)) {
+ $upload->attachToNotice($notice);
+ }
+
+ if ($this->boolean('ajax')) {
+ header('Content-Type: text/xml;charset=utf-8');
+ $this->xw->startDocument('1.0', 'UTF-8');
+ $this->elementStart('html');
+ $this->elementStart('head');
+ $this->element('title', null, _('Notice posted'));
+ $this->elementEnd('head');
+ $this->elementStart('body');
+ $this->showNotice($notice);
+ $this->elementEnd('body');
+ $this->elementEnd('html');
+ } else {
+ $returnto = $this->trimmed('returnto');
+
+ if ($returnto) {
+ $url = common_local_url($returnto,
+ array('nickname' => $user->nickname));
+ } else {
+ $url = common_local_url('shownotice',
+ array('notice' => $notice->id));
+ }
+ common_redirect($url, 303);
+ }
+ }
+
+ function validate()
+ {
+ return true;
+ }
+
+ function getSummary()
+ {
+ # have this function in the DB class,
+ # respect Notice::MaxContent()
+ }
+
+ function getReplyTo()
+ {
+ return $this->trimmed('inreplyto');
+ }
+
+ function getMentions()
+ {
+ }
+
+ function getUrls()
+ {
+ }
+
+ function getTags()
+ {
+ }
+
+ function getGroups()
+ {
+ }
+
+ function save()
+ {
+ # save your custom data, video, event or whatever.
+ }
+
+ function saveNew()
+ {
+ # save new social-object to its table.
+ }
+
+ function showPage()
+ {
+ if ($this->boolean('ajax')) {
+ header('Content-Type: text/xml;charset=utf-8');
+ $this->xw->startDocument('1.0', 'UTF-8');
+ $this->elementStart('html');
+ $this->elementStart('head');
+ $this->elementEnd('head');
+ $this->elementStart('body');
+ $this->showSocialObjectForm();
+ $this->elementEnd('body');
+ $this->elementEnd('html');
+ return false;
+ }
+ else {
+ parent::showPage();
+ }
+ }
+
+ function showNoticeForm()
+ {
+ $this->showSocialObjectForm();
+ }
+
+ # when user choses to post a social object,
+ # the existing notice box will be replaced
+ # with this.
+ # abstracted out in SocialLayout plugin
+ # has autocomplete for replies and groupnames
+ function showSocialObjectForm()
+ {
+ # show some awesome variation of SocialObjectForm
+ }
+}