with
+ * a bunch of - 's, occasionally with
- 's.
+ * There are sometimes
's lost inside.
+ *
+ * @param array $data pair of user, text
+ *
+ * @return boolean success value
+ */
+
+ function handle($data)
+ {
+ list($user, $body) = $data;
+
+ $doc = $this->importHTML($body);
+
+ $dls = $doc->getElementsByTagName('dl');
+
+ if ($dls->length != 1) {
+ throw new ClientException(_("Bad import file."));
+ }
+
+ $dl = $dls->item(0);
+
+ $children = $dl->childNodes;
+
+ $dt = null;
+
+ for ($i = 0; $i < $children->length; $i++) {
+ try {
+ $child = $children->item($i);
+ if ($child->nodeType != XML_ELEMENT_NODE) {
+ continue;
+ }
+ switch (strtolower($child->tagName)) {
+ case 'dt':
+ if (!empty($dt)) {
+ // No DD provided
+ $this->importBookmark($user, $dt);
+ $dt = null;
+ }
+ $dt = $child;
+ break;
+ case 'dd':
+ $dd = $child;
+
+ $saved = $this->importBookmark($user, $dt, $dd);
+
+ $dt = null;
+ $dd = null;
+ case 'p':
+ common_log(LOG_INFO, 'Skipping the
in the
.');
+ break;
+ default:
+ common_log(LOG_WARNING,
+ "Unexpected element $child->tagName ".
+ " found in import.");
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ $dt = $dd = null;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Import a single bookmark
+ *
+ * Takes a - /
- pair. The
- has a single
+ * in it with some non-standard attributes.
+ *
+ * A
- sequence will appear as a
- with
+ * anothe
- as a child. We handle this case recursively.
+ *
+ * @param User $user User to import data as
+ * @param DOMElement $dt
- element
+ * @param DOMElement $dd
- element
+ *
+ * @return Notice imported notice
+ */
+
+ function importBookmark($user, $dt, $dd = null)
+ {
+ // We have to go squirrelling around in the child nodes
+ // on the off chance that we've received another
-
+ // as a child.
+
+ for ($i = 0; $i < $dt->childNodes->length; $i++) {
+ $child = $dt->childNodes->item($i);
+ if ($child->nodeType == XML_ELEMENT_NODE) {
+ if ($child->tagName == 'dt' && !is_null($dd)) {
+ $this->importBookmark($user, $dt);
+ $this->importBookmark($user, $child, $dd);
+ return;
+ }
+ }
+ }
+
+ $qm = QueueManager::get();
+
+ $qm->enqueue(array($user, $dt, $dd), 'dlcsbkmk');
+ }
+
+ /**
+ * Parse some HTML
+ *
+ * Hides the errors that the dom parser returns
+ *
+ * @param string $body Data to import
+ *
+ * @return DOMDocument parsed document
+ */
+
+ function importHTML($body)
+ {
+ // DOMDocument::loadHTML may throw warnings on unrecognized elements,
+ // and notices on unrecognized namespaces.
+ $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE));
+ $dom = new DOMDocument();
+ $ok = $dom->loadHTML($body);
+ error_reporting($old);
+
+ if ($ok) {
+ return $dom;
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/plugins/Bookmark/deliciousbookmarkimporter.php b/plugins/Bookmark/deliciousbookmarkimporter.php
new file mode 100644
index 0000000000..297ef81246
--- /dev/null
+++ b/plugins/Bookmark/deliciousbookmarkimporter.php
@@ -0,0 +1,109 @@
+.
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ // This check helps protect against security problems;
+ // your code file can't be executed directly from the web.
+ exit(1);
+}
+
+/**
+ * Importer class for Delicious bookmarks
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class DeliciousBookmarkImporter extends QueueHandler
+{
+ /**
+ * Return the transport for this queue handler
+ *
+ * @return string 'dlcsbkmk'
+ */
+
+ function transport()
+ {
+ return 'dlcsbkmk';
+ }
+
+ /**
+ * Handle the data
+ *
+ * @param array $data array of user, dt, dd
+ *
+ * @return boolean success value
+ */
+
+ function handle($data)
+ {
+ list($user, $dt, $dd) = $data;
+
+ $as = $dt->getElementsByTagName('a');
+
+ if ($as->length == 0) {
+ throw new ClientException(_("No tag in a
- ."));
+ }
+
+ $a = $as->item(0);
+
+ $private = $a->getAttribute('private');
+
+ if ($private != 0) {
+ throw new ClientException(_('Skipping private bookmark.'));
+ }
+
+ if (!empty($dd)) {
+ $description = $dd->nodeValue;
+ } else {
+ $description = null;
+ }
+
+ $title = $a->nodeValue;
+ $url = $a->getAttribute('href');
+ $tags = $a->getAttribute('tags');
+ $addDate = $a->getAttribute('add_date');
+ $created = common_sql_date(intval($addDate));
+
+ $saved = Bookmark::saveNew($user->getProfile(),
+ $title,
+ $url,
+ $tags,
+ $description,
+ array('created' => $created,
+ 'distribute' => false));
+
+ return true;
+ }
+}
diff --git a/plugins/Bookmark/importbookmarks.php b/plugins/Bookmark/importbookmarks.php
new file mode 100644
index 0000000000..5518b00e97
--- /dev/null
+++ b/plugins/Bookmark/importbookmarks.php
@@ -0,0 +1,96 @@
+.
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
+
+$shortoptions = 'i:n:f:';
+$longoptions = array('id=', 'nickname=', 'file=');
+
+$helptext = <<enqueue(array($user, $html), 'dlcsback');
+
+} catch (Exception $e) {
+ print $e->getMessage()."\n";
+ exit(1);
+}
diff --git a/plugins/Bookmark/importdelicious.php b/plugins/Bookmark/importdelicious.php
new file mode 100644
index 0000000000..f8529cc914
--- /dev/null
+++ b/plugins/Bookmark/importdelicious.php
@@ -0,0 +1,336 @@
+.
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ // This check helps protect against security problems;
+ // your code file can't be executed directly from the web.
+ exit(1);
+}
+
+/**
+ * UI for importing del.icio.us bookmark backups
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class ImportdeliciousAction extends Action
+{
+ protected $success = false;
+
+ /**
+ * Return the title of the page
+ *
+ * @return string page title
+ */
+
+ function title()
+ {
+ return _("Import del.icio.us bookmarks");
+ }
+
+ /**
+ * For initializing members of the class.
+ *
+ * @param array $argarray misc. arguments
+ *
+ * @return boolean true
+ */
+
+ function prepare($argarray)
+ {
+ parent::prepare($argarray);
+
+ $cur = common_current_user();
+
+ if (empty($cur)) {
+ throw new ClientException(_('Only logged-in users can '.
+ 'import del.icio.us backups.'),
+ 403);
+ }
+
+ if (!$cur->hasRight(BookmarkPlugin::IMPORTDELICIOUS)) {
+ throw new ClientException(_('You may not restore your account.'), 403);
+ }
+
+ return true;
+ }
+
+ /**
+ * Handler method
+ *
+ * @param array $argarray is ignored since it's now passed in in prepare()
+ *
+ * @return void
+ */
+
+ function handle($argarray=null)
+ {
+ parent::handle($argarray);
+
+ if ($this->isPost()) {
+ $this->importDelicious();
+ } else {
+ $this->showPage();
+ }
+ return;
+ }
+
+ /**
+ * Queue a file for importation
+ *
+ * Uses the DeliciousBackupImporter class; may take a long time!
+ *
+ * @return void
+ */
+
+ function importDelicious()
+ {
+ $this->checkSessionToken();
+
+ if (!isset($_FILES[ImportDeliciousForm::FILEINPUT]['error'])) {
+ throw new ClientException(_('No uploaded file.'));
+ }
+
+ switch ($_FILES[ImportDeliciousForm::FILEINPUT]['error']) {
+ case UPLOAD_ERR_OK: // success, jump out
+ break;
+ case UPLOAD_ERR_INI_SIZE:
+ // TRANS: Client exception thrown when an uploaded file is too large.
+ throw new ClientException(_('The uploaded file exceeds the ' .
+ 'upload_max_filesize directive in php.ini.'));
+ return;
+ case UPLOAD_ERR_FORM_SIZE:
+ throw new ClientException(
+ // TRANS: Client exception.
+ _('The uploaded file exceeds the MAX_FILE_SIZE directive' .
+ ' that was specified in the HTML form.'));
+ return;
+ case UPLOAD_ERR_PARTIAL:
+ @unlink($_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']);
+ // TRANS: Client exception.
+ throw new ClientException(_('The uploaded file was only' .
+ ' partially uploaded.'));
+ return;
+ case UPLOAD_ERR_NO_FILE:
+ // No file; probably just a non-AJAX submission.
+ throw new ClientException(_('No uploaded file.'));
+ return;
+ case UPLOAD_ERR_NO_TMP_DIR:
+ // TRANS: Client exception thrown when a temporary folder is not present
+ throw new ClientException(_('Missing a temporary folder.'));
+ return;
+ case UPLOAD_ERR_CANT_WRITE:
+ // TRANS: Client exception thrown when writing to disk is not possible
+ throw new ClientException(_('Failed to write file to disk.'));
+ return;
+ case UPLOAD_ERR_EXTENSION:
+ // TRANS: Client exception thrown when a file upload has been stopped
+ throw new ClientException(_('File upload stopped by extension.'));
+ return;
+ default:
+ common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " .
+ $_FILES[ImportDeliciousForm::FILEINPUT]['error']);
+ // TRANS: Client exception thrown when a file upload operation has failed
+ throw new ClientException(_('System error uploading file.'));
+ return;
+ }
+
+ $filename = $_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name'];
+
+ try {
+ if (!file_exists($filename)) {
+ throw new ServerException("No such file '$filename'.");
+ }
+
+ if (!is_file($filename)) {
+ throw new ServerException("Not a regular file: '$filename'.");
+ }
+
+ if (!is_readable($filename)) {
+ throw new ServerException("File '$filename' not readable.");
+ }
+
+ common_debug(sprintf(_("Getting backup from file '%s'."), $filename));
+
+ $html = file_get_contents($filename);
+
+ // Enqueue for processing.
+
+ $qm = QueueManager::get();
+ $qm->enqueue(array(common_current_user(), $html), 'dlcsback');
+
+ $this->success = true;
+
+ $this->showPage();
+
+ } catch (Exception $e) {
+ // Delete the file and re-throw
+ @unlink($_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']);
+ throw $e;
+ }
+ }
+
+ /**
+ * Show the content of the page
+ *
+ * @return void
+ */
+
+ function showContent()
+ {
+ if ($this->success) {
+ $this->element('p', null,
+ _('Feed will be restored. '.
+ 'Please wait a few minutes for results.'));
+ } else {
+ $form = new ImportDeliciousForm($this);
+ $form->show();
+ }
+ }
+
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return !$this->isPost();
+ }
+}
+
+/**
+ * A form for backing up the account.
+ *
+ * @category Account
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class ImportDeliciousForm extends Form
+{
+ const FILEINPUT = 'deliciousbackupfile';
+
+ /**
+ * Constructor
+ *
+ * Set the encoding type, since this is a file upload.
+ *
+ * @param HTMLOutputter $out output channel
+ *
+ * @return ImportDeliciousForm this
+ */
+
+ function __construct($out=null)
+ {
+ parent::__construct($out);
+ $this->enctype = 'multipart/form-data';
+ }
+
+ /**
+ * Class of the form.
+ *
+ * @return string the form's class
+ */
+
+ function formClass()
+ {
+ return 'form_import_delicious';
+ }
+
+ /**
+ * URL the form posts to
+ *
+ * @return string the form's action URL
+ */
+
+ function action()
+ {
+ return common_local_url('importdelicious');
+ }
+
+ /**
+ * Output form data
+ *
+ * Really, just instructions for doing a backup.
+ *
+ * @return void
+ */
+
+ function formData()
+ {
+ $this->out->elementStart('p', 'instructions');
+
+ $this->out->raw(_('You can upload a backed-up '.
+ 'delicious.com bookmarks file.'));
+
+ $this->out->elementEnd('p');
+
+ $this->out->elementStart('ul', 'form_data');
+
+ $this->out->elementStart('li', array ('id' => 'settings_attach'));
+ $this->out->element('input', array('name' => self::FILEINPUT,
+ 'type' => 'file',
+ 'id' => self::FILEINPUT));
+ $this->out->elementEnd('li');
+
+ $this->out->elementEnd('ul');
+ }
+
+ /**
+ * Buttons for the form
+ *
+ * In this case, a single submit button
+ *
+ * @return void
+ */
+
+ function formActions()
+ {
+ $this->out->submit('submit',
+ _m('BUTTON', 'Upload'),
+ 'submit',
+ null,
+ _('Upload the file'));
+ }
+}
diff --git a/plugins/Bookmark/newbookmark.php b/plugins/Bookmark/newbookmark.php
new file mode 100644
index 0000000000..a0cf3fffb2
--- /dev/null
+++ b/plugins/Bookmark/newbookmark.php
@@ -0,0 +1,196 @@
+.
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+if (!defined('STATUSNET')) {
+ // This check helps protect against security problems;
+ // your code file can't be executed directly from the web.
+ exit(1);
+}
+
+/**
+ * Add a new bookmark
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class NewbookmarkAction extends Action
+{
+ protected $user = null;
+ protected $error = null;
+ protected $complete = null;
+ protected $title = null;
+ protected $url = null;
+ protected $tags = null;
+ protected $description = null;
+
+ /**
+ * Returns the title of the action
+ *
+ * @return string Action title
+ */
+
+ function title()
+ {
+ return _('New bookmark');
+ }
+
+ /**
+ * For initializing members of the class.
+ *
+ * @param array $argarray misc. arguments
+ *
+ * @return boolean true
+ */
+
+ function prepare($argarray)
+ {
+ parent::prepare($argarray);
+
+ $this->user = common_current_user();
+
+ if (empty($this->user)) {
+ throw new ClientException(_("Must be logged in to post a bookmark."),
+ 403);
+ }
+
+ if ($this->isPost()) {
+ $this->checkSessionToken();
+ }
+
+ $this->title = $this->trimmed('title');
+ $this->url = $this->trimmed('url');
+ $this->tags = $this->trimmed('tags');
+ $this->description = $this->trimmed('description');
+
+ return true;
+ }
+
+ /**
+ * Handler method
+ *
+ * @param array $argarray is ignored since it's now passed in in prepare()
+ *
+ * @return void
+ */
+
+ function handle($argarray=null)
+ {
+ parent::handle($argarray);
+
+ if ($this->isPost()) {
+ $this->newBookmark();
+ } else {
+ $this->showPage();
+ }
+
+ return;
+ }
+
+ /**
+ * Add a new bookmark
+ *
+ * @return void
+ */
+
+ function newBookmark()
+ {
+ try {
+ if (empty($this->title)) {
+ throw new ClientException(_('Bookmark must have a title.'));
+ }
+
+ if (empty($this->url)) {
+ throw new ClientException(_('Bookmark must have an URL.'));
+ }
+
+
+ $saved = Bookmark::saveNew($this->user->getProfile(),
+ $this->title,
+ $this->url,
+ $this->tags,
+ $this->description);
+
+ } catch (ClientException $ce) {
+ $this->error = $ce->getMessage();
+ $this->showPage();
+ return;
+ }
+
+ common_redirect($saved->bestUrl(), 303);
+ }
+
+ /**
+ * Show the bookmark form
+ *
+ * @return void
+ */
+
+ function showContent()
+ {
+ if (!empty($this->error)) {
+ $this->element('p', 'error', $this->error);
+ }
+
+ $form = new BookmarkForm($this,
+ $this->title,
+ $this->url,
+ $this->tags,
+ $this->description);
+
+ $form->show();
+
+ return;
+ }
+
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
+ $_SERVER['REQUEST_METHOD'] == 'HEAD') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
\ No newline at end of file
diff --git a/plugins/Bookmark/noticebyurl.php b/plugins/Bookmark/noticebyurl.php
new file mode 100644
index 0000000000..226c7a32bf
--- /dev/null
+++ b/plugins/Bookmark/noticebyurl.php
@@ -0,0 +1,177 @@
+.
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ // This check helps protect against security problems;
+ // your code file can't be executed directly from the web.
+ exit(1);
+}
+
+/**
+ * List notices that contain/link to/use a given URL
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class NoticebyurlAction extends Action
+{
+ protected $url = null;
+ protected $file = null;
+ protected $notices = null;
+ protected $page = null;
+
+ /**
+ * For initializing members of the class.
+ *
+ * @param array $argarray misc. arguments
+ *
+ * @return boolean true
+ */
+
+ function prepare($argarray)
+ {
+ parent::prepare($argarray);
+
+ $this->file = File::staticGet('id', $this->trimmed('id'));
+
+ if (empty($this->file)) {
+ throw new ClientException(_('Unknown URL'));
+ }
+
+ $pageArg = $this->trimmed('page');
+
+ $this->page = (empty($pageArg)) ? 1 : intval($pageArg);
+
+ $this->notices = $this->file->stream(($this->page - 1) * NOTICES_PER_PAGE,
+ NOTICES_PER_PAGE + 1);
+
+ return true;
+ }
+
+ /**
+ * Title of the page
+ *
+ * @return string page title
+ */
+
+ function title()
+ {
+ if ($this->page == 1) {
+ return sprintf(_("Notices linking to %s"), $this->file->url);
+ } else {
+ return sprintf(_("Notices linking to %s, page %d"),
+ $this->file->url,
+ $this->page);
+ }
+ }
+
+ /**
+ * Handler method
+ *
+ * @param array $argarray is ignored since it's now passed in in prepare()
+ *
+ * @return void
+ */
+
+ function handle($argarray=null)
+ {
+ $this->showPage();
+ }
+
+ /**
+ * Show main page content.
+ *
+ * Shows a list of the notices that link to the given URL
+ *
+ * @return void
+ */
+
+ function showContent()
+ {
+ $nl = new NoticeList($this->notices, $this);
+
+ $nl->show();
+
+ $cnt = $nl->show();
+
+ $this->pagination($this->page > 1,
+ $cnt > NOTICES_PER_PAGE,
+ $this->page,
+ 'noticebyurl',
+ array('id' => $this->file->id));
+ }
+
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
+ /**
+ * Return last modified, if applicable.
+ *
+ * MAY override
+ *
+ * @return string last modified http header
+ */
+ function lastModified()
+ {
+ // For comparison with If-Last-Modified
+ // If not applicable, return null
+ return null;
+ }
+
+ /**
+ * Return etag, if applicable.
+ *
+ * MAY override
+ *
+ * @return string etag http header
+ */
+
+ function etag()
+ {
+ return null;
+ }
+}
diff --git a/plugins/Bookmark/showbookmark.php b/plugins/Bookmark/showbookmark.php
new file mode 100644
index 0000000000..e9e656f84c
--- /dev/null
+++ b/plugins/Bookmark/showbookmark.php
@@ -0,0 +1,145 @@
+.
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ // This check helps protect against security problems;
+ // your code file can't be executed directly from the web.
+ exit(1);
+}
+
+/**
+ * Show a single bookmark, with associated information
+ *
+ * @category Bookmark
+ * @package StatusNet
+ * @author Evan Prodromou
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class ShowbookmarkAction extends ShownoticeAction
+{
+ protected $bookmark = null;
+
+ /**
+ * For initializing members of the class.
+ *
+ * @param array $argarray misc. arguments
+ *
+ * @return boolean true
+ */
+
+ function prepare($argarray)
+ {
+ OwnerDesignAction::prepare($argarray);
+
+ $this->user = User::staticGet('id', $this->trimmed('user'));
+
+ if (empty($this->user)) {
+ throw new ClientException(_('No such user.'), 404);
+ }
+
+ $this->profile = $this->user->getProfile();
+
+ if (empty($this->profile)) {
+ throw new ServerException(_('User without a profile.'));
+ }
+
+ $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
+
+ sscanf($this->trimmed('crc32'), '%08x', $crc32);
+
+ if (empty($crc32)) {
+ throw new ClientException(_('No such URL.'), 404);
+ }
+
+ $dt = new DateTime($this->trimmed('created'),
+ new DateTimeZone('UTC'));
+
+ if (empty($dt)) {
+ throw new ClientException(_('No such create date.'), 404);
+ }
+
+ $bookmarks = Bookmark::getByCRC32($this->profile,
+ $crc32);
+
+ foreach ($bookmarks as $bookmark) {
+ $bdt = new DateTime($bookmark->created, new DateTimeZone('UTC'));
+ if ($bdt->format('U') == $dt->format('U')) {
+ $this->bookmark = $bookmark;
+ break;
+ }
+ }
+
+ if (empty($this->bookmark)) {
+ throw new ClientException(_('No such bookmark.'), 404);
+ }
+
+ $this->notice = Notice::staticGet('uri', $this->bookmark->uri);
+
+ if (empty($this->notice)) {
+ // Did we used to have it, and it got deleted?
+ throw new ClientException(_('No such bookmark.'), 404);
+ }
+
+ return true;
+ }
+
+ /**
+ * Title of the page
+ *
+ * Used by Action class for layout.
+ *
+ * @return string page tile
+ */
+
+ function title()
+ {
+ return sprintf(_('%s\'s bookmark for "%s"'),
+ $this->user->nickname,
+ $this->bookmark->title);
+ }
+
+ /**
+ * Overload page title display to show bookmark link
+ *
+ * @return void
+ */
+
+ function showPageTitle()
+ {
+ $this->elementStart('h1');
+ $this->element('a',
+ array('href' => $this->bookmark->url),
+ $this->bookmark->title);
+ $this->elementEnd('h1');
+ }
+}
diff --git a/plugins/OStatus/actions/groupsalmon.php b/plugins/OStatus/actions/groupsalmon.php
index 3a3d63fe20..024f0cc217 100644
--- a/plugins/OStatus/actions/groupsalmon.php
+++ b/plugins/OStatus/actions/groupsalmon.php
@@ -47,6 +47,9 @@ class GroupsalmonAction extends SalmonAction
$this->clientError(_m('No such group.'));
}
+
+ $this->target = $this->group;
+
$oprofile = Ostatus_profile::staticGet('group_id', $id);
if ($oprofile) {
// TRANS: Client error.
diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php
index e78c653300..5355aeba03 100644
--- a/plugins/OStatus/actions/usersalmon.php
+++ b/plugins/OStatus/actions/usersalmon.php
@@ -43,6 +43,8 @@ class UsersalmonAction extends SalmonAction
$this->clientError(_m('No such user.'));
}
+ $this->target = $this->user;
+
return true;
}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 77cf57a670..9c0f014fc6 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -457,7 +457,8 @@ class Ostatus_profile extends Memcached_DataObject
{
$activity = new Activity($entry, $feed);
- if (Event::handle('StartHandleFeedEntry', array($activity))) {
+ if (Event::handle('StartHandleFeedEntryWithProfile', array($activity, $this)) &&
+ Event::handle('StartHandleFeedEntry', array($activity))) {
// @todo process all activity objects
switch ($activity->objects[0]->type) {
@@ -479,6 +480,7 @@ class Ostatus_profile extends Memcached_DataObject
}
Event::handle('EndHandleFeedEntry', array($activity));
+ Event::handle('EndHandleFeedEntryWithProfile', array($activity, $this));
}
}
@@ -491,36 +493,10 @@ class Ostatus_profile extends Memcached_DataObject
*/
public function processPost($activity, $method)
{
- if ($this->isGroup()) {
- // A group feed will contain posts from multiple authors.
- // @fixme validate these profiles in some way!
- $oprofile = self::ensureActorProfile($activity);
- if ($oprofile->isGroup()) {
- // Groups can't post notices in StatusNet.
- common_log(LOG_WARNING, "OStatus: skipping post with group listed as author: $oprofile->uri in feed from $this->uri");
- return false;
- }
- } else {
- $actor = $activity->actor;
+ $oprofile = $this->checkAuthorship($activity);
- if (empty($actor)) {
- // OK here! assume the default
- } else if ($actor->id == $this->uri || $actor->link == $this->uri) {
- $this->updateFromActivityObject($actor);
- } else if ($actor->id) {
- // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner.
- // This isn't what we expect from mainline OStatus person feeds!
- // Group feeds go down another path, with different validation...
- // Most likely this is a plain ol' blog feed of some kind which
- // doesn't match our expectations. We'll take the entry, but ignore
- // the info.
- common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
- } else {
- // Plain without ActivityStreams actor info.
- // We'll just ignore this info for now and save the update under the feed's identity.
- }
-
- $oprofile = $this;
+ if (empty($oprofile)) {
+ return false;
}
// It's not always an ActivityObject::NOTE, but... let's just say it is.
@@ -1810,6 +1786,45 @@ class Ostatus_profile extends Memcached_DataObject
}
return $oprofile;
}
+
+ function checkAuthorship($activity)
+ {
+ if ($this->isGroup()) {
+ // A group feed will contain posts from multiple authors.
+ // @fixme validate these profiles in some way!
+ $oprofile = self::ensureActorProfile($activity);
+ if ($oprofile->isGroup()) {
+ // Groups can't post notices in StatusNet.
+ common_log(LOG_WARNING,
+ "OStatus: skipping post with group listed as author: ".
+ "$oprofile->uri in feed from $this->uri");
+ return false;
+ }
+ } else {
+ $actor = $activity->actor;
+
+ if (empty($actor)) {
+ // OK here! assume the default
+ } else if ($actor->id == $this->uri || $actor->link == $this->uri) {
+ $this->updateFromActivityObject($actor);
+ } else if ($actor->id) {
+ // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner.
+ // This isn't what we expect from mainline OStatus person feeds!
+ // Group feeds go down another path, with different validation...
+ // Most likely this is a plain ol' blog feed of some kind which
+ // doesn't match our expectations. We'll take the entry, but ignore
+ // the info.
+ common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
+ } else {
+ // Plain without ActivityStreams actor info.
+ // We'll just ignore this info for now and save the update under the feed's identity.
+ }
+
+ $oprofile = $this;
+ }
+
+ return $oprofile;
+ }
}
/**
diff --git a/plugins/OStatus/lib/salmonaction.php b/plugins/OStatus/lib/salmonaction.php
index 41bdb48928..8bfd7c8261 100644
--- a/plugins/OStatus/lib/salmonaction.php
+++ b/plugins/OStatus/lib/salmonaction.php
@@ -30,6 +30,7 @@ class SalmonAction extends Action
{
var $xml = null;
var $activity = null;
+ var $target = null;
function prepare($args)
{
@@ -82,7 +83,8 @@ class SalmonAction extends Action
StatusNet::setApi(true); // Send smaller error pages
common_log(LOG_DEBUG, "Got a " . $this->activity->verb);
- if (Event::handle('StartHandleSalmon', array($this->activity))) {
+ if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) &&
+ Event::handle('StartHandleSalmon', array($this->activity))) {
switch ($this->activity->verb)
{
case ActivityVerb::POST:
@@ -118,6 +120,7 @@ class SalmonAction extends Action
throw new ClientException(_m("Unrecognized activity type."));
}
Event::handle('EndHandleSalmon', array($this->activity));
+ Event::handle('EndHandleSalmonTarget', array($this->activity, $this->target));
}
}