X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FTwitterBridge%2FTwitterBridgePlugin.php;h=d4bb74e93559ee8ecb80e1ad613677ea6c94a4bf;hb=3f28b17c86c4cd88d4f39629ea8a89ec3a820790;hp=29192cf53b05c8853ac87b8135153a5c5990e422;hpb=19b965d99188fde59cdd39b668df8951bc0f180c;p=quix0rs-gnu-social.git diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index 29192cf53b..d4bb74e935 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -30,13 +30,15 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; +require_once __DIR__ . '/twitter.php'; /** * Plugin for sending and importing Twitter statuses * * This class allows users to link their Twitter accounts * + * Depends on Favorite plugin. + * * @category Plugin * @package StatusNet * @author Zach Copley @@ -47,7 +49,7 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; */ class TwitterBridgePlugin extends Plugin { - const VERSION = STATUSNET_VERSION; + const VERSION = GNUSOCIAL_VERSION; public $adminImportControl = false; // Should the 'import' checkbox be exposed in the admin panel? /** @@ -105,11 +107,11 @@ class TwitterBridgePlugin extends Plugin * * Hook for RouterInitialized event. * - * @param Net_URL_Mapper $m path-to-action mapper + * @param URLMapper $m path-to-action mapper * * @return boolean hook return */ - function onRouterInitialized($m) + public function onRouterInitialized(URLMapper $m) { $m->connect('panel/twitter', array('action' => 'twitteradminpanel')); @@ -148,8 +150,10 @@ class TwitterBridgePlugin extends Plugin if (self::hasKeys() && common_config('twitter', 'signin')) { $action->menuItem( common_local_url('twitterlogin'), - _m('Twitter'), - _m('Login or register using Twitter'), + // TRANS: Menu item in login navigation. + _m('MENU','Twitter'), + // TRANS: Title for menu item in login navigation. + _m('Login or register using Twitter.'), 'twitterlogin' === $action_name ); } @@ -171,7 +175,9 @@ class TwitterBridgePlugin extends Plugin $action->menuItem( common_local_url('twittersettings'), - _m('Twitter'), + // TRANS: Menu item in connection settings navigation. + _m('MENU','Twitter'), + // TRANS: Title for menu item in connection settings navigation. _m('Twitter integration options'), $action_name === 'twittersettings' ); @@ -179,45 +185,6 @@ class TwitterBridgePlugin extends Plugin return true; } - /** - * Automatically load the actions and libraries used by the Twitter bridge - * - * @param Class $cls the class - * - * @return boolean hook return - * - */ - function onAutoload($cls) - { - $dir = dirname(__FILE__); - - switch ($cls) { - case 'TwittersettingsAction': - case 'TwitterauthorizationAction': - case 'TwitterloginAction': - case 'TwitteradminpanelAction': - include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; - return false; - case 'TwitterOAuthClient': - case 'TwitterQueueHandler': - case 'TwitterImport': - case 'JsonStreamReader': - case 'TwitterStreamReader': - include_once $dir . '/' . strtolower($cls) . '.php'; - return false; - case 'TwitterSiteStream': - case 'TwitterUserStream': - include_once $dir . '/twitterstreamreader.php'; - return false; - case 'Notice_to_status': - case 'Twitter_synch_status': - include_once $dir . '/' . $cls . '.php'; - return false; - default: - return true; - } - } - /** * Add a Twitter queue item for each notice * @@ -226,7 +193,7 @@ class TwitterBridgePlugin extends Plugin * * @return boolean hook return */ - function onStartEnqueueNotice($notice, &$transports) + function onStartEnqueueNotice(Notice $notice, array &$transports) { if (self::hasKeys() && $notice->isLocal() && $notice->inScope(null)) { // Avoid a possible loop @@ -244,7 +211,7 @@ class TwitterBridgePlugin extends Plugin * * @return boolean hook return */ - function onGetValidDaemons($daemons) + function onGetValidDaemons(array &$daemons) { if (self::hasKeys()) { array_push( @@ -283,6 +250,18 @@ class TwitterBridgePlugin extends Plugin return true; } + /** + * If the plugin's installed, this should be accessible to admins + */ + function onAdminPanelCheck($name, &$isOK) + { + if ($name == 'twitter') { + $isOK = true; + return false; + } + return true; + } + /** * Add a Twitter tab to the admin panel * @@ -291,7 +270,7 @@ class TwitterBridgePlugin extends Plugin * @return boolean hook value */ - function onEndAdminPanelNav($nav) + function onEndAdminPanelNav(Menu $nav) { if (AdminPanelAction::canAdmin('twitter')) { @@ -299,8 +278,10 @@ class TwitterBridgePlugin extends Plugin $nav->out->menuItem( common_local_url('twitteradminpanel'), + // TRANS: Menu item in administrative panel that leads to the Twitter bridge configuration. _m('Twitter'), - _m('Twitter bridge configuration'), + // TRANS: Menu item title in administrative panel that leads to the Twitter bridge configuration. + _m('Twitter bridge configuration page.'), $action_name == 'twitteradminpanel', 'nav_twitter_admin_panel' ); @@ -316,15 +297,15 @@ class TwitterBridgePlugin extends Plugin * * @return boolean hook value */ - function onPluginVersion(&$versions) + function onPluginVersion(array &$versions) { $versions[] = array( 'name' => 'TwitterBridge', 'version' => self::VERSION, - 'author' => 'Zach Copley, Julien C', + 'author' => 'Zach Copley, Julien C, Jean Baptiste Favre', 'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge', - 'rawdescription' => _m( - 'The Twitter "bridge" plugin allows integration ' . + // TRANS: Plugin description. + 'rawdescription' => _m('The Twitter "bridge" plugin allows integration ' . 'of a StatusNet instance with ' . 'Twitter.' ) @@ -385,28 +366,10 @@ class TwitterBridgePlugin extends Plugin // 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))); + $schema->ensureTable('twitter_synch_status', Twitter_synch_status::schemaDef()); // For storing user-submitted flags on profiles - - $schema->ensureTable('notice_to_status', - array(new ColumnDef('notice_id', 'integer', null, - false, 'PRI'), - new ColumnDef('status_id', 'bigint', null, // XXX: check for PostgreSQL - false, 'UNI'), - new ColumnDef('created', 'datetime', null, - false))); + $schema->ensureTable('notice_to_status', Notice_to_status::schemaDef()); return true; } @@ -422,7 +385,7 @@ class TwitterBridgePlugin extends Plugin */ function onStartDeleteOwnNotice(User $user, Notice $notice) { - $n2s = Notice_to_status::staticGet('notice_id', $notice->id); + $n2s = Notice_to_status::getKV('notice_id', $notice->id); if (!empty($n2s)) { @@ -539,4 +502,85 @@ class TwitterBridgePlugin extends Plugin } return true; } + + /** + * Add links in the user's profile block to their Twitter profile URL. + * + * @param Profile $profile The profile being shown + * @param Array &$links Writeable array of arrays (href, text, image). + * + * @return boolean hook value (true) + */ + + function onOtherAccountProfiles($profile, &$links) + { + $fuser = null; + + $flink = Foreign_link::getByUserID($profile->id, TWITTER_SERVICE); + + if (!empty($flink)) { + $fuser = $flink->getForeignUser(); + + if (!empty($fuser)) { + $links[] = array("href" => $fuser->uri, + "text" => sprintf(_("@%s on Twitter"), $fuser->nickname), + "image" => $this->path("icons/twitter-bird-white-on-blue.png")); + } + } + + return true; + } + + public function onEndShowHeadElements(Action $action) + { + if (!($action instanceof AttachmentAction)) { + return true; + } + + /* Twitter card support. See https://dev.twitter.com/docs/cards */ + /* @fixme: should we display twitter cards only for attachments posted + * by local users ? Seems mandatory to display twitter:creator + * + * Author: jbfavre + */ + switch ($action->attachment->mimetype) { + case 'image/pjpeg': + case 'image/jpeg': + case 'image/jpg': + case 'image/png': + case 'image/gif': + $action->element('meta', array('name' => 'twitter:card', + 'content' => 'photo'), + null); + $action->element('meta', array('name' => 'twitter:url', + 'content' => common_local_url('attachment', + array('attachment' => $action->attachment->id))), + null ); + $action->element('meta', array('name' => 'twitter:image', + 'content' => $action->attachment->url)); + $action->element('meta', array('name' => 'twitter:title', + 'content' => $action->attachment->title)); + + $ns = new AttachmentNoticeSection($action); + $notices = $ns->getNotices(); + $noticeArray = $notices->fetchAll(); + + // Should not have more than 1 notice for this attachment. + if( count($noticeArray) != 1 ) { break; } + $post = $noticeArray[0]; + + $flink = Foreign_link::getByUserID($post->profile_id, TWITTER_SERVICE); + if( $flink ) { // Our local user has registered Twitter Gateway + $fuser = Foreign_user::getForeignUser($flink->foreign_id, TWITTER_SERVICE); + if( $fuser ) { // Got nickname for local user's Twitter account + $action->element('meta', array('name' => 'twitter:creator', + 'content' => '@'.$fuser->nickname)); + } + } + break; + default: break; + } + + return true; + } }