X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FAnonymousFave%2FAnonymousFavePlugin.php;h=841b6524012de81d5e2c72717bcbd900d78e9dc0;hb=refs%2Fheads%2Fupstream-changes%2Fgoogle-analytics-removal;hp=be93c1704f6cb206f9c29d33bb35e687209a287b;hpb=7d0d89ddea7ae21f7c1526c170a20aa865d7c376;p=quix0rs-gnu-social.git diff --git a/plugins/AnonymousFave/AnonymousFavePlugin.php b/plugins/AnonymousFave/AnonymousFavePlugin.php index be93c1704f..841b652401 100644 --- a/plugins/AnonymousFave/AnonymousFavePlugin.php +++ b/plugins/AnonymousFave/AnonymousFavePlugin.php @@ -56,10 +56,8 @@ define('ANONYMOUS_FAVE_PLUGIN_VERSION', '0.1'); * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ - class AnonymousFavePlugin extends Plugin { - // Array of users who should not have anon faving. The default is // that anonymous faving is allowed for all users. public $restricted = array(); @@ -82,22 +80,7 @@ class AnonymousFavePlugin extends Plugin $schema = Schema::get(); // For storing total number of times a notice has been faved - - $schema->ensureTable('fave_tally', - array( - new ColumnDef('notice_id', 'integer', null, false, 'PRI'), - new ColumnDef('count', 'integer', null, false), - new ColumnDef( - 'modified', - 'timestamp', - null, - false, - null, - 'CURRENT_TIMESTAMP', - 'on update CURRENT_TIMESTAMP' - ) - ) - ); + $schema->ensureTable('fave_tally', Fave_tally::schemaDef()); return true; } @@ -117,31 +100,6 @@ class AnonymousFavePlugin extends Plugin $action->inlineScript('SN.U.NoticeFavor();'); } - function onAutoload($cls) - { - $dir = dirname(__FILE__); - - switch ($cls) { - case 'Fave_tally': - include_once $dir . '/' . $cls . '.php'; - return false; - case 'AnonFavorAction': - include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; - return false; - case 'AnonDisFavorAction': - include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; - return false; - case 'AnonFavorForm': - include_once $dir . '/anonfavorform.php'; - return false; - case 'AnonDisFavorForm': - include_once $dir . '/anondisfavorform.php'; - return false; - default: - return true; - } - } - function onStartInitializeRouter($m) { $m->connect('main/anonfavor', array('action' => 'AnonFavor')); @@ -166,8 +124,8 @@ class AnonymousFavePlugin extends Plugin if (!common_logged_in() && $this->hasAnonFaving($item)) { $profile = AnonymousFavePlugin::getAnonProfile(); - if (!empty($profile)) { - if ($profile->hasFave($item->notice)) { + if ($profile instanceof Profile) { + if (Fave::existsForProfile($item->notice, $profile)) { $disfavor = new AnonDisFavorForm($item->out, $item->notice); $disfavor->show(); } else { @@ -203,6 +161,7 @@ class AnonymousFavePlugin extends Plugin ) ); $out->elementStart('span', array('class' => 'fave-tally-title')); + // TRANS: Label for tally for number of times a notice was favored. $out->raw(sprintf(_m("Favored"))); $out->elementEnd('span'); $out->elementStart('span', array('class' => 'fave-tally')); @@ -228,14 +187,15 @@ class AnonymousFavePlugin extends Plugin list($proxy, $ip) = common_client_ip(); // IP + time + random number should help to avoid collisions - $baseNickname = $ip . '-' . time() . '-' . common_good_rand(5); + $baseNickname = $ip . '-' . time() . '-' . common_random_hexstr(5); $profile = new Profile(); $profile->nickname = $baseNickname; $id = $profile->insert(); if (!$id) { - throw new ServerException(_m("Couldn't create anonymous user session.")); + // TRANS: Server exception. + throw new ServerException(_m("Could not create anonymous user session.")); } // Stick the Profile ID into the nickname @@ -245,7 +205,8 @@ class AnonymousFavePlugin extends Plugin $result = $profile->update($orig); if (!$result) { - throw new ServerException(_m("Couldn't create anonymous user session.")); + // TRANS: Server exception. + throw new ServerException(_m("Could not create anonymous user session.")); } common_log( @@ -271,7 +232,7 @@ class AnonymousFavePlugin extends Plugin $parts = explode('-', $anon); $id = $parts[1]; // Do Profile lookup by ID instead of nickname for safety/performance - $profile = Profile::staticGet('id', $id); + $profile = Profile::getKV('id', $id); } else { $profile = AnonymousFavePlugin::createAnonProfile(); // Obfuscate so it's hard to figure out the Profile ID @@ -293,7 +254,7 @@ class AnonymousFavePlugin extends Plugin */ function hasAnonFaving($item) { - $profile = Profile::staticGet('id', $item->notice->profile_id); + $profile = Profile::getKV('id', $item->notice->profile_id); if (in_array($profile->nickname, $this->restricted)) { return false; } @@ -310,7 +271,7 @@ class AnonymousFavePlugin extends Plugin * * @return boolean hook value */ - function onPluginVersion(&$versions) + function onPluginVersion(array &$versions) { $url = 'http://status.net/wiki/Plugin:AnonymousFave'; @@ -319,9 +280,9 @@ class AnonymousFavePlugin extends Plugin 'author' => 'Zach Copley', 'homepage' => $url, 'rawdescription' => + // TRANS: Plugin description. _m('Allow anonymous users to favorite notices.')); return true; } - }