return $notice;
}
+ public static function getById($id)
+ {
+ $notice = new Notice();
+ $notice->id = $id;
+ if (!$notice->find(true)) {
+ throw new NoResultException($notice);
+ }
+ return $notice;
+ }
+
/**
* Extract #hashtags from this notice's content and save them to the database.
*/
* Record the given set of hash tags in the db for this notice.
* Given tag strings will be normalized and checked for dupes.
*/
- function saveKnownTags($hashtags)
+ function saveKnownTags(array $hashtags)
{
//turn each into their canonical tag
//this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
* @return Notice
* @throws ClientException
*/
- static function saveNew($profile_id, $content, $source, array $options=null) {
+ static function saveNew($profile_id, $content, $source, array $options=array()) {
$defaults = array('uri' => null,
'url' => null,
'conversation' => null, // URI of conversation
'object_type' => null,
'verb' => null);
- if (!empty($options) && is_array($options)) {
+ /*
+ * Above type-hint is already array, so simply count it, this saves
+ * "some" CPU cycles.
+ */
+ if (count($options) > 0) {
$options = array_merge($defaults, $options);
- extract($options);
- } else {
- extract($defaults);
}
+ extract($options);
+
if (!isset($is_local)) {
$is_local = Notice::LOCAL_PUBLIC;
}
'delete' => false,
'move' => true),
'image' =>
- array('jpegquality' => 85),
+ array('jpegquality' => 95),
'avatar' =>
array('server' => null,
'dir' => INSTALLDIR . '/avatar/',
array('server' => null,
'dir' => INSTALLDIR . '/file/',
'path' => $_path . '/file/',
+ 'chmod' => 0644, // Access rights (chmod) for any attachments
'sslserver' => null,
'sslpath' => null,
'ssl' => null,
array('disabled' => true),
'plugins' =>
array('core' => array(
+ 'ActivityVerb' => array(),
'AuthCrypt' => array(),
'Cronish' => array(),
'Favorite' => array(),
}
// @fixme hardcoded list; should use Nickname::isValid()
// if/when it's safe to have loaded the infrastructure here
- $blacklist = array('main', 'panel', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook');
+ $blacklist = array('main', 'panel', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook', 'activity');
if (in_array($this->adminNick, $blacklist)) {
$this->updateStatus('The user nickname "' . htmlspecialchars($this->adminNick) .
'" is reserved.', true);
}
}
- if (!$conn instanceof DB_common) {
+ if (!is_object($conn)) {
+ // No object at all
+ throw new Exception('Fatal error: conn is no object.');
+ } elseif (!$conn instanceof DB_common) {
// Is not the right instance
throw new Exception('Cannot connect to database: ' . $conn->getMessage());
}
protected $id_prefix = null;
protected $options = true;
protected $maxchars = 0; // if <= 0 it means use full posts
+ protected $item_tag = 'li';
/**
* constructor
}
}
// string preferences
- foreach(array('id_prefix') as $key) {
+ foreach(array('id_prefix', 'item_tag') as $key) {
if (array_key_exists($key, $prefs)) {
$this->$key = $prefs[$key];
}
{
if (Event::handle('StartShowNoticeOptions', array($this))) {
$user = common_current_user();
- if ($user) {
+
+ if ($user instanceof User) {
$this->out->elementStart('div', 'notice-options');
if (Event::handle('StartShowNoticeOptionItems', array($this))) {
$this->showReplyLink();
}
$this->out->elementEnd('div');
}
+
Event::handle('EndShowNoticeOptions', array($this));
}
}
$class .= ' notice-source-'.$this->notice->source;
}
$id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
- $this->out->elementStart('li', array('class' => $class,
+ $this->out->elementStart($this->item_tag, array('class' => $class,
'id' => "${id_prefix}notice-${id}"));
Event::handle('EndOpenNoticeListItemElement', array($this));
}
*
* @return void
*/
- function handle($args)
+ function handle(array $args=array())
{
parent::handle($args);
$notice = Notice::getKV($id);
$token = $this->checkSessionToken();
- if (Fave::existsForProfile($notice, $profile)) {
- // TRANS: Client error.
- throw new AlreadyFulfilledException(_m('This notice is already a favorite!'));
- }
-
// Throws exception
$stored = Fave::addNew($profile, $notice);
protected $needPost = true;
+ /**
+ * Take arguments for running
+ *
+ * @return boolean success flag
+ */
protected function prepare(array $args=array())
{
parent::prepare($args);
$this->notice = Notice::getKV($this->arg('id'));
if (!empty($this->notice->repeat_of)) {
- common_log(LOG_DEBUG, 'Trying to Fave '.$this->notice->id.', repeat of '.$this->notice->repeat_of);
- common_log(LOG_DEBUG, 'Will Fave '.$this->notice->repeat_of.' instead');
+ common_debug('Trying to Fave '.$this->notice->id.', repeat of '.$this->notice->repeat_of);
+ common_debug('Will Fave '.$this->notice->repeat_of.' instead');
$real_notice_id = $this->notice->repeat_of;
$this->notice = Notice::getKV($real_notice_id);
}
return true;
}
+ /**
+ * Handle the request
+ *
+ * Check the format and show the user info
+ *
+ * @return void
+ */
protected function handle()
{
parent::handle();
);
}
- // Note: Twitter lets you fave things repeatedly via API.
-
- if (Fave::existsForProfile($this->notice, $this->scoped)) {
- $this->clientError(
- // TRANS: Client error displayed when trying to mark a notice favourite that already is a favourite.
- _('This status is already a favorite.'),
- 403,
- $this->format
- );
+ try {
+ $stored = Fave::addNew($this->scoped, $this->notice);
+ } catch (AlreadyFulfilledException $e) {
+ // Note: Twitter lets you fave things repeatedly via API.
+ $this->clientError($e->getMessage(), 403);
}
- // throws exception on failure
- $stored = Fave::addNew($this->scoped, $this->notice);
-
if ($this->format == 'xml') {
$this->showSingleXmlStatus($this->notice);
} elseif ($this->format == 'json') {