]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/AnonymousFave/AnonymousFavePlugin.php
Merge remote-tracking branch 'upstream/master'
[quix0rs-gnu-social.git] / plugins / AnonymousFave / AnonymousFavePlugin.php
index 96edf82e12d26b2d786ad1679c48a3e3be06a017..c00e0ecb509b17aa3bc5ff239f1b2fb7dd719eb4 100644 (file)
@@ -56,15 +56,13 @@ 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();
 
-    function onArgsInitialize() {
+    function onArgsInitialize(array &$args) {
         // We always want a session because we're tracking anon users
         common_ensure_session();
     }
@@ -82,27 +80,12 @@ 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;
     }
 
-    function onEndShowHTML($action)
+    function onEndShowHTML(Action $action)
     {
         if (!common_logged_in()) {
             // Set a place to return to when submitting forms
@@ -110,38 +93,13 @@ class AnonymousFavePlugin extends Plugin
         }
     }
 
-    function onEndShowScripts($action)
+    function onEndShowScripts(Action $action)
     {
         // Setup ajax calls for favoriting. Usually this is only done when
         // a user is logged in.
         $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 {
@@ -229,7 +187,7 @@ 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;
@@ -237,7 +195,7 @@ class AnonymousFavePlugin extends Plugin
 
         if (!$id) {
             // TRANS: Server exception.
-            throw new ServerException(_m("Couldn't create anonymous user session."));
+            throw new ServerException(_m("Could not create anonymous user session."));
         }
 
         // Stick the Profile ID into the nickname
@@ -248,7 +206,7 @@ class AnonymousFavePlugin extends Plugin
 
         if (!$result) {
             // TRANS: Server exception.
-            throw new ServerException(_m("Couldn't create anonymous user session."));
+            throw new ServerException(_m("Could not create anonymous user session."));
         }
 
         common_log(
@@ -274,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
@@ -296,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;
         }
@@ -313,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';
 
@@ -327,5 +285,4 @@ class AnonymousFavePlugin extends Plugin
 
         return true;
     }
-
 }