diff options
Diffstat (limited to 'plugins/FollowEveryone')
7 files changed, 500 insertions, 0 deletions
diff --git a/plugins/FollowEveryone/FollowEveryonePlugin.php b/plugins/FollowEveryone/FollowEveryonePlugin.php new file mode 100644 index 000000000..228efc935 --- /dev/null +++ b/plugins/FollowEveryone/FollowEveryonePlugin.php @@ -0,0 +1,206 @@ +<?php +/** + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2010, StatusNet, Inc. + * + * When a new user registers, all existing users follow them automatically. + * + * 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 Community + * @package StatusNet + * @author Evan Prodromou <evan@status.net> + * @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); +} + +/** + * Plugin to make all users follow each other at registration + * + * Users can unfollow afterwards if they want. + * + * @category Sample + * @package StatusNet + * @author Evan Prodromou <evan@status.net> + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ +class FollowEveryonePlugin extends Plugin +{ + /** + * Called when a new user is registered. + * + * We find all users, and try to subscribe them to the new user, and + * the new user to them. Exceptions (like silenced users or whatever) + * are caught, logged, and ignored. + * + * @param Profile &$newProfile The new user's profile + * @param User &$newUser The new user + * + * @return boolean hook value + * + */ + function onEndUserRegister(&$newProfile, &$newUser) + { + $otherUser = new User(); + $otherUser->whereAdd('id != ' . $newUser->id); + + if ($otherUser->find()) { + while ($otherUser->fetch()) { + $otherProfile = $otherUser->getProfile(); + try { + if (User_followeveryone_prefs::followEveryone($otherUser->id)) { + Subscription::start($otherProfile, $newProfile); + } + Subscription::start($newProfile, $otherProfile); + } catch (Exception $e) { + common_log(LOG_WARNING, $e->getMessage()); + continue; + } + } + } + + $ufep = new User_followeveryone_prefs(); + + $ufep->user_id = $newUser->id; + $ufep->followeveryone = true; + + $ufep->insert(); + + return true; + } + + /** + * Database schema setup + * + * Plugins can add their own tables to the StatusNet database. Plugins + * should use StatusNet's schema interface to add or delete tables. The + * ensureTable() method provides an easy way to ensure a table's structure + * and availability. + * + * By default, the schema is checked every time StatusNet is run (say, when + * a Web page is hit). Admins can configure their systems to only check the + * schema when the checkschema.php script is run, greatly improving performance. + * However, they need to remember to run that script after installing or + * upgrading a plugin! + * + * @see Schema + * @see ColumnDef + * + * @return boolean hook value; true means continue processing, false means stop. + */ + function onCheckSchema() + { + $schema = Schema::get(); + + // For storing user-submitted flags on profiles + + $schema->ensureTable('user_followeveryone_prefs', + array(new ColumnDef('user_id', 'integer', null, + true, 'PRI'), + new ColumnDef('followeveryone', 'tinyint', null, + false, null, 1))); + + return true; + } + + /** + * Load related modules when needed + * + * @param string $cls Name of the class to be loaded + * + * @return boolean hook value; true means continue processing, false means stop. + */ + function onAutoload($cls) + { + $dir = dirname(__FILE__); + + switch ($cls) + { + case 'User_followeveryone_prefs': + include_once $dir . '/'.$cls.'.php'; + return false; + default: + return true; + } + } + + /** + * Show a checkbox on the profile form to ask whether to follow everyone + * + * @param Action $action The action being executed + * + * @return boolean hook value + */ + function onEndProfileFormData($action) + { + $user = common_current_user(); + + $action->elementStart('li'); + // TRANS: Checkbox label in form for profile settings. + $action->checkbox('followeveryone', _('Follow everyone'), + ($action->arg('followeveryone')) ? + $action->arg('followeveryone') : + User_followeveryone_prefs::followEveryone($user->id)); + $action->elementEnd('li'); + + return true; + } + + /** + * Save checkbox value for following everyone + * + * @param Action $action The action being executed + * + * @return boolean hook value + */ + function onEndProfileSaveForm($action) + { + $user = common_current_user(); + + User_followeveryone_prefs::savePref($user->id, + $action->boolean('followeveryone')); + + return true; + } + + /** + * Provide version information about this plugin. + * + * @param Array &$versions Array of version data + * + * @return boolean hook value + * + */ + function onPluginVersion(&$versions) + { + $versions[] = array('name' => 'FollowEveryone', + 'version' => STATUSNET_VERSION, + 'author' => 'Evan Prodromou', + 'homepage' => 'http://status.net/wiki/Plugin:FollowEveryone', + 'rawdescription' => + _m('New users follow everyone at registration and are followed in return.')); + return true; + } +} diff --git a/plugins/FollowEveryone/User_followeveryone_prefs.php b/plugins/FollowEveryone/User_followeveryone_prefs.php new file mode 100644 index 000000000..7690fd220 --- /dev/null +++ b/plugins/FollowEveryone/User_followeveryone_prefs.php @@ -0,0 +1,164 @@ +<?php +/** + * Data class for counting greetings + * + * PHP version 5 + * + * @category Data + * @package StatusNet + * @author Evan Prodromou <evan@status.net> + * @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('STATUSNET')) { + exit(1); +} + +require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; + +/** + * Data class for counting greetings + * + * We use the DB_DataObject framework for data classes in StatusNet. Each + * table maps to a particular data class, making it easier to manipulate + * data. + * + * Data classes should extend Memcached_DataObject, the (slightly misnamed) + * extension of DB_DataObject that provides caching, internationalization, + * and other bits of good functionality to StatusNet-specific data classes. + * + * @category Action + * @package StatusNet + * @author Evan Prodromou <evan@status.net> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * @see DB_DataObject + */ +class User_followeveryone_prefs extends Memcached_DataObject +{ + public $__table = 'user_followeveryone_prefs'; // table name + public $user_id; // int(4) primary_key not_null + public $followeveryone; // tinyint(1) + + /** + * Get an instance by key + * + * This is a utility method to get a single instance with a given key value. + * + * @param string $k Key to use to lookup (usually 'user_id' for this class) + * @param mixed $v Value to lookup + * + * @return User_followeveryone_prefs object found, or null for no hits + */ + function staticGet($k, $v=null) + { + return Memcached_DataObject::staticGet('User_followeveryone_prefs', $k, $v); + } + + /** + * return table definition for DB_DataObject + * + * DB_DataObject needs to know something about the table to manipulate + * instances. This method provides all the DB_DataObject needs to know. + * + * @return array array of column definitions + */ + function table() + { + return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, + 'followeveryone' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL); + } + + /** + * return key definitions for DB_DataObject + * + * DB_DataObject needs to know about keys that the table has, since it + * won't appear in StatusNet's own keys list. In most cases, this will + * simply reference your keyTypes() function. + * + * @return array list of key field names + */ + function keys() + { + return array_keys($this->keyTypes()); + } + + /** + * return key definitions for Memcached_DataObject + * + * Our caching system uses the same key definitions, but uses a different + * method to get them. This key information is used to store and clear + * cached data, so be sure to list any key that will be used for static + * lookups. + * + * @return array associative array of key definitions, field name to type: + * 'K' for primary key: for compound keys, add an entry for each component; + * 'U' for unique keys: compound keys are not well supported here. + */ + function keyTypes() + { + return array('user_id' => 'K'); + } + + /** + * Magic formula for non-autoincrementing integer primary keys + * + * If a table has a single integer column as its primary key, DB_DataObject + * assumes that the column is auto-incrementing and makes a sequence table + * to do this incrementation. Since we don't need this for our class, we + * overload this method and return the magic formula that DB_DataObject needs. + * + * @return array magic three-false array that stops auto-incrementing. + */ + function sequenceKey() + { + return array(false, false, false); + } + + static function followEveryone($user_id) + { + $ufep = self::staticGet('user_id', $user_id); + + if (empty($ufep)) { + return true; + } else { + return (bool)$ufep->followeveryone; + } + } + + static function savePref($user_id, $followEveryone) + { + $ufep = self::staticGet('user_id', $user_id); + + if (empty($ufep)) { + $ufep = new User_followeveryone_prefs(); + $ufep->user_id = $user_id; + $ufep->followeveryone = $followEveryone; + $ufep->insert(); + } else { + $orig = clone($ufep); + $ufep->followeveryone = $followEveryone; + $ufep->update(); + } + + return true; + } +} diff --git a/plugins/FollowEveryone/locale/FollowEveryone.pot b/plugins/FollowEveryone/locale/FollowEveryone.pot new file mode 100644 index 000000000..7531677df --- /dev/null +++ b/plugins/FollowEveryone/locale/FollowEveryone.pot @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-10-27 23:43+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: FollowEveryonePlugin.php:203 +msgid "New users follow everyone at registration and are followed in return." +msgstr "" diff --git a/plugins/FollowEveryone/locale/ia/LC_MESSAGES/FollowEveryone.po b/plugins/FollowEveryone/locale/ia/LC_MESSAGES/FollowEveryone.po new file mode 100644 index 000000000..fdb2571c7 --- /dev/null +++ b/plugins/FollowEveryone/locale/ia/LC_MESSAGES/FollowEveryone.po @@ -0,0 +1,26 @@ +# Translation of StatusNet - FollowEveryone to Interlingua (Interlingua) +# Expored from translatewiki.net +# +# Author: McDutchie +# -- +# This file is distributed under the same license as the StatusNet package. +# +msgid "" +msgstr "" +"Project-Id-Version: StatusNet - FollowEveryone\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-10-27 23:43+0000\n" +"PO-Revision-Date: 2010-10-28 23:10:36+0000\n" +"Language-Team: Interlingua <http://translatewiki.net/wiki/Portal:ia>\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-POT-Import-Date: 2010-10-28 00:08:01+0000\n" +"X-Generator: MediaWiki 1.17alpha (r75629); Translate extension (2010-09-17)\n" +"X-Translation-Project: translatewiki.net at http://translatewiki.net\n" +"X-Language-Code: ia\n" +"X-Message-Group: #out-statusnet-plugin-followeveryone\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: FollowEveryonePlugin.php:203 +msgid "New users follow everyone at registration and are followed in return." +msgstr "Nove usatores seque omnes al inscription e es sequite per omnes." diff --git a/plugins/FollowEveryone/locale/mk/LC_MESSAGES/FollowEveryone.po b/plugins/FollowEveryone/locale/mk/LC_MESSAGES/FollowEveryone.po new file mode 100644 index 000000000..1930d6658 --- /dev/null +++ b/plugins/FollowEveryone/locale/mk/LC_MESSAGES/FollowEveryone.po @@ -0,0 +1,26 @@ +# Translation of StatusNet - FollowEveryone to Macedonian (Македонски) +# Expored from translatewiki.net +# +# Author: Bjankuloski06 +# -- +# This file is distributed under the same license as the StatusNet package. +# +msgid "" +msgstr "" +"Project-Id-Version: StatusNet - FollowEveryone\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-10-27 23:43+0000\n" +"PO-Revision-Date: 2010-10-28 23:10:36+0000\n" +"Language-Team: Macedonian <http://translatewiki.net/wiki/Portal:mk>\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-POT-Import-Date: 2010-10-28 00:08:01+0000\n" +"X-Generator: MediaWiki 1.17alpha (r75629); Translate extension (2010-09-17)\n" +"X-Translation-Project: translatewiki.net at http://translatewiki.net\n" +"X-Language-Code: mk\n" +"X-Message-Group: #out-statusnet-plugin-followeveryone\n" +"Plural-Forms: nplurals=2; plural=(n == 1 || n%10 == 1) ? 0 : 1;\n" + +#: FollowEveryonePlugin.php:203 +msgid "New users follow everyone at registration and are followed in return." +msgstr "Новите корисници следат секого при регистрација и сите ги следат нив." diff --git a/plugins/FollowEveryone/locale/nl/LC_MESSAGES/FollowEveryone.po b/plugins/FollowEveryone/locale/nl/LC_MESSAGES/FollowEveryone.po new file mode 100644 index 000000000..55dcb2325 --- /dev/null +++ b/plugins/FollowEveryone/locale/nl/LC_MESSAGES/FollowEveryone.po @@ -0,0 +1,28 @@ +# Translation of StatusNet - FollowEveryone to Dutch (Nederlands) +# Expored from translatewiki.net +# +# Author: Siebrand +# -- +# This file is distributed under the same license as the StatusNet package. +# +msgid "" +msgstr "" +"Project-Id-Version: StatusNet - FollowEveryone\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-10-27 23:43+0000\n" +"PO-Revision-Date: 2010-10-28 23:10:37+0000\n" +"Language-Team: Dutch <http://translatewiki.net/wiki/Portal:nl>\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-POT-Import-Date: 2010-10-28 00:08:01+0000\n" +"X-Generator: MediaWiki 1.17alpha (r75629); Translate extension (2010-09-17)\n" +"X-Translation-Project: translatewiki.net at http://translatewiki.net\n" +"X-Language-Code: nl\n" +"X-Message-Group: #out-statusnet-plugin-followeveryone\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: FollowEveryonePlugin.php:203 +msgid "New users follow everyone at registration and are followed in return." +msgstr "" +"Nieuwe gebruikers volgen iedereen bij inschrijving en worden door iedereen " +"gevolgd." diff --git a/plugins/FollowEveryone/locale/uk/LC_MESSAGES/FollowEveryone.po b/plugins/FollowEveryone/locale/uk/LC_MESSAGES/FollowEveryone.po new file mode 100644 index 000000000..0db1e6ca3 --- /dev/null +++ b/plugins/FollowEveryone/locale/uk/LC_MESSAGES/FollowEveryone.po @@ -0,0 +1,29 @@ +# Translation of StatusNet - FollowEveryone to Ukrainian (Українська) +# Expored from translatewiki.net +# +# Author: Boogie +# -- +# This file is distributed under the same license as the StatusNet package. +# +msgid "" +msgstr "" +"Project-Id-Version: StatusNet - FollowEveryone\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-10-27 23:43+0000\n" +"PO-Revision-Date: 2010-10-28 23:10:37+0000\n" +"Language-Team: Ukrainian <http://translatewiki.net/wiki/Portal:uk>\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-POT-Import-Date: 2010-10-28 00:08:01+0000\n" +"X-Generator: MediaWiki 1.17alpha (r75629); Translate extension (2010-09-17)\n" +"X-Translation-Project: translatewiki.net at http://translatewiki.net\n" +"X-Language-Code: uk\n" +"X-Message-Group: #out-statusnet-plugin-followeveryone\n" +"Plural-Forms: nplurals=3; plural=(n%10 == 1 && n%100 != 11) ? 0 : ( (n%10 >= " +"2 && n%10 <= 4 && (n%100 < 10 || n%100 >= 20)) ? 1 : 2 );\n" + +#: FollowEveryonePlugin.php:203 +msgid "New users follow everyone at registration and are followed in return." +msgstr "" +"Нові користувачі автоматично підписуються до всіх після реєстрації, а всі " +"решта автоматично підписуються навзаєм." |