X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FTwitterBridge%2FTwitterBridgePlugin.php;h=097d4486f91c4d9d214ce2ef6118860237fa8221;hb=04ca706601a2a3b556cc52fa21b61fcd842c4e87;hp=f7d3b6659a5c400780a326d613739b7cc1bc56ba;hpb=ba8a24073fc3d545fdc86b613d32b4bfc33743c3;p=quix0rs-gnu-social.git diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index f7d3b6659a..097d4486f9 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -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 ' . 'Twitter.' ) ); @@ -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,42 +397,41 @@ 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)) { + + $flink = Foreign_link::getByUserID($notice->profile_id, + TWITTER_SERVICE); // twitter service + + if (empty($flink)) { + return true; + } + + if (!TwitterOAuthClient::isPackedToken($flink->credentials)) { + $this->log(LOG_INFO, "Skipping deleting notice for {$notice->id} since link is not OAuth."); + return true; + } + + $token = TwitterOAuthClient::unpackToken($flink->credentials); + $client = new TwitterOAuthClient($token->key, $token->secret); + + $client->statusesDestroy($n2s->status_id); + $n2s->delete(); } return true; @@ -436,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, @@ -473,7 +480,6 @@ class TwitterBridgePlugin extends Plugin * * @return hook return value */ - function onEndDisfavorNotice(Profile $profile, Notice $notice) { $flink = Foreign_link::getByUserID($profile->id,