Skip to content

Instantly share code, notes, and snippets.

@apfelbox
Last active December 14, 2015 06:09
Show Gist options
  • Save apfelbox/5040125 to your computer and use it in GitHub Desktop.
Save apfelbox/5040125 to your computer and use it in GitHub Desktop.
Simple plugin for usage in Status.Net, so that the notices keep line breaks.
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009,2011 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/>.
*/
/**
* @package LineBreakerPlugin
* @maintainer Jannik Zschiesche <hello@apfelbox.net>
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
class LineBreakPlugin extends Plugin
{
/**
* Registers the event handlers
*/
public function __construct ()
{
Event::addHandler("StartNoticeSave", array($this, "onStartNoticeSave"));
}
/**
* Handles the start notice save event
*
* @param Notice $notice
* @return bool
*/
public function onStartNoticeSave (Notice $notice)
{
$notice->rendered = !empty($notice->rendered)
? nl2br($notice->rendered)
: nl2br($notice->content);
return true;
}
/**
* Adds the version to the version list
*
* @param array $versions
*
* @return bool
*/
public function onPluginVersion(&$versions)
{
$versions[] = array(
'name' => 'LineBreak',
'version' => STATUSNET_VERSION,
'author' => 'Jannik Zschiesche',
'homepage' => 'http://apfelbox.net',
'rawdescription' => 'Renders line breaks in the notice content.'
);
return true;
}
}
@apfelbox
Copy link
Author

Installation

Just copy the file to /local/ and add the following line to your config.php:

addPlugin("LineBreak", array());

Current limitations

Since the used event is only triggered for saving (there is no event for rendering), this will only work for new notices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment