]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/TwitterBridgePlugin.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / TwitterBridge / TwitterBridgePlugin.php
index bad6a3941b8b46e784a5a54ee4765fed3b8244b5..097d4486f91c4d9d214ce2ef6118860237fa8221 100644 (file)
@@ -45,17 +45,14 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
  * @link     http://status.net/
  * @link     http://twitter.com/
  */
-
 class TwitterBridgePlugin extends Plugin
 {
-
     const VERSION = STATUSNET_VERSION;
     public $adminImportControl = false; // Should the 'import' checkbox be exposed in the admin panel?
 
     /**
      * Initializer for the plugin.
      */
-
     function initialize()
     {
         // Allow the key and secret to be passed in
@@ -86,7 +83,6 @@ class TwitterBridgePlugin extends Plugin
      *
      * @return boolean result
      */
-
     static function hasKeys()
     {
         $ckey    = common_config('twitter', 'consumer_key');
@@ -113,7 +109,6 @@ class TwitterBridgePlugin extends Plugin
      *
      * @return boolean hook return
      */
-
     function onRouterInitialized($m)
     {
         $m->connect('admin/twitter', array('action' => 'twitteradminpanel'));
@@ -208,6 +203,7 @@ class TwitterBridgePlugin extends Plugin
             include_once $dir . '/' . strtolower($cls) . '.php';
             return false;
         case 'Notice_to_status':
+        case 'Twitter_synch_status':
             include_once $dir . '/' . $cls . '.php';
             return false;
         default:
@@ -309,7 +305,6 @@ class TwitterBridgePlugin extends Plugin
      *
      * @return boolean hook value
      */
-
     function onPluginVersion(&$versions)
     {
         $versions[] = array(
@@ -318,8 +313,8 @@ class TwitterBridgePlugin extends Plugin
             'author' => 'Zach Copley, Julien C',
             'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge',
             'rawdescription' => _m(
-                'The Twitter "bridge" plugin allows you to integrate ' .
-                'your StatusNet instance with ' .
+                'The Twitter "bridge" plugin allows integration ' .
+                'of a StatusNet instance with ' .
                 '<a href="http://twitter.com/">Twitter</a>.'
             )
         );
@@ -373,11 +368,25 @@ class TwitterBridgePlugin extends Plugin
      *
      * @return boolean hook value; true means continue processing, false means stop.
      */
-
     function onCheckSchema()
     {
         $schema = Schema::get();
 
+        // For saving the last-synched status of various timelines
+        // home_timeline, messages (in), messages (out), ...
+
+        $schema->ensureTable('twitter_synch_status',
+                             array(new ColumnDef('foreign_id', 'bigint', null,
+                                                 false, 'PRI'),
+                                   new ColumnDef('timeline', 'varchar', 255,
+                                                 false, 'PRI'),
+                                   new ColumnDef('last_id', 'bigint', null, // XXX: check for PostgreSQL
+                                                 false),
+                                   new ColumnDef('created', 'datetime', null,
+                                                 false),
+                                   new ColumnDef('modified', 'datetime', null,
+                                                 false)));
+
         // For storing user-submitted flags on profiles
 
         $schema->ensureTable('notice_to_status',
@@ -388,51 +397,24 @@ class TwitterBridgePlugin extends Plugin
                                    new ColumnDef('created', 'datetime', null,
                                                  false)));
 
-        // We update any notices that may have come in from
-        // Twitter that we don't have a status_id for. Note that
-        // this won't catch notices that originated at this StatusNet site.
-
-        $n = new Notice();
-
-        $n->query('SELECT notice.id, notice.uri ' .
-                  'FROM notice LEFT JOIN notice_to_status ' .
-                  'ON notice.id = notice_to_status.notice_id ' .
-                  'WHERE notice.source = "twitter"' .
-                  'AND notice_to_status.status_id IS NULL');
-
-        while ($n->fetch()) {
-            if (preg_match('#^http://twitter.com/[\w_.]+/status/(\d+)$#', $n->uri, $match)) {
-
-                $status_id = $match[1];
-
-                Notice_to_status::saveNew($n->id, $status_id);
-            }
-        }
-
         return true;
     }
 
     /**
-     * If a notice gets deleted, remove the Notice_to_status mapping
+     * If a notice gets deleted, remove the Notice_to_status mapping and
+     * delete the status on Twitter.
      *
+     * @param User   $user   The user doing the deleting
      * @param Notice $notice The notice getting deleted
      *
      * @return boolean hook value
      */
-
-    function onNoticeDeleteRelated($notice)
+    function onStartDeleteOwnNotice(User $user, Notice $notice)
     {
         $n2s = Notice_to_status::staticGet('notice_id', $notice->id);
 
         if (!empty($n2s)) {
 
-            $user = common_current_user();
-
-            if (empty($user) || $user->id != $notice->profile_id) {
-                $this->log(LOG_INFO, "Skipping deleting notice for {$notice->id} since it doesn't seem to be by the author.");
-                return true;
-            }
-
             $flink = Foreign_link::getByUserID($notice->profile_id,
                                                TWITTER_SERVICE); // twitter service
 
@@ -462,7 +444,6 @@ class TwitterBridgePlugin extends Plugin
      * @param Notice $notice being favored
      * @return hook return value
      */
-
     function onEndFavorNotice(Profile $profile, Notice $notice)
     {
         $flink = Foreign_link::getByUserID($profile->id,
@@ -499,7 +480,6 @@ class TwitterBridgePlugin extends Plugin
      *
      * @return hook return value
      */
-
     function onEndDisfavorNotice(Profile $profile, Notice $notice)
     {
         $flink = Foreign_link::getByUserID($profile->id,