[Bookmark] Fix undefined variable "rendered" in Activity options

This commit is contained in:
Alexei Sorokin 2020-08-12 13:12:36 +03:00
parent 60eed202dd
commit 629857d3ef

View File

@ -1,44 +1,40 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social 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.
//
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Data class to mark notices as bookmarks * Data class to mark notices as bookmarks
* *
* PHP version 5 * @category Data
* * @package GNUsocial
* @category Data * @author Evan Prodromou <evan@status.net>
* @package StatusNet * @copyright 2009 StatusNet, Inc.
* @author Evan Prodromou <evan@status.net> * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009, StatusNet, Inc.
*
* 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/>.
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* For storing the fact that a notice is a bookmark * For storing the fact that a notice is a bookmark
* *
* @category Bookmark * @category Bookmark
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
* *
* @see DB_DataObject * @see DB_DataObject
*/ */
class Bookmark extends Managed_DataObject class Bookmark extends Managed_DataObject
{ {
@ -92,7 +88,7 @@ class Bookmark extends Managed_DataObject
* @return Bookmark The found bookmark object. * @return Bookmark The found bookmark object.
* @throws NoResultException When you don't find it after all. * @throws NoResultException When you don't find it after all.
*/ */
static public function fromStored(Notice $stored) public static function fromStored(Notice $stored)
{ {
return self::getByPK(array('uri' => $stored->getUri())); return self::getByPK(array('uri' => $stored->getUri()));
} }
@ -133,7 +129,7 @@ class Bookmark extends Managed_DataObject
* *
* @return Bookmark bookmark found or null * @return Bookmark bookmark found or null
*/ */
static function getByURL(Profile $profile, $url) public static function getByURL(Profile $profile, $url)
{ {
$nb = new Bookmark(); $nb = new Bookmark();
@ -157,8 +153,10 @@ class Bookmark extends Managed_DataObject
* *
* @return Bookmark the Bookmark object * @return Bookmark the Bookmark object
*/ */
static function saveActivityObject(ActivityObject $actobj, Notice $stored) public static function saveActivityObject(
{ ActivityObject $actobj,
Notice $stored
): self {
$url = null; $url = null;
// each extra element is array('tagname', array('attr'=>'val', ...), 'content') // each extra element is array('tagname', array('attr'=>'val', ...), 'content')
foreach ($actobj->extra as $extra) { foreach ($actobj->extra as $extra) {
@ -277,8 +275,14 @@ class Bookmark extends Managed_DataObject
* *
* @return Notice saved notice * @return Notice saved notice
*/ */
static function addNew(Profile $actor, $title, $url, array $rawtags, $description, array $options=array()) public static function addNew(
{ Profile $actor,
$title,
$url,
array $rawtags,
$description,
array $options = []
) {
$act = new Activity(); $act = new Activity();
$act->verb = ActivityVerb::POST; $act->verb = ActivityVerb::POST;
$act->time = time(); $act->time = time();
@ -336,15 +340,17 @@ class Bookmark extends Managed_DataObject
// TRANS: Rendered bookmark content. // TRANS: Rendered bookmark content.
// TRANS: %1$s is a URL, %2$s the bookmark title, %3$s is the bookmark description, // TRANS: %1$s is a URL, %2$s the bookmark title, %3$s is the bookmark description,
// TRANS: %4$s is space separated list of hash tags. // TRANS: %4$s is space separated list of hash tags.
$actobj->content = sprintf(_m('<span class="xfolkentry">'. $actobj->content = sprintf(
'<a class="taggedlink" href="%1$s">%2$s</a> '. _m('<span class="xfolkentry">'
'<span class="description">%3$s</span> '. . '<a class="taggedlink" href="%1$s">%2$s</a> '
'<span class="meta">%4$s</span>'. . '<span class="description">%3$s</span> '
'</span>'), . '<span class="meta">%4$s</span>'
htmlspecialchars($url), . '</span>'),
htmlspecialchars($title), htmlspecialchars($url),
htmlspecialchars($description), htmlspecialchars($title),
implode(' ', $taglinks)); htmlspecialchars($description),
implode(' ', $taglinks)
);
foreach ($tags as $term) { foreach ($tags as $term) {
$catEl = new AtomCategory(); $catEl = new AtomCategory();
@ -352,12 +358,13 @@ class Bookmark extends Managed_DataObject
$activity->categories[] = $catEl; $activity->categories[] = $catEl;
} }
$options = array_merge(array('urls' => array($url), $options = array_merge([
'rendered' => $rendered, 'urls' => [$url],
'tags' => $tags, 'rendered' => $actobj->content,
'replies' => $replies, 'tags' => $tags,
'object_type' => ActivityObject::BOOKMARK), 'replies' => $replies,
$options); 'object_type' => ActivityObject::BOOKMARK,
], $options);
return Notice::saveActivity($act, $actor, $options); return Notice::saveActivity($act, $actor, $options);
} }