2014-05-14 16:46:07 +09:00
< ? php
2015-07-02 22:00:57 +09:00
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
2014-05-14 16:46:07 +09:00
· ·
· ·
· Q V I T T E R ·
· ·
2016-01-18 09:24:37 +09:00
· https :// git . gnu . io / h2p / Qvitter ·
2014-05-14 16:46:07 +09:00
· ·
· ·
· < o ) ·
· / _ //// ·
· ( ____ / ·
· ( o < ·
· o > \\\\_\ ·
· \\ ) \____ ) ·
· ·
2015-07-02 22:00:57 +09:00
· ·
2014-05-14 16:46:07 +09:00
· ·
· Qvitter is free software : you can redistribute it and / or modify it ·
· under the terms of the GNU Affero General Public License as published by ·
· the Free Software Foundation , either version three of the License or ( at ·
· your option ) any later version . ·
· ·
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
· WARRANTY ; without even the implied warranty of MERCHANTABILTY or FITNESS ·
· FOR A PARTICULAR PURPOSE . See the GNU Affero General Public License for ·
· more details . ·
· ·
· You should have received a copy of the GNU Affero General Public License ·
· along with Qvitter . If not , see < http :// www . gnu . org / licenses />. ·
· ·
· Contact h @ nnesmannerhe . im if you have any questions . ·
2015-07-02 22:00:57 +09:00
· ·
2014-05-14 16:46:07 +09:00
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
2014-11-28 21:49:00 +09:00
const QVITTERDIR = __DIR__ ;
2014-05-14 16:46:07 +09:00
class QvitterPlugin extends Plugin {
2015-07-11 04:51:20 +09:00
protected $hijack_ui = false ;
2015-07-07 07:52:26 +09:00
protected $qvitter_hide_replies = false ;
2015-06-07 03:37:40 +09:00
2015-06-07 17:04:53 +09:00
static function settings ( $setting )
2014-05-14 16:46:07 +09:00
{
2015-07-02 22:00:57 +09:00
2015-01-28 05:22:17 +09:00
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· ·
· S E T T I N G S ·
· ·
2015-07-02 22:00:57 +09:00
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
2014-05-14 16:46:07 +09:00
2014-11-28 05:04:41 +09:00
// THESE SETTINGS CAN BE OVERRIDDEN IN CONFIG.PHP
2015-07-11 06:40:40 +09:00
// e.g. $config['site']['qvitter']['enabledbydefault'] = false;
2014-11-28 05:04:41 +09:00
2014-05-14 16:46:07 +09:00
// ENABLED BY DEFAULT (true/false)
$settings [ 'enabledbydefault' ] = true ;
// DEFAULT BACKGROUND COLOR
$settings [ 'defaultbackgroundcolor' ] = '#f4f4f4' ;
2015-01-28 05:22:17 +09:00
// DEFAULT BACKGROUND IMAGE
$settings [ 'sitebackground' ] = 'img/vagnsmossen.jpg' ;
2015-01-22 05:03:38 +09:00
2016-02-16 21:37:29 +09:00
// FAVICON PATH (we've used realfavicongenerator.net to generate the icons)
$settings [ 'favicon_path' ] = Plugin :: staticPath ( 'Qvitter' , '' ) . 'img/gnusocial-favicons/' ;
2015-01-22 05:03:38 +09:00
2015-06-06 23:20:26 +09:00
// DEFAULT SPRITE
2015-09-18 08:42:52 +09:00
$settings [ 'sprite' ] = Plugin :: staticPath ( 'Qvitter' , '' ) . 'img/sprite.png?v=41' ;
2015-06-06 23:20:26 +09:00
2014-05-14 16:46:07 +09:00
// DEFAULT LINK COLOR
$settings [ 'defaultlinkcolor' ] = '#0084B4' ;
2015-05-30 00:30:03 +09:00
// ENABLE DEFAULT WELCOME TEXT
2015-07-02 22:00:57 +09:00
$settings [ 'enablewelcometext' ] = true ;
2015-05-30 00:30:03 +09:00
2015-05-30 00:40:45 +09:00
// CUSTOM WELCOME TEXT (overrides the previous setting)
2015-07-02 22:00:57 +09:00
$settings [ 'customwelcometext' ] = false ;
2015-05-30 00:30:03 +09:00
// Example:
2015-05-30 00:40:45 +09:00
// $settings['customwelcometext']['sv'] = '<h1>Välkommen till Quitter.se – en federerad<sup>1</sup> mikrobloggsallmänning!</h1><p>Etc etc...</p>';
// $settings['customwelcometext']['en'] = '<h1>Welcome to Quitter.se – a federated microblog common!</h1><p>Etc etc...</p>';
2015-02-05 05:40:56 +09:00
2014-05-14 16:46:07 +09:00
// TIME BETWEEN POLLING
$settings [ 'timebetweenpolling' ] = 5000 ; // ms
2015-01-28 05:22:17 +09:00
2014-09-20 09:53:10 +09:00
// URL SHORTENER
$settings [ 'urlshortenerapiurl' ] = 'http://qttr.at/yourls-api.php' ;
2014-11-28 05:04:41 +09:00
$settings [ 'urlshortenersignature' ] = 'b6afeec983' ;
2017-01-31 07:50:42 +09:00
$settings [ 'urlshortenerformat' ] = 'jsonp' ; // if you're using shortener.php you can set this to 'json', which enables you to use YOURLS versions below 1.5.1
2015-07-02 22:00:57 +09:00
2015-01-26 03:05:09 +09:00
// CUSTOM TERMS OF USE
$settings [ 'customtermsofuse' ] = false ;
2015-07-02 22:00:57 +09:00
2015-02-04 22:44:04 +09:00
// IP ADDRESSES BLOCKED FROM REGISTRATION
$settings [ 'blocked_ips' ] = array ();
2014-05-14 16:46:07 +09:00
2015-07-12 05:25:34 +09:00
// LINKIFY DOMAINS WITHOUT PROTOCOL AS DEFAULT
$settings [ 'linkify_bare_domains' ] = true ;
2014-05-14 16:46:07 +09:00
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
2015-07-02 22:00:57 +09:00
· ·
2014-05-14 16:46:07 +09:00
· ( o > > o ) ·
· \\\\_\ / _ //// .
2015-07-02 22:00:57 +09:00
· \____ ) ( ____ / ·
2014-05-14 16:46:07 +09:00
· ·
2015-07-02 22:00:57 +09:00
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
// config.php settings override the settings in this file
2014-11-28 07:39:25 +09:00
$configphpsettings = common_config ( 'site' , 'qvitter' ) ? : array ();
2014-11-28 05:04:41 +09:00
foreach ( $configphpsettings as $configphpsetting => $value ) {
$settings [ $configphpsetting ] = $value ;
2014-11-28 08:01:25 +09:00
}
2014-05-14 16:46:07 +09:00
2015-07-12 05:25:34 +09:00
// set linkify setting
common_config_set ( 'linkify' , 'bare_domains' , $settings [ 'linkify_bare_domains' ]);
2014-11-28 08:01:25 +09:00
if ( isset ( $settings [ $setting ])) {
2015-07-02 22:00:57 +09:00
return $settings [ $setting ];
2014-11-28 08:01:25 +09:00
}
else {
return false ;
}
2014-05-14 16:46:07 +09:00
}
2015-06-07 03:37:40 +09:00
public function initialize ()
{
// show qvitter link in the admin panel
common_config_append ( 'admin' , 'panels' , 'qvitteradm' );
}
2015-07-02 22:00:57 +09:00
2016-01-08 10:06:42 +09:00
2022-10-15 16:17:31 +09:00
function onCheckSchema () : bool
2014-09-25 06:20:35 +09:00
{
$schema = Schema :: get ();
2016-01-08 10:06:42 +09:00
// make sure we have a notifications table
2014-09-25 06:20:35 +09:00
$schema -> ensureTable ( 'qvitternotification' , QvitterNotification :: schemaDef ());
2016-01-08 10:06:42 +09:00
// index the url column in the notice table
$notice_schemadef = $schema -> getTableDef ( 'notice' );
if ( ! isset ( $notice_schemadef [ 'indexes' ][ 'notice_url_idx' ])) {
try {
$schema -> createIndex ( 'notice' , 'url' );
} catch ( Exception $e ) {
common_log ( LOG_ERR , __METHOD__ . ': ' . $e -> getMessage ());
}
}
2014-09-25 06:20:35 +09:00
return true ;
2016-03-29 21:10:57 +09:00
}
2022-10-15 16:17:31 +09:00
public function onBeforePluginCheckSchema () : bool
2016-03-29 21:10:57 +09:00
{
QvitterNotification :: beforeSchemaUpdate ();
return true ;
2014-09-25 06:20:35 +09:00
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
// route/reroute urls
2014-05-14 16:46:07 +09:00
public function onRouterInitialized ( $m )
{
2017-04-06 20:45:13 +09:00
$m -> connect ( 'api/qvitter/statuses/user_timeline.:format' ,
array ( 'action' => 'ApiQvitterTimelineUser' ,
'format' => '(xml|json|rss|atom|as)' ));
2016-03-05 07:07:15 +09:00
$m -> connect ( ':nickname/mutes' ,
array ( 'action' => 'qvitter' ,
'nickname' => Nickname :: INPUT_FMT ));
$m -> connect ( 'api/qvitter/mutes.json' ,
array ( 'action' => 'ApiQvitterMutes' ));
2016-02-27 07:18:02 +09:00
$m -> connect ( 'api/qvitter/sandboxed.:format' ,
array ( 'action' => 'ApiQvitterSandboxed' ,
'format' => '(xml|json)' ));
$m -> connect ( 'api/qvitter/silenced.:format' ,
array ( 'action' => 'ApiQvitterSilenced' ,
'format' => '(xml|json)' ));
2016-03-01 03:37:06 +09:00
$m -> connect ( 'api/qvitter/sandbox/create.json' ,
array ( 'action' => 'ApiQvitterSandboxCreate' ));
$m -> connect ( 'api/qvitter/sandbox/destroy.json' ,
array ( 'action' => 'ApiQvitterSandboxDestroy' ));
2016-02-27 07:18:02 +09:00
$m -> connect ( 'api/qvitter/silence/create.json' ,
array ( 'action' => 'ApiQvitterSilenceCreate' ));
2016-03-01 03:37:06 +09:00
$m -> connect ( 'api/qvitter/silence/destroy.json' ,
array ( 'action' => 'ApiQvitterSilenceDestroy' ));
2016-01-21 04:56:50 +09:00
$m -> connect ( 'services/oembed.:format' ,
2016-01-21 04:39:50 +09:00
array ( 'action' => 'apiqvitteroembednotice' ,
'format' => '(xml|json)' ));
2015-12-15 05:01:27 +09:00
$m -> connect ( 'api/qvitter/check_email.json' ,
array ( 'action' => 'ApiQvitterCheckEmail' ));
2015-11-30 04:19:23 +09:00
$m -> connect ( 'api/qvitter/:nickname/lists/:id/subscribers.json' ,
array ( 'action' => 'ApiQvitterListSubscribers' ,
'nickname' => '[a-zA-Z0-9]+' ,
'id' => '[a-zA-Z0-9]+' ));
$m -> connect ( 'api/qvitter/:nickname/lists/:id/members.json' ,
array ( 'action' => 'ApiQvitterListMembers' ,
'nickname' => '[a-zA-Z0-9]+' ,
'id' => '[a-zA-Z0-9]+' ));
$m -> connect ( 'api/qvitter/:nickname/lists/:id/statuses.json' ,
array ( 'action' => 'ApiQvitterTimelineList' ,
'nickname' => '[a-zA-Z0-9]+' ,
'id' => '[a-zA-Z0-9]+' ));
2015-11-18 23:32:20 +09:00
$m -> connect ( 'api/qvitter/blocks.json' ,
array ( 'action' => 'ApiQvitterBlocks' ));
2015-11-18 06:48:28 +09:00
$m -> connect ( 'api/qvitter/hello.json' ,
array ( 'action' => 'ApiQvitterHello' ));
$m -> connect ( 'api/qvitter/mark_all_notifications_as_seen.json' ,
array ( 'action' => 'ApiQvitterMarkAllNotificationsAsSeen' ));
2015-02-26 05:16:24 +09:00
$m -> connect ( 'api/qvitter/favs_and_repeats/:notice_id.json' ,
array ( 'action' => 'ApiFavsAndRepeats' ),
array ( 'notice_id' => '[0-9]+' ));
2014-05-14 16:46:07 +09:00
$m -> connect ( 'api/statuses/public_and_external_timeline.:format' ,
array ( 'action' => 'ApiTimelinePublicAndExternal' ,
'format' => '(xml|json|rss|atom|as)' ));
2015-09-01 06:53:09 +09:00
$m -> connect ( 'api/qvitter/update_bookmarks.json' ,
array ( 'action' => 'ApiQvitterUpdateBookmarks' ));
2015-11-18 06:48:28 +09:00
$m -> connect ( 'api/qvitter/set_profile_pref.json' ,
array ( 'action' => 'ApiQvitterSetProfilePref' ));
2015-09-01 06:53:09 +09:00
$m -> connect ( 'api/qvitter/update_link_color.json' ,
2014-05-14 16:46:07 +09:00
array ( 'action' => 'apiqvitterupdatelinkcolor' ));
$m -> connect ( 'api/qvitter/update_background_color.json' ,
array ( 'action' => 'apiqvitterupdatebackgroundcolor' ));
2014-05-16 19:36:30 +09:00
$m -> connect ( 'api/qvitter/checklogin.json' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'apiqvitterchecklogin' ));
2014-05-28 03:40:51 +09:00
$m -> connect ( 'api/qvitter/allfollowing/:id.json' ,
array ( 'action' => 'apiqvitterallfollowing' ,
2015-07-02 22:00:57 +09:00
'id' => Nickname :: INPUT_FMT ));
2016-01-29 05:12:34 +09:00
$m -> connect ( 'api/account/update_profile_banner.json' ,
array ( 'action' => 'ApiAccountUpdateProfileBanner' ));
2016-01-29 07:15:32 +09:00
$m -> connect ( 'api/saved_searches/list.json' ,
array ( 'action' => 'ApiSavedSearchesList' ));
$m -> connect ( 'api/trends/place.json' ,
array ( 'action' => 'ApiTrendsPlace' ));
$m -> connect ( 'api/activity/about_me/unread.json' ,
array ( 'action' => 'ApiActivityAboutMeUnread' ));
2014-11-24 21:47:45 +09:00
$m -> connect ( 'api/qvitter/update_background_image.json' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'ApiUpdateBackgroundImage' ));
2014-11-24 21:47:45 +09:00
$m -> connect ( 'api/qvitter/update_avatar.json' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'ApiUpdateAvatar' ));
2015-01-23 21:20:30 +09:00
$m -> connect ( 'api/qvitter/upload_image.json' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'ApiUploadImage' ));
2014-11-24 21:47:45 +09:00
$m -> connect ( 'api/qvitter/external_user_show.json' ,
array ( 'action' => 'ApiExternalUserShow' ));
$m -> connect ( 'api/qvitter/toggle_qvitter.json' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'ApiToggleQvitter' ));
2014-09-25 06:20:35 +09:00
$m -> connect ( 'api/qvitter/statuses/notifications.json' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'apiqvitternotifications' ));
2014-09-25 06:20:35 +09:00
$m -> connect ( ':nickname/notifications' ,
array ( 'action' => 'qvitter' ,
2015-07-02 22:00:57 +09:00
'nickname' => Nickname :: INPUT_FMT ));
2016-02-02 08:44:44 +09:00
$m -> connect ( ':nickname/blocks' ,
array ( 'action' => 'qvitter' ,
'nickname' => Nickname :: INPUT_FMT ));
2014-05-14 16:46:07 +09:00
$m -> connect ( 'settings/qvitter' ,
array ( 'action' => 'qvittersettings' ));
2014-09-25 06:20:35 +09:00
$m -> connect ( 'panel/qvitter' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'qvitteradminsettings' ));
2014-05-14 16:46:07 +09:00
$m -> connect ( 'main/qlogin' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'qvitterlogin' ));
2016-01-15 04:50:17 +09:00
$m -> connect ( 'api/qvitter/statuses/update.:format' ,
array ( 'action' => 'ApiQvitterStatusesUpdate' ),
array ( 'format' => '(xml|json)' ));
2015-07-07 07:52:26 +09:00
2015-07-11 22:09:39 +09:00
// check if we should reroute UI to qvitter, and which home-stream the user wants (hide-replies or normal)
$scoped = Profile :: current ();
$qvitter_enabled_by_user = 0 ;
$qvitter_disabled_by_user = 0 ;
if ( $scoped instanceof Profile ) {
$qvitter_enabled_by_user = ( int ) $scoped -> getPref ( 'qvitter' , 'enable_qvitter' , false );
$qvitter_disabled_by_user = ( int ) $scoped -> getPref ( 'qvitter' , 'disable_qvitter' , false );
$this -> qvitter_hide_replies = $scoped -> getPref ( 'qvitter' , 'hide_replies' , false );
}
// reroute to qvitter if we're logged out and qvitter is enabled by default
if ( static :: settings ( 'enabledbydefault' ) === true && is_null ( $scoped )) {
$this -> hijack_ui = true ;
}
// if we're logged in and qvitter is enabled by default, reroute if the user has not disabled qvitter
elseif ( static :: settings ( 'enabledbydefault' ) === true && $qvitter_disabled_by_user == 0 ){
$this -> hijack_ui = true ;
}
// if we're logged in, and qvitter is _not_ enabled by default, reroute if the user enabled qvitter
elseif ( static :: settings ( 'enabledbydefault' ) === false && $qvitter_enabled_by_user == 1 ) {
$this -> hijack_ui = true ;
}
2015-07-11 04:39:15 +09:00
if ( $this -> hijack_ui === true ) {
2015-10-20 01:47:24 +09:00
// other plugins might want to reroute to qvitter
Event :: handle ( 'QvitterHijackUI' , array ( $m ));
$m -> connect ( '' , array ( 'action' => 'qvitter' ));
2015-07-02 22:00:57 +09:00
$m -> connect ( 'main/all' , array ( 'action' => 'qvitter' ));
2015-08-25 20:27:14 +09:00
$m -> connect ( 'main/public' , array ( 'action' => 'qvitter' ));
2016-02-27 07:18:02 +09:00
$m -> connect ( 'main/silenced' , array ( 'action' => 'qvitter' ));
$m -> connect ( 'main/sandboxed' , array ( 'action' => 'qvitter' ));
2015-07-02 22:00:57 +09:00
$m -> connect ( 'search/notice' , array ( 'action' => 'qvitter' ));
2015-07-07 07:52:26 +09:00
// if the user wants the twitter style home stream with hidden replies to non-friends
2015-07-11 08:06:46 +09:00
if ( $this -> qvitter_hide_replies == 1 ) {
2015-07-07 07:52:26 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , 'api/statuses/friends_timeline.:format' ,
array ( 'action' => 'ApiTimelineFriends' ),
array ( 'format' => '(xml|json|rss|atom|as)' ),
'ApiTimelineFriendsHiddenReplies' );
}
2015-07-02 22:00:57 +09:00
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname' ,
array ( 'action' => 'showstream' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
2014-05-14 16:46:07 +09:00
'qvitter' );
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/' ,
array ( 'action' => 'showstream' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/all' ,
array ( 'action' => 'all' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
2014-05-14 16:46:07 +09:00
'qvitter' );
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/subscriptions' ,
array ( 'action' => 'subscriptions' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/subscribers' ,
array ( 'action' => 'subscribers' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/groups' ,
array ( 'action' => 'usergroups' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/replies' ,
array ( 'action' => 'replies' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/favorites' ,
array ( 'action' => 'showfavorites' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , 'group/:nickname' ,
array ( 'action' => 'showgroup' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2014-05-14 16:46:07 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , 'group/:nickname/members' ,
array ( 'action' => 'groupmembers' ),
2015-07-02 22:00:57 +09:00
array ( 'nickname' => Nickname :: DISPLAY_FMT ),
'qvitter' );
2015-11-30 04:19:23 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , ':nickname/all/:tag' ,
array ( 'action' => 'showprofiletag' ),
array ( 'nickname' => Nickname :: DISPLAY_FMT ,
'tag' => Router :: REGEX_TAG ),
'qvitter' );
URLMapperOverwrite :: overwrite_variable ( $m , ':tagger/all/:tag/tagged' ,
array ( 'action' => 'peopletagged' ),
array ( 'tagger' => Nickname :: DISPLAY_FMT ,
'tag' => Router :: REGEX_TAG ),
'qvitter' );
URLMapperOverwrite :: overwrite_variable ( $m , ':tagger/all/:tag/subscribers' ,
array ( 'action' => 'peopletagsubscribers' ),
array ( 'tagger' => Nickname :: DISPLAY_FMT ,
'tag' => Router :: REGEX_TAG ),
'qvitter' );
2014-05-14 16:46:07 +09:00
$m -> connect ( 'group/:nickname/admins' ,
array ( 'action' => 'qvitter' ),
array ( 'nickname' => Nickname :: DISPLAY_FMT ));
URLMapperOverwrite :: overwrite_variable ( $m , 'tag/:tag' ,
array ( 'action' => 'showstream' ),
2015-07-02 22:00:57 +09:00
array ( 'tag' => Router :: REGEX_TAG ),
'qvitter' );
2014-09-25 06:20:35 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , 'notice/:notice' ,
array ( 'action' => 'shownotice' ),
2015-07-02 22:00:57 +09:00
array ( 'notice' => '[0-9]+' ),
'qvitter' );
2017-04-06 20:45:13 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , 'user/:id' ,
array ( 'action' => 'userbyid' ),
array ( 'id' => '[0-9]+' ),
'qvitter' );
2015-11-17 02:13:48 +09:00
URLMapperOverwrite :: overwrite_variable ( $m , 'conversation/:id' ,
array ( 'action' => 'conversation' ),
array ( 'id' => '[0-9]+' ),
'qvitter' );
2015-07-02 22:00:57 +09:00
}
2015-01-20 02:01:10 +09:00
// if qvitter is opt-out, disable the default register page (if we don't have a valid invitation code)
2015-06-07 04:06:35 +09:00
$valid_code = isset ( $_POST [ 'code' ])
? Invitation :: getKV ( 'code' , $_POST [ 'code' ])
: null ;
2015-01-20 02:01:10 +09:00
if ( self :: settings ( 'enabledbydefault' ) && empty ( $valid_code )) {
2014-10-31 08:28:06 +09:00
$m -> connect ( 'main/register' ,
2015-07-02 22:00:57 +09:00
array ( 'action' => 'qvitter' ));
2014-10-31 08:28:06 +09:00
}
2015-06-03 06:45:46 +09:00
// add user arrays for some urls, to use to build profile cards
// this way we don't have to request this in a separate http request
2015-06-04 06:25:55 +09:00
if ( isset ( $_GET [ 'withuserarray' ])) switch ( getPath ( $_REQUEST )) {
case 'api/statuses/followers.json' :
case 'api/statuses/friends.json' :
case 'api/statusnet/groups/list.json' :
case 'api/statuses/mentions.json' :
case 'api/favorites.json' :
case 'api/statuses/friends_timeline.json' :
case 'api/statuses/user_timeline.json' :
2017-04-06 20:45:13 +09:00
case 'api/qvitter/statuses/user_timeline.json' :
2015-07-02 22:00:57 +09:00
2015-06-03 06:45:46 +09:00
// add logged in user's user array
2015-09-18 08:42:52 +09:00
if ( common_logged_in () && ! isset ( $_GET [ 'screen_name' ]) && ! isset ( $_GET [ 'id' ])) {
2015-07-02 22:00:57 +09:00
$profilecurrent = Profile :: current ();
2015-06-03 06:45:46 +09:00
header ( 'Qvitter-User-Array: ' . json_encode ( $this -> qvitterTwitterUserArray ( $profilecurrent )));
}
// add screen_name's user array
2015-09-18 08:42:52 +09:00
elseif ( isset ( $_GET [ 'screen_name' ]) || isset ( $_GET [ 'id' ])){
if ( isset ( $_GET [ 'screen_name' ])) {
$user = User :: getKV ( 'nickname' , $_GET [ 'screen_name' ]);
2017-04-06 20:45:13 +09:00
if ( $user instanceof User ) {
$profile = $user -> getProfile ();
}
2015-09-18 08:42:52 +09:00
}
elseif ( isset ( $_GET [ 'id' ])) {
2017-04-06 20:45:13 +09:00
$profile = Profile :: getKV ( 'id' , $_GET [ 'id' ]);
2015-09-18 08:42:52 +09:00
$user = User :: getKV ( 'id' , $_GET [ 'id' ]);
}
2017-04-06 20:45:13 +09:00
if ( isset ( $profile ) && $profile instanceof Profile ) {
header ( 'Qvitter-User-Array: ' . json_encode ( $this -> qvitterTwitterUserArray ( $profile )));
2015-06-03 06:45:46 +09:00
}
2015-07-02 22:00:57 +09:00
}
2015-06-04 06:25:55 +09:00
break ;
2015-07-02 22:00:57 +09:00
}
2014-05-14 16:46:07 +09:00
}
2015-07-02 22:00:57 +09:00
2014-11-24 21:47:45 +09:00
/**
* Add script to default ui , to be able to toggle Qvitter with one click
*
* @ return boolean hook return
2015-07-02 22:00:57 +09:00
*/
2014-11-24 21:47:45 +09:00
function onEndShowScripts ( $action ){
2015-07-02 22:00:57 +09:00
if ( common_logged_in ()) {
2014-11-24 21:47:45 +09:00
$user = common_current_user ();
$profile = $user -> getProfile ();
$qvitter_enabled = 'false' ;
// if qvitter is enabled by default but _not_ disabled by the user,
if ( QvitterPlugin :: settings ( 'enabledbydefault' )) {
$disabled = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'disable_qvitter' );
if ( $disabled == 0 ) {
$qvitter_enabled = 'true' ;
}
}
// if qvitter is disabled by default and _enabled_ by the user,
else {
$enabled = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'enable_qvitter' );
if ( $enabled == 1 ) {
$qvitter_enabled = 'true' ;
}
}
2014-11-27 20:54:56 +09:00
$action -> inlineScript ( ' var toggleQvitterAPIURL = \'' . common_path ( '' , true ) . ' api / qvitter / toggle_qvitter . json\ ' ;
2015-08-05 20:49:42 +09:00
var toggleText = \ '' . _ ( 'New' ) . ' ' . str_replace ( " ' " , " \ ' " , common_config ( 'site' , 'name' )) . ' \ ' ;
2014-11-27 20:54:56 +09:00
var qvitterEnabled = '.$qvitter_enabled.' ;
var qvitterAllLink = \ '' . common_local_url ( 'all' , array ( 'nickname' => $user -> nickname )) . ' \ ' ;
2015-07-02 22:00:57 +09:00
' );
2014-12-05 12:48:55 +09:00
$action -> script ( $this -> path ( 'js/toggleqvitter.js' ) . '?changed=' . date ( 'YmdHis' , filemtime ( QVITTERDIR . '/js/toggleqvitter.js' )));
2014-11-24 21:47:45 +09:00
}
}
2015-07-02 22:00:57 +09:00
2014-05-14 16:46:07 +09:00
/**
* Menu item for Qvitter
*
* @ param Action $action action being executed
*
* @ return boolean hook return
*/
2022-10-15 16:17:31 +09:00
function onEndAccountSettingsNav ( $action ) : bool
2014-05-14 16:46:07 +09:00
{
$action_name = $action -> trimmed ( 'action' );
$action -> menuItem ( common_local_url ( 'qvittersettings' ),
// TRANS: Poll plugin menu item on user settings page.
_m ( 'MENU' , 'Qvitter' ),
// TRANS: Poll plugin tooltip for user settings menu item.
2015-07-07 07:52:26 +09:00
_m ( 'Qvitter Settings' ),
2014-05-14 16:46:07 +09:00
$action_name === 'qvittersettings' );
return true ;
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
/**
* Menu item for admin panel
*
* @ param Action $action action being executed
*
* @ return boolean hook return
*/
2022-10-15 16:17:31 +09:00
function onEndAdminPanelNav ( $action ) : bool
2014-09-25 06:20:35 +09:00
{
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
$action_name = $action -> trimmed ( 'action' );
$action -> out -> menuItem ( common_local_url ( 'qvitteradminsettings' ),
// TRANS: Poll plugin menu item on user settings page.
_m ( 'MENU' , 'Qvitter' ),
// TRANS: Poll plugin tooltip for user settings menu item.
_m ( 'Qvitter Sidebar Notice' ),
$action_name === 'qvitteradminsettings' );
return true ;
2015-07-02 22:00:57 +09:00
}
2014-09-25 06:20:35 +09:00
2014-09-10 03:48:44 +09:00
/**
2014-10-03 02:24:54 +09:00
* Add stuff to notices in API responses
2014-09-10 03:48:44 +09:00
*
* @ param Action $action action being executed
*
* @ return boolean hook return
*/
2015-02-26 05:16:24 +09:00
function onNoticeSimpleStatusArray ( $notice , & $twitter_status , $scoped )
2014-09-10 03:48:44 +09:00
{
2015-07-02 22:00:57 +09:00
2016-09-02 05:55:04 +09:00
// strip tags from source, we can't trust html here, because of gs bug
$twitter_status [ 'source' ] = htmlspecialchars ( strip_tags ( $twitter_status [ 'source' ]));
2014-10-03 02:24:54 +09:00
// groups
2014-09-10 03:48:44 +09:00
$notice_groups = $notice -> getGroups ();
$group_addressees = false ;
foreach ( $notice_groups as $g ) {
2015-08-26 07:11:31 +09:00
$group_addressees [] = array ( 'nickname' => $g -> nickname , 'url' => $g -> mainpage );
2014-11-24 21:47:45 +09:00
}
2015-07-02 22:00:57 +09:00
$twitter_status [ 'statusnet_in_groups' ] = $group_addressees ;
2014-09-10 03:48:44 +09:00
2015-11-26 02:26:13 +09:00
// for older verions of gnu social: include the repeat-id, which we need when unrepeating later
if ( array_key_exists ( 'repeated' , $twitter_status ) && $twitter_status [ 'repeated' ] === true ) {
$repeated = Notice :: pkeyGet ( array ( 'profile_id' => $scoped -> id ,
'repeat_of' => $notice -> id ,
'verb' => 'http://activitystrea.ms/schema/1.0/share' ));
$twitter_status [ 'repeated_id' ] = $repeated -> id ;
}
2015-09-21 07:58:11 +09:00
// more metadata about attachments
2015-07-02 22:00:57 +09:00
2015-09-21 07:58:11 +09:00
// get all attachments first, and put all the extra meta data in an array
2014-10-03 02:24:54 +09:00
$attachments = $notice -> attachments ();
2015-01-24 00:28:41 +09:00
$attachment_url_to_id = array ();
2014-10-03 02:24:54 +09:00
if ( ! empty ( $attachments )) {
foreach ( $attachments as $attachment ) {
2015-07-02 22:00:57 +09:00
if ( is_object ( $attachment )) {
2015-09-21 07:58:11 +09:00
try {
2015-06-10 06:42:41 +09:00
$enclosure_o = $attachment -> getEnclosure ();
2015-09-21 07:58:11 +09:00
2016-01-21 01:39:34 +09:00
// Oembed
2022-10-15 15:56:19 +09:00
if ( array_key_exists ( 'Oembed' , GNUsocial :: getActiveModules ())) {
2016-01-21 01:39:34 +09:00
$oembed = File_oembed :: getKV ( 'file_id' , $attachment -> id );
if ( $oembed instanceof File_oembed ) {
2016-01-21 03:06:21 +09:00
$oembed_html = str_replace ( '<!--//-->' , '' , $oembed -> html ); // trash left of wordpress' javascript after htmLawed removed the tags
2016-02-25 19:08:47 +09:00
if ( $oembed -> provider == 'Twitter' && strstr ( $oembed_html , '>— ' . $oembed -> author_name )) {
$oembed_html = substr ( $oembed_html , 0 , strpos ( $oembed_html , '>— ' . $oembed -> author_name ) + 1 ); // remove user data from twitter oembed html (we have it in )
$twitter_username = substr ( $oembed -> html , strpos ( $oembed -> html , '>— ' . $oembed -> author_name ) + strlen ( '>— ' . $oembed -> author_name ));
2016-01-21 10:16:39 +09:00
$twitter_username = substr ( $twitter_username , strpos ( $twitter_username , '(@' ) + 1 );
$twitter_username = substr ( $twitter_username , 0 , strpos ( $twitter_username , ')' ));
$oembed -> title = $twitter_username ;
}
2016-01-21 03:06:21 +09:00
$oembed_html = str_replace ( '…' , '...' , $oembed_html ); // ellipsis is sometimes stored as html in db, for some reason
2016-02-25 19:08:47 +09:00
$oembed_html = mb_substr ( trim ( strip_tags ( $oembed_html )), 0 , 250 );
$oembed_title = trim ( strip_tags ( html_entity_decode ( $oembed -> title , ENT_QUOTES ))); // sometimes we have html charachters that we want to decode and then strip
2016-01-23 08:31:13 +09:00
$oembed_provider = trim ( strip_tags ( html_entity_decode ( $oembed -> provider , ENT_QUOTES )));
$oembed_author_name = trim ( strip_tags ( html_entity_decode ( $oembed -> author_name , ENT_QUOTES )));
2016-01-21 01:39:34 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'oembed' ] = array (
2016-01-21 10:16:39 +09:00
'type' => $oembed -> type ,
2016-01-23 08:31:13 +09:00
'provider' => $oembed_provider ,
2016-01-21 01:39:34 +09:00
'provider_url' => $oembed -> provider_url ,
2016-01-21 03:06:21 +09:00
'oembedHTML' => $oembed_html ,
2016-01-21 08:31:28 +09:00
'title' => $oembed_title ,
2016-01-23 08:31:13 +09:00
'author_name' => $oembed_author_name ,
2016-01-21 01:39:34 +09:00
'author_url' => $oembed -> author_url
);
} else {
$attachment_url_to_id [ $enclosure_o -> url ][ 'oembed' ] = false ;
}
}
2015-09-21 07:58:11 +09:00
// add id to all attachments
$attachment_url_to_id [ $enclosure_o -> url ][ 'id' ] = $attachment -> id ;
2016-01-23 05:19:08 +09:00
// add an attachment version to all attachments
// this means we can force all cached attachments to update, if we change this
$attachment_url_to_id [ $enclosure_o -> url ][ 'version' ] = '1.2' ;
2015-09-21 07:58:11 +09:00
// add data about thumbnails
$thumb = $attachment -> getThumbnail ();
2015-09-13 08:59:02 +09:00
$large_thumb = $attachment -> getThumbnail ( 1000 , 3000 , false );
if ( method_exists ( 'File_thumbnail' , 'url' )) {
$thumb_url = File_thumbnail :: url ( $thumb -> filename );
$large_thumb_url = File_thumbnail :: url ( $large_thumb -> filename );
} else {
$thumb_url = $thumb -> getUrl ();
$large_thumb_url = $large_thumb -> getUrl ();
}
$attachment_url_to_id [ $enclosure_o -> url ][ 'thumb_url' ] = $thumb_url ;
$attachment_url_to_id [ $enclosure_o -> url ][ 'large_thumb_url' ] = $large_thumb_url ;
2015-06-10 06:42:41 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'width' ] = $attachment -> width ;
2015-07-02 22:00:57 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'height' ] = $attachment -> height ;
2015-06-17 07:44:18 +09:00
// animated gif?
if ( $attachment -> mimetype == 'image/gif' ) {
$image = ImageFile :: fromFileObject ( $attachment );
if ( $image -> animated == 1 ) {
$attachment_url_to_id [ $enclosure_o -> url ][ 'animated' ] = true ;
2016-01-21 01:39:34 +09:00
} else {
2015-07-02 22:00:57 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'animated' ] = false ;
2015-06-17 07:44:18 +09:00
}
2016-01-21 01:39:34 +09:00
}
2015-07-02 22:00:57 +09:00
2015-09-21 07:58:11 +09:00
// this applies to older versions of gnu social, i think
2016-01-26 19:44:42 +09:00
} catch ( Exception $e ) {
2017-02-05 21:17:36 +09:00
$twitter_status [ 'attachment_error' ] = array ( 'code' => $e -> getCode (), 'message' => $e -> getMessage (), 'file' => $e -> getFile (), 'line' => $e -> getLine (), 'trace' => $e -> getTraceAsString ());
2015-06-10 06:42:41 +09:00
$thumb = File_thumbnail :: getKV ( 'file_id' , $attachment -> id );
if ( $thumb instanceof File_thumbnail ) {
2015-09-13 08:59:02 +09:00
$thumb_url = $thumb -> getUrl ();
2015-06-10 06:42:41 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'id' ] = $attachment -> id ;
2015-09-13 08:59:02 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'thumb_url' ] = $thumb_url ;
$attachment_url_to_id [ $enclosure_o -> url ][ 'large_thumb_url' ] = $thumb_url ;
2015-06-10 06:42:41 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'width' ] = $attachment -> width ;
2015-07-02 22:00:57 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'height' ] = $attachment -> height ;
2015-06-17 07:44:18 +09:00
// animated gif?
if ( $attachment -> mimetype == 'image/gif' ) {
$image = ImageFile :: fromFileObject ( $attachment );
if ( $image -> animated == 1 ) {
$attachment_url_to_id [ $enclosure_o -> url ][ 'animated' ] = true ;
}
else {
2015-07-02 22:00:57 +09:00
$attachment_url_to_id [ $enclosure_o -> url ][ 'animated' ] = false ;
2015-06-17 07:44:18 +09:00
}
2015-07-02 22:00:57 +09:00
}
}
2015-06-10 06:42:41 +09:00
}
}
2015-04-30 19:50:28 +09:00
}
2014-10-03 02:24:54 +09:00
}
2015-07-02 22:00:57 +09:00
2015-09-21 07:58:11 +09:00
// add the extra meta data to $twitter_status
2014-10-03 02:24:54 +09:00
if ( ! empty ( $twitter_status [ 'attachments' ])) {
foreach ( $twitter_status [ 'attachments' ] as & $attachment ) {
2015-01-24 00:28:41 +09:00
if ( ! empty ( $attachment_url_to_id [ $attachment [ 'url' ]])) {
2015-09-21 07:58:11 +09:00
$attachment = array_merge ( $attachment , $attachment_url_to_id [ $attachment [ 'url' ]]);
2014-10-03 02:24:54 +09:00
}
}
2015-07-02 22:00:57 +09:00
}
2016-01-07 11:03:18 +09:00
// quoted notices
if ( ! empty ( $twitter_status [ 'attachments' ])) {
foreach ( $twitter_status [ 'attachments' ] as & $attachment ) {
$quoted_notice = false ;
// if this attachment has an url this might be a notice url
if ( isset ( $attachment [ 'url' ])) {
2022-10-15 15:56:19 +09:00
$noticeurl = common_path ( 'notice/' , GNUsocial :: isHTTPS ());
$instanceurl = common_path ( '' , GNUsocial :: isHTTPS ());
2016-01-07 11:03:18 +09:00
2016-01-08 00:07:15 +09:00
// remove protocol for the comparison below
$noticeurl_wo_protocol = preg_replace ( '(^https?://)' , '' , $noticeurl );
$instanceurl_wo_protocol = preg_replace ( '(^https?://)' , '' , $instanceurl );
$attachment_url_wo_protocol = preg_replace ( '(^https?://)' , '' , $attachment [ 'url' ]);
2016-01-07 11:03:18 +09:00
// local notice urls
2016-01-08 00:07:15 +09:00
if ( strpos ( $attachment_url_wo_protocol , $noticeurl_wo_protocol ) === 0 ) {
$possible_notice_id = str_replace ( $noticeurl_wo_protocol , '' , $attachment_url_wo_protocol );
2016-01-07 11:03:18 +09:00
if ( ctype_digit ( $possible_notice_id )) {
$quoted_notice = Notice :: getKV ( 'id' , $possible_notice_id );;
}
}
// remote. but we don't want to lookup every url in the db,
// so only do this if we have reason to believe this might
// be a remote notice url
2016-01-08 00:07:15 +09:00
elseif ( strpos ( $attachment_url_wo_protocol , $instanceurl_wo_protocol ) !== 0 && stristr ( $attachment_url_wo_protocol , '/notice/' )) {
2016-01-07 11:03:18 +09:00
$quoted_notice = Notice :: getKV ( 'url' , $attachment [ 'url' ]);
2016-01-08 10:21:14 +09:00
// try with http<->https if no match. applies to quitter.se notices mostly
if ( ! $quoted_notice instanceof Notice ) {
if ( strpos ( $attachment [ 'url' ], 'https://' ) === 0 ) {
$quoted_notice = Notice :: getKV ( 'url' , str_replace ( 'https://' , 'http://' , $attachment [ 'url' ]));
} else {
$quoted_notice = Notice :: getKV ( 'url' , str_replace ( 'http://' , 'https://' , $attachment [ 'url' ]));
}
}
2016-01-07 11:03:18 +09:00
}
// include the quoted notice in the attachment
if ( $quoted_notice instanceof Notice ) {
$quoted_notice_author = Profile :: getKV ( 'id' , $quoted_notice -> profile_id );
if ( $quoted_notice_author instanceof Profile ) {
$attachment [ 'quoted_notice' ][ 'id' ] = $quoted_notice -> id ;
$attachment [ 'quoted_notice' ][ 'content' ] = $quoted_notice -> content ;
$attachment [ 'quoted_notice' ][ 'nickname' ] = $quoted_notice_author -> nickname ;
$attachment [ 'quoted_notice' ][ 'fullname' ] = $quoted_notice_author -> fullname ;
2016-01-23 05:19:08 +09:00
$attachment [ 'quoted_notice' ][ 'is_local' ] = $quoted_notice_author -> isLocal ();
2016-01-07 11:03:18 +09:00
$quoted_notice_attachments = $quoted_notice -> attachments ();
foreach ( $quoted_notice_attachments as $q_attach ) {
if ( is_object ( $q_attach )) {
try {
$qthumb = $q_attach -> getThumbnail ();
2016-01-07 22:13:06 +09:00
if ( method_exists ( 'File_thumbnail' , 'url' )) {
$thumb_url = File_thumbnail :: url ( $qthumb -> filename );
} else {
$thumb_url = $qthumb -> getUrl ();
}
2016-01-07 11:03:18 +09:00
$attachment [ 'quoted_notice' ][ 'attachments' ][] = array ( 'thumb_url' => $thumb_url ,
'attachment_id' => $q_attach -> id );
} catch ( Exception $e ) {
2016-01-07 22:13:06 +09:00
common_debug ( 'Qvitter: could not get thumbnail for attachment id=' . $q_attach -> id . ' in quoted notice id=' . $quoted_notice -> id );
2016-01-07 11:03:18 +09:00
}
}
}
}
}
}
}
}
2016-01-21 01:39:34 +09:00
try {
$twitter_status [ 'external_url' ] = $notice -> getUrl ( true );
} catch ( InvalidUrlException $e ) {
common_debug ( 'Qvitter: No URL available for external notice: id=' . $notice -> id );
}
2016-01-07 11:03:18 +09:00
2014-11-24 21:47:45 +09:00
// reply-to profile url
2015-06-12 23:56:25 +09:00
try {
$reply = $notice -> getParent ();
2016-02-17 03:20:20 +09:00
$reply_profile = $reply -> getProfile ();
$twitter_status [ 'in_reply_to_profileurl' ] = $reply_profile -> getUrl ();
$twitter_status [ 'in_reply_to_ostatus_uri' ] = $reply_profile -> getUri ();
2015-06-12 23:56:25 +09:00
} catch ( ServerException $e ) {
$twitter_status [ 'in_reply_to_profileurl' ] = null ;
2016-02-16 22:28:00 +09:00
$twitter_status [ 'in_reply_to_ostatus_uri' ] = null ;
2014-11-24 21:47:45 +09:00
}
2014-11-25 09:58:30 +09:00
2016-02-17 03:20:20 +09:00
// attentions
try {
$attentions = $notice -> getAttentionProfiles ();
$attentions_array = array ();
foreach ( $attentions as $attn ) {
2016-02-17 09:37:15 +09:00
if ( ! $attn -> isGroup ()) {
$attentions_array [] = array (
'id' => $attn -> getID (),
'screen_name' => $attn -> getNickname (),
'fullname' => $attn -> getStreamName (),
'profileurl' => $attn -> getUrl (),
'ostatus_uri' => $attn -> getUri (),
);
}
2016-02-17 03:20:20 +09:00
}
$twitter_status [ 'attentions' ] = $attentions_array ;
} catch ( Exception $e ) {
//
}
2015-11-23 08:24:33 +09:00
2015-06-24 22:34:44 +09:00
// fave number
$faves = Fave :: byNotice ( $notice );
$favenum = count ( $faves );
$twitter_status [ 'fave_num' ] = $favenum ;
2015-07-02 22:00:57 +09:00
2015-06-24 22:34:44 +09:00
// repeat number
$repeats = $notice -> repeatStream ();
$repeatnum = 0 ;
while ( $repeats -> fetch ()) {
2015-11-23 08:24:33 +09:00
if ( $repeats -> verb == ActivityVerb :: SHARE ) { // i.e. not deleted repeats
$repeatnum ++ ;
}
2015-06-24 22:34:44 +09:00
}
2015-07-02 22:00:57 +09:00
$twitter_status [ 'repeat_num' ] = $repeatnum ;
2016-01-07 22:13:06 +09:00
// is this a post? (previously is_activity)
if ( method_exists ( 'ActivityUtils' , 'compareVerbs' )) {
$twitter_status [ 'is_post_verb' ] = ActivityUtils :: compareVerbs ( $notice -> verb , array ( ActivityVerb :: POST ));
}
else {
$twitter_status [ 'is_post_verb' ] = ( $notice -> verb == ActivityVerb :: POST ? true : false );
}
2016-01-05 20:47:26 +09:00
2014-11-24 21:47:45 +09:00
// some more metadata about notice
if ( $notice -> is_local == '1' ) {
2015-07-02 22:00:57 +09:00
$twitter_status [ 'is_local' ] = true ;
2014-11-24 21:47:45 +09:00
}
else {
2015-07-02 22:00:57 +09:00
$twitter_status [ 'is_local' ] = false ;
2016-01-05 20:47:26 +09:00
if ( $twitter_status [ 'is_post_verb' ] === true ) {
2015-08-23 04:30:26 +09:00
try {
$twitter_status [ 'external_url' ] = $notice -> getUrl ( true );
} catch ( InvalidUrlException $e ) {
common_debug ( 'Qvitter: No URL available for external notice: id=' . $notice -> id );
}
2015-05-25 19:17:38 +09:00
}
2014-11-24 21:47:45 +09:00
}
2015-07-02 22:00:57 +09:00
2015-10-03 23:52:35 +09:00
if ( ActivityUtils :: compareTypes ( $notice -> verb , array ( 'qvitter-delete-notice' , 'delete' ))) {
2015-07-02 22:00:57 +09:00
$twitter_status [ 'qvitter_delete_notice' ] = true ;
2015-06-19 03:55:46 +09:00
}
2014-10-03 02:24:54 +09:00
2014-09-10 03:48:44 +09:00
return true ;
}
2015-07-02 22:00:57 +09:00
2014-09-10 03:48:44 +09:00
/**
2014-11-24 21:47:45 +09:00
* Cover photo in API response , also follows_you , etc
2014-09-10 03:48:44 +09:00
*
* @ return boolean hook return
*/
2022-10-15 16:17:31 +09:00
function onTwitterUserArray ( $profile , & $twitter_user , $scoped ) : bool
2014-09-10 03:48:44 +09:00
{
2015-07-02 22:00:57 +09:00
$twitter_user [ 'cover_photo' ] = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'cover_photo' );
$twitter_user [ 'background_image' ] = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'background_image' );
2016-01-29 02:51:26 +09:00
// twitter compatible
$twitter_user [ 'profile_link_color' ] = Profile_prefs :: getConfigData ( $profile , 'theme' , 'linkcolor' );
$twitter_user [ 'profile_background_color' ] = Profile_prefs :: getConfigData ( $profile , 'theme' , 'backgroundcolor' );
$twitter_user [ 'profile_banner_url' ] = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'cover_photo' );
2016-02-03 00:25:07 +09:00
2014-09-30 21:52:41 +09:00
if ( $scoped ) {
2016-02-03 00:25:07 +09:00
// follows me?
$twitter_user [ 'follows_you' ] = $profile -> isSubscribed ( $scoped );
// blocks me?
$twitter_user [ 'blocks_you' ] = $profile -> hasBlocked ( $scoped );
}
2015-07-02 22:00:57 +09:00
// local user?
2014-11-24 21:47:45 +09:00
$twitter_user [ 'is_local' ] = $profile -> isLocal ();
2014-09-30 21:52:41 +09:00
2016-02-27 07:18:02 +09:00
// silenced?
$twitter_user [ 'is_silenced' ] = $profile -> isSilenced ();
2016-02-27 10:00:25 +09:00
// rights
$twitter_user [ 'rights' ] = array ();
$twitter_user [ 'rights' ][ 'delete_user' ] = $profile -> hasRight ( Right :: DELETEUSER );
$twitter_user [ 'rights' ][ 'delete_others_notice' ] = $profile -> hasRight ( Right :: DELETEOTHERSNOTICE );
$twitter_user [ 'rights' ][ 'silence' ] = $profile -> hasRight ( Right :: SILENCEUSER );
$twitter_user [ 'rights' ][ 'sandbox' ] = $profile -> hasRight ( Right :: SANDBOXUSER );
2016-02-27 07:18:02 +09:00
// sandboxed?
$twitter_user [ 'is_sandboxed' ] = $profile -> isSandboxed ();
2015-09-15 00:49:06 +09:00
// ostatus uri
if ( $twitter_user [ 'is_local' ]) {
$user = $profile -> getUser ();
if ( $user instanceof User ) {
$twitter_user [ 'ostatus_uri' ] = $user -> uri ;
}
} else {
$ostatus_profile = Ostatus_profile :: getKV ( 'profile_id' , $profile -> id );
if ( $ostatus_profile instanceof Ostatus_profile ) {
$twitter_user [ 'ostatus_uri' ] = $ostatus_profile -> uri ;
}
}
2014-09-10 03:48:44 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2014-09-25 06:20:35 +09:00
/**
* Insert into notification table
*/
function insertNotification ( $to_profile_id , $from_profile_id , $ntype , $notice_id = false )
{
2015-07-02 22:00:57 +09:00
2015-05-19 23:51:42 +09:00
$to_user = User :: getKV ( 'id' , $to_profile_id );
2015-06-17 03:20:28 +09:00
$from_profile = Profile :: getKV ( $from_profile_id );
// don't notify remote profiles
if ( ! $to_user instanceof User ) {
return false ;
}
// no notifications from blocked profiles
if ( $to_user -> hasBlocked ( $from_profile )) {
2015-05-19 23:51:42 +09:00
return false ;
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
// never notify myself
2015-05-19 23:51:42 +09:00
if ( $to_profile_id == $from_profile_id ) {
return false ;
}
2015-07-02 22:00:57 +09:00
// insert
2015-05-19 23:51:42 +09:00
$notif = new QvitterNotification ();
$notif -> to_profile_id = $to_profile_id ;
2015-07-02 22:00:57 +09:00
$notif -> from_profile_id = $from_profile_id ;
2015-05-19 23:51:42 +09:00
$notif -> ntype = $ntype ;
2015-07-02 22:00:57 +09:00
$notif -> notice_id = $notice_id ;
$notif -> created = common_sql_now ();
2015-05-19 23:51:42 +09:00
if ( ! $notif -> insert ()) {
common_log_db_error ( $notif , 'INSERT' , __FILE__ );
return false ;
2014-09-25 06:20:35 +09:00
}
2015-05-19 23:51:42 +09:00
2014-09-25 06:20:35 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2014-09-25 06:20:35 +09:00
/**
* Insert likes in notification table
*/
public function onEndFavorNotice ( $profile , $notice )
{
2015-07-02 22:00:57 +09:00
// don't notify people favoriting their own notices
2014-09-25 06:20:35 +09:00
if ( $notice -> profile_id != $profile -> id ) {
2015-01-22 01:49:59 +09:00
$this -> insertNotification ( $notice -> profile_id , $profile -> id , 'like' , $notice -> id );
2015-07-02 22:00:57 +09:00
}
2015-11-18 08:24:57 +09:00
// mark reply and mention notifications as seen if i'm liking a notice i'm notified about
self :: markNotificationAsSeen ( $notice -> id , $profile -> id , 'mention' );
self :: markNotificationAsSeen ( $notice -> id , $profile -> id , 'reply' );
2015-07-02 22:00:57 +09:00
}
2015-11-18 08:24:57 +09:00
/**
* Mark single notification as seen
*/
2017-04-23 08:43:47 +09:00
public static function markNotificationAsSeen ( $notice_id , $to_profile_id , $ntype )
2015-11-18 08:24:57 +09:00
{
$notification_to_mark_as_seen = QvitterNotification :: pkeyGet ( array (
'is_seen' => 0 ,
'notice_id' => $notice_id ,
'to_profile_id' => $to_profile_id ,
'ntype' => $ntype
));
if ( $notification_to_mark_as_seen instanceof QvitterNotification ) {
$orig = clone ( $notification_to_mark_as_seen );
$notification_to_mark_as_seen -> is_seen = 1 ;
$notification_to_mark_as_seen -> update ( $orig );
}
}
2014-09-25 06:20:35 +09:00
/**
* Remove likes in notification table on dislike
*/
2022-10-15 16:17:31 +09:00
public function onEndDisfavorNotice ( $profile , $notice ) : bool
2014-09-25 06:20:35 +09:00
{
$notif = new QvitterNotification ();
2015-07-02 22:00:57 +09:00
$notif -> from_profile_id = $profile -> id ;
2014-09-25 06:20:35 +09:00
$notif -> notice_id = $notice -> id ;
$notif -> ntype = 'like' ;
$notif -> delete ();
return true ;
2015-07-02 22:00:57 +09:00
}
2014-09-25 06:20:35 +09:00
/**
* Insert notifications for replies , mentions and repeats
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
function onStartNoticeDistribute ( $notice ) : bool {
2015-06-17 07:44:18 +09:00
2015-06-02 20:30:29 +09:00
assert ( $notice -> id > 0 ); // since we removed tests below
2014-09-25 06:20:35 +09:00
// repeats
if ( $notice -> isRepeat ()) {
$repeated_notice = Notice :: getKV ( 'id' , $notice -> repeat_of );
2015-07-02 22:00:57 +09:00
if ( $repeated_notice instanceof Notice ) {
2014-09-25 06:20:35 +09:00
$this -> insertNotification ( $repeated_notice -> profile_id , $notice -> profile_id , 'repeat' , $repeated_notice -> id );
2015-11-18 08:24:57 +09:00
// mark reply/mention-notifications as read if we're repeating to a notice we're notified about
self :: markNotificationAsSeen ( $repeated_notice -> id , $notice -> profile_id , 'mention' );
self :: markNotificationAsSeen ( $repeated_notice -> id , $notice -> profile_id , 'reply' );
2015-11-23 08:24:33 +09:00
// (no other notifications repeats)
return true ;
2015-11-18 08:24:57 +09:00
}
2015-07-02 22:00:57 +09:00
}
2014-09-25 06:20:35 +09:00
2016-01-05 20:48:46 +09:00
// don't add notifications for activity/non-post-verb notices
2016-01-11 05:11:34 +09:00
if ( method_exists ( 'ActivityUtils' , 'compareVerbs' )) {
$is_post_verb = ActivityUtils :: compareVerbs ( $notice -> verb , array ( ActivityVerb :: POST ));
}
else {
$is_post_verb = ( $notice -> verb == ActivityVerb :: POST ? true : false );
}
if ( $notice -> source == 'activity' || ! $is_post_verb ) {
2015-11-23 08:24:33 +09:00
return true ;
2015-06-02 21:04:22 +09:00
}
2014-09-25 06:20:35 +09:00
2015-11-23 08:24:33 +09:00
// mark reply/mention-notifications as read if we're replying to a notice we're notified about
if ( $notice -> reply_to ) {
self :: markNotificationAsSeen ( $notice -> reply_to , $notice -> profile_id , 'mention' );
self :: markNotificationAsSeen ( $notice -> reply_to , $notice -> profile_id , 'reply' );
}
2015-06-17 03:20:28 +09:00
2015-07-02 22:00:57 +09:00
2015-11-23 08:24:33 +09:00
// replies and mentions
$reply_notification_to = false ;
// check for reply to insert in notifications
if ( $notice -> reply_to ) {
try {
$replyauthor = $notice -> getParent () -> getProfile ();
$reply_notification_to = $replyauthor -> id ;
$this -> insertNotification ( $replyauthor -> id , $notice -> profile_id , 'reply' , $notice -> id );
//} catch (NoParentNoticeException $e) { // TODO: catch this when everyone runs latest GNU social!
// This is not a reply to something (has no parent)
} catch ( NoResultException $e ) {
// Parent author's profile not found! Complain louder?
common_log ( LOG_ERR , " Parent notice's author not found: " . $e -> getMessage ());
}
}
// check for mentions to insert in notifications
$mentions = $notice -> getReplies ();
$sender = Profile :: getKV ( $notice -> profile_id );
$all_mentioned_user_ids = array ();
foreach ( $mentions as $mentioned ) {
// no duplicate mentions
if ( in_array ( $mentioned , $all_mentioned_user_ids )) {
continue ;
2015-07-02 22:00:57 +09:00
}
2015-11-23 08:24:33 +09:00
$all_mentioned_user_ids [] = $mentioned ;
// only notify if mentioned user is not already notified for reply
if ( $reply_notification_to != $mentioned ) {
$this -> insertNotification ( $mentioned , $notice -> profile_id , 'mention' , $notice -> id );
}
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
return true ;
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
/**
* Delete any notifications tied to deleted notices and un - repeats
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
public function onNoticeDeleteRelated ( $notice ) : bool
2014-09-25 06:20:35 +09:00
{
$notif = new QvitterNotification ();
// unrepeats
if ( $notice -> isRepeat ()) {
$repeated_notice = Notice :: getKV ( 'id' , $notice -> repeat_of );
2015-07-02 22:00:57 +09:00
$notif -> notice_id = $repeated_notice -> id ;
$notif -> from_profile_id = $notice -> profile_id ;
}
2014-09-25 06:20:35 +09:00
// notices
else {
$notif -> notice_id = $notice -> id ;
2015-07-02 22:00:57 +09:00
}
$notif -> delete ();
2015-07-12 20:27:45 +09:00
// don't delete if this is a user is being deleted
// because that creates an infinite loop of deleting and creating notices...
$user_is_deleted = false ;
2016-04-22 16:47:12 +09:00
try {
// outputs an activity notice that this notice was deleted
$profile = $notice -> getProfile ();
$user = User :: getKV ( 'id' , $profile -> id );
if ( $user instanceof User && $user -> hasRole ( Profile_role :: DELETED )) {
$user_is_deleted = true ;
}
} catch ( NoProfileException $e ) {
2015-07-12 20:27:45 +09:00
$user_is_deleted = true ;
}
2022-10-15 15:56:19 +09:00
if ( ! $user_is_deleted && class_exists ( 'GNUsocial' ) && ! array_key_exists ( 'ActivityModeration' , GNUsocial :: getActiveModules ())) {
2015-07-12 20:27:45 +09:00
$rendered = sprintf ( _m ( '<a href="%1$s">%2$s</a> deleted notice <a href="%3$s">{{%4$s}}</a>.' ),
2015-09-06 08:21:43 +09:00
htmlspecialchars ( $profile -> getUrl ()),
htmlspecialchars ( $profile -> getBestName ()),
htmlspecialchars ( $notice -> getUrl ()),
htmlspecialchars ( $notice -> uri ));
2015-07-12 20:27:45 +09:00
$text = sprintf ( _m ( '%1$s deleted notice {{%2$s}}.' ),
$profile -> getBestName (),
$notice -> uri );
$uri = TagURI :: mint ( 'delete-notice:%d:%d:%s' ,
$notice -> profile_id ,
$notice -> id ,
common_date_iso8601 ( common_sql_now ()));
$notice = Notice :: saveNew ( $notice -> profile_id ,
$text ,
ActivityPlugin :: SOURCE ,
array ( 'rendered' => $rendered ,
'urls' => array (),
'uri' => $uri ,
'verb' => 'qvitter-delete-notice' ,
'object_type' => ActivityObject :: ACTIVITY ));
}
2015-06-19 03:55:46 +09:00
2014-09-25 06:20:35 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2015-06-19 03:55:46 +09:00
/**
* Checks for deleted remote notices and deleted the locally
* A local qvitter - delete - notice is outputted in the onNoticeDeleteRelated event above
*
* @ return boolean hook flag
*/
2015-07-02 22:00:57 +09:00
2022-10-15 16:17:31 +09:00
public function onEndHandleFeedEntry ( $activity ) : bool {
2015-06-19 03:55:46 +09:00
2022-10-15 15:56:19 +09:00
if ( $activity -> verb == 'qvitter-delete-notice' && class_exists ( 'GNUsocial' ) && ! array_key_exists ( 'ActivityModeration' , GNUsocial :: getActiveModules ())) {
2015-06-19 03:55:46 +09:00
$deleter_profile_uri = $activity -> actor -> id ;
$deleted_notice_uri = $activity -> objects [ 0 ] -> objects [ 0 ] -> content ;
$deleted_notice_uri = substr ( $deleted_notice_uri , strpos ( $deleted_notice_uri , '{{' ) + 2 );
$deleted_notice_uri = substr ( $deleted_notice_uri , 0 , strpos ( $deleted_notice_uri , '}}' ));
$deleter_ostatus_profile = Ostatus_profile :: getKV ( 'uri' , $deleter_profile_uri );
if ( ! $deleter_ostatus_profile instanceof Ostatus_profile ) {
return true ;
}
$deleter_profile = Profile :: getKV ( 'id' , $deleter_ostatus_profile -> profile_id );
$deleted_notice = Notice :: getKV ( 'uri' , $deleted_notice_uri );
2015-07-02 22:00:57 +09:00
2015-06-19 03:55:46 +09:00
if ( ! ( $deleter_profile instanceof Profile ) || ! ( $deleted_notice instanceof Notice )) {
return true ;
2015-07-02 22:00:57 +09:00
}
2015-06-19 03:55:46 +09:00
if ( $deleter_profile -> id != $deleted_notice -> profile_id ) {
2015-07-02 22:00:57 +09:00
return true ;
}
2015-06-19 03:55:46 +09:00
$deleted_notice -> delete ();
2015-07-02 22:00:57 +09:00
}
2015-09-13 08:59:02 +09:00
return true ;
}
2015-06-19 03:55:46 +09:00
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
/**
* Add notification on subscription , remove on unsubscribe
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
public function onEndSubscribe ( $subscriber , $other ) : bool
2014-09-25 06:20:35 +09:00
{
if ( Subscription :: exists ( $subscriber , $other )) {
2015-07-02 22:00:57 +09:00
$this -> insertNotification ( $other -> id , $subscriber -> id , 'follow' , 1 );
2014-09-25 06:20:35 +09:00
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2022-10-15 16:17:31 +09:00
public function onEndUnsubscribe ( $subscriber , $other ) : bool
2014-09-25 06:20:35 +09:00
{
if ( ! Subscription :: exists ( $subscriber , $other )) {
$notif = new QvitterNotification ();
2015-07-02 22:00:57 +09:00
$notif -> to_profile_id = $other -> id ;
$notif -> from_profile_id = $subscriber -> id ;
2014-09-25 06:20:35 +09:00
$notif -> ntype = 'follow' ;
$notif -> delete ();
}
2015-07-02 22:00:57 +09:00
2014-09-25 06:20:35 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2014-11-28 09:16:34 +09:00
/**
* Replace GNU Social 's default FAQ with Qvitter' s
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
public function onEndLoadDoc ( $title , & $output ) : bool
2014-11-28 09:16:34 +09:00
{
2015-07-02 22:00:57 +09:00
2014-11-28 09:16:34 +09:00
if ( $title == 'faq' ) {
2015-07-02 22:00:57 +09:00
$faq = file_get_contents ( QVITTERDIR . '/doc/en/faq.html' );
$faq = str_replace ( '{instance-name}' , common_config ( 'site' , 'name' ), $faq );
$faq = str_replace ( '{instance-url}' , common_config ( 'site' , 'server' ), $faq );
$faq = str_replace ( '{instance-url-with-protocol}' , common_path ( '' , true ), $faq );
if ( common_logged_in ()) {
2014-11-28 09:16:34 +09:00
$user = common_current_user ();
$faq = str_replace ( '{nickname}' , $user -> nickname , $faq );
}
$output = $faq ;
}
2015-07-02 22:00:57 +09:00
2014-11-28 09:16:34 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2014-11-28 09:16:34 +09:00
/**
* Add menu items to top header in Classic
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
public function onStartPrimaryNav ( $action ) : bool
2014-11-28 09:16:34 +09:00
{
2015-07-02 22:00:57 +09:00
2014-11-28 09:16:34 +09:00
$action -> menuItem ( common_local_url ( 'doc' , array ( 'title' => 'faq' )),
// TRANS: Menu item in primary navigation panel.
_m ( 'MENU' , 'FAQ' ),
// TRANS: Menu item title in primary navigation panel.
_ ( 'Frequently asked questions' ),
false ,
'top_nav_doc_faq' );
2015-07-02 22:00:57 +09:00
2014-11-28 09:16:34 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2015-02-04 22:44:04 +09:00
/**
* No registration for blocked ips
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
public function onStartUserRegister ( $profile ) : bool
2015-02-04 22:44:04 +09:00
{
2015-07-02 22:00:57 +09:00
2015-02-04 22:44:04 +09:00
if ( is_array ( self :: settings ( " blocked_ips " ))) {
if ( in_array ( $_SERVER [ 'REMOTE_ADDR' ], self :: settings ( " blocked_ips " ))) {
return false ;
}
2015-07-02 22:00:57 +09:00
}
2015-02-04 22:44:04 +09:00
return true ;
2015-07-02 22:00:57 +09:00
}
2015-08-26 06:27:08 +09:00
/**
* Correct group mentions
*
* We get the correct group ids in a $_POST var called " post_to_groups " , formatted as a string with ids separated by colon , e . g . 4 : 5
*
* @ return boolean hook flag
*/
2022-10-15 16:17:31 +09:00
public function onEndFindMentions ( $sender , $text , & $mentions ) : bool {
2015-08-26 06:27:08 +09:00
// get the correct group profiles
if ( isset ( $_POST [ 'post_to_groups' ])) {
$correct_group_mentions = explode ( ':' , $_POST [ 'post_to_groups' ]);
foreach ( $correct_group_mentions as $group_id ) {
2015-08-26 08:40:29 +09:00
$correct_groups [] = User_group :: getKV ( 'id' , $group_id );
2015-08-26 06:27:08 +09:00
}
// loop through the groups guessed by gnu social's common_find_mentions() and correct them
foreach ( $mentions as $mention_array_id => $mention ) {
2015-08-26 08:40:29 +09:00
foreach ( $correct_groups as $correct_groups_array_id => $correct_group ) {
2016-01-08 00:39:46 +09:00
if ( isset ( $mention [ 'mentioned' ][ 0 ] -> nickname )
&& isset ( $correct_group -> nickname )
&& $mention [ 'mentioned' ][ 0 ] -> nickname == $correct_group -> nickname
2015-08-26 06:27:08 +09:00
&& ! isset ( $mentions [ $mention_array_id ][ 'corrected' ])) {
2015-08-26 08:40:29 +09:00
$user_group_profile = Profile :: getKV ( 'id' , $correct_group -> profile_id );
$mentions [ $mention_array_id ][ 'mentioned' ][ 0 ] = $user_group_profile ;
$mentions [ $mention_array_id ][ 'url' ] = $correct_group -> permalink ();
$mentions [ $mention_array_id ][ 'title' ] = $correct_group -> getFancyName ();
2015-08-26 06:27:08 +09:00
$mentions [ $mention_array_id ][ 'corrected' ] = true ;
// now we've used this
2015-08-26 08:40:29 +09:00
unset ( $correct_groups [ $correct_groups_array_id ]);
2015-08-26 06:27:08 +09:00
}
}
}
}
return true ;
}
2015-07-02 22:00:57 +09:00
2015-01-27 01:13:34 +09:00
/**
2015-06-03 06:45:46 +09:00
* Add unread notification count to all API responses , when logged in
2015-01-27 01:13:34 +09:00
*
* @ return boolean hook flag
2015-07-02 22:00:57 +09:00
*/
2022-10-15 16:17:31 +09:00
public function onEndSetApiUser ( $user ) : bool {
2015-09-13 08:59:02 +09:00
// cleanup sessions, to allow for simultaneous http-requests,
// e.g. if posting a notice takes a very long time
Session :: cleanup ();
2015-02-13 09:02:03 +09:00
if ( ! $user instanceof User ) {
return true ;
}
2015-01-27 01:13:34 +09:00
$user_id = $user -> id ;
2016-02-27 07:18:02 +09:00
$profile = $user -> getProfile ();
2015-01-27 01:13:34 +09:00
$notification = new QvitterNotification ();
$notification -> selectAdd ();
$notification -> selectAdd ( 'ntype' );
2015-07-02 22:00:57 +09:00
$notification -> selectAdd ( 'count(id) as count' );
2015-01-27 01:13:34 +09:00
$notification -> whereAdd ( " (to_profile_id = ' " . $user_id . " ') " );
2015-11-18 06:48:28 +09:00
2016-02-27 07:18:02 +09:00
// if the user only want notifications from users they follow
$only_show_notifications_from_users_i_follow = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'only_show_notifications_from_users_i_follow' );
if ( $only_show_notifications_from_users_i_follow == '1' ) {
$notification -> whereAdd ( sprintf ( 'qvitternotification.from_profile_id IN (SELECT subscribed FROM subscription WHERE subscriber = %u)' , $user_id ));
}
2016-03-05 07:07:15 +09:00
// the user might have opted out from notifications from profiles they have muted
$hide_notifications_from_muted_users = Profile_prefs :: getConfigData ( $profile , 'qvitter' , 'hide_notifications_from_muted_users' );
if ( $hide_notifications_from_muted_users == '1' ) {
$muted_ids = QvitterMuted :: getMutedIDs ( $profile -> id , 0 , 10000 ); // get all (hopefully not more than 10 000...)
if ( $muted_ids !== false && count ( $muted_ids ) > 0 ) {
$ids_imploded = implode ( ',' , $muted_ids );
$notification -> whereAdd ( 'qvitternotification.from_profile_id NOT IN (' . $ids_imploded . ')' );
}
}
2015-11-18 06:48:28 +09:00
// the user might have opted out from certain notification types
$current_profile = $user -> getProfile ();
$disable_notify_replies_and_mentions = Profile_prefs :: getConfigData ( $current_profile , 'qvitter' , 'disable_notify_replies_and_mentions' );
$disable_notify_favs = Profile_prefs :: getConfigData ( $current_profile , 'qvitter' , 'disable_notify_favs' );
$disable_notify_repeats = Profile_prefs :: getConfigData ( $current_profile , 'qvitter' , 'disable_notify_repeats' );
$disable_notify_follows = Profile_prefs :: getConfigData ( $current_profile , 'qvitter' , 'disable_notify_follows' );
if ( $disable_notify_replies_and_mentions == '1' ) {
$notification -> whereAdd ( 'qvitternotification.ntype != "mention"' );
$notification -> whereAdd ( 'qvitternotification.ntype != "reply"' );
}
if ( $disable_notify_favs == '1' ) {
$notification -> whereAdd ( 'qvitternotification.ntype != "like"' );
}
if ( $disable_notify_repeats == '1' ) {
$notification -> whereAdd ( 'qvitternotification.ntype != "repeat"' );
}
if ( $disable_notify_follows == '1' ) {
$notification -> whereAdd ( 'qvitternotification.ntype != "follow"' );
}
2015-07-02 22:00:57 +09:00
$notification -> groupBy ( 'ntype' );
2015-01-27 01:13:34 +09:00
$notification -> whereAdd ( " (is_seen = '0') " );
2015-07-02 22:00:57 +09:00
$notification -> whereAdd ( " (notice_id IS NOT NULL) " ); // sometimes notice_id is NULL, those notifications are corrupt and should be discarded
2015-01-27 01:13:34 +09:00
$notification -> find ();
2015-07-02 22:00:57 +09:00
2015-01-28 09:19:36 +09:00
$new_notifications = array ();
2015-01-27 01:13:34 +09:00
while ( $notification -> fetch ()) {
$new_notifications [ $notification -> ntype ] = $notification -> count ;
}
2015-07-02 22:00:57 +09:00
header ( 'Qvitter-Notifications: ' . json_encode ( $new_notifications ));
2015-01-27 01:13:34 +09:00
return true ;
}
2015-07-02 22:00:57 +09:00
2022-10-15 16:17:31 +09:00
function onPluginVersion ( array & $versions ) : bool
2014-11-24 21:47:45 +09:00
{
$versions [] = array ( 'name' => 'Qvitter' ,
2015-06-07 17:57:25 +09:00
'version' => '5-alpha' ,
2014-11-24 21:47:45 +09:00
'author' => 'Hannes Mannerheim' ,
2016-01-16 09:21:17 +09:00
'homepage' => 'https://git.gnu.io/h2p/Qvitter' ,
2014-11-24 21:47:45 +09:00
'rawdescription' => _m ( 'User interface' ));
return true ;
}
2015-11-20 02:32:46 +09:00
function qvitterTwitterUserArray ( $profile )
2015-06-03 06:45:46 +09:00
{
$twitter_user = array ();
try {
$user = $profile -> getUser ();
} catch ( NoSuchUserException $e ) {
$user = null ;
}
$twitter_user [ 'id' ] = intval ( $profile -> id );
$twitter_user [ 'name' ] = $profile -> getBestName ();
$twitter_user [ 'screen_name' ] = $profile -> nickname ;
$twitter_user [ 'location' ] = ( $profile -> location ) ? $profile -> location : null ;
$twitter_user [ 'description' ] = ( $profile -> bio ) ? $profile -> bio : null ;
// TODO: avatar url template (example.com/user/avatar?size={x}x{y})
$twitter_user [ 'profile_image_url' ] = Avatar :: urlByProfile ( $profile , AVATAR_STREAM_SIZE );
$twitter_user [ 'profile_image_url_https' ] = $twitter_user [ 'profile_image_url' ];
// START introduced by qvitter API, not necessary for StatusNet API
$twitter_user [ 'profile_image_url_profile_size' ] = Avatar :: urlByProfile ( $profile , AVATAR_PROFILE_SIZE );
try {
$avatar = Avatar :: getUploaded ( $profile );
$origurl = $avatar -> displayUrl ();
} catch ( Exception $e ) {
2016-01-12 12:27:04 +09:00
// ugly fix if avatar is missing in the db but exists on the server
2016-01-12 12:53:24 +09:00
$largest_avatar = array ( 'name' => false , 'size' => 0 );
2016-01-12 13:06:16 +09:00
foreach ( glob ( 'avatar/' . $profile -> id . '-*' ) as $filename ) {
2016-01-12 12:53:24 +09:00
$size = filesize ( $filename );
if ( $size > $largest_avatar [ 'size' ]) {
$largest_avatar [ 'size' ] = $size ;
$largest_avatar [ 'name' ] = $filename ;
}
}
if ( $largest_avatar [ 'size' ] > 0 ) {
2022-10-15 15:56:19 +09:00
$origurl = common_path ( '' , GNUsocial :: isHTTPS ()) . $largest_avatar [ 'name' ];
2016-01-12 12:27:04 +09:00
} else {
$origurl = $twitter_user [ 'profile_image_url_profile_size' ];
}
2016-01-12 12:53:24 +09:00
2015-06-03 06:45:46 +09:00
}
$twitter_user [ 'profile_image_url_original' ] = $origurl ;
$twitter_user [ 'groups_count' ] = $profile -> getGroupCount ();
foreach ( array ( 'linkcolor' , 'backgroundcolor' ) as $key ) {
$twitter_user [ $key ] = Profile_prefs :: getConfigData ( $profile , 'theme' , $key );
}
// END introduced by qvitter API, not necessary for StatusNet API
$twitter_user [ 'url' ] = ( $profile -> homepage ) ? $profile -> homepage : null ;
$twitter_user [ 'protected' ] = ( ! empty ( $user ) && $user -> private_stream ) ? true : false ;
$twitter_user [ 'followers_count' ] = $profile -> subscriberCount ();
// Note: some profiles don't have an associated user
$twitter_user [ 'friends_count' ] = $profile -> subscriptionCount ();
$twitter_user [ 'created_at' ] = ApiAction :: dateTwitter ( $profile -> created );
$timezone = 'UTC' ;
if ( ! empty ( $user ) && $user -> timezone ) {
$timezone = $user -> timezone ;
}
$t = new DateTime ;
$t -> setTimezone ( new DateTimeZone ( $timezone ));
$twitter_user [ 'utc_offset' ] = $t -> format ( 'Z' );
$twitter_user [ 'time_zone' ] = $timezone ;
$twitter_user [ 'statuses_count' ] = $profile -> noticeCount ();
// Is the requesting user following this user?
$twitter_user [ 'following' ] = false ;
$twitter_user [ 'statusnet_blocking' ] = false ;
2015-07-02 22:00:57 +09:00
2015-11-20 05:34:51 +09:00
$logged_in_profile = null ;
2015-06-03 06:45:46 +09:00
2015-11-20 02:32:46 +09:00
if ( common_logged_in ()) {
2015-06-03 06:45:46 +09:00
2015-11-20 02:32:46 +09:00
$logged_in_profile = Profile :: current ();
2015-06-03 06:45:46 +09:00
2015-11-20 02:32:46 +09:00
$twitter_user [ 'following' ] = $logged_in_profile -> isSubscribed ( $profile );
$twitter_user [ 'statusnet_blocking' ] = $logged_in_profile -> hasBlocked ( $profile );
2015-06-03 06:45:46 +09:00
}
// StatusNet-specific
$twitter_user [ 'statusnet_profile_url' ] = $profile -> profileurl ;
Event :: handle ( 'TwitterUserArray' , array ( $profile , & $twitter_user , $logged_in_profile , array ()));
return $twitter_user ;
}
2014-11-24 21:47:45 +09:00
2014-05-14 16:46:07 +09:00
}
2014-09-10 03:48:44 +09:00
2014-05-14 16:46:07 +09:00
/**
* Overwrites variables in URL - mapping
*
*/
class URLMapperOverwrite extends URLMapper
{
2015-06-13 00:16:04 +09:00
static function overwrite_variable ( $m , $path , $args , $paramPatterns , $newaction )
2014-05-14 16:46:07 +09:00
{
2015-07-02 22:00:57 +09:00
$m -> connect ( $path , array ( 'action' => $newaction ), $paramPatterns );
2015-06-13 00:16:04 +09:00
$regex = self :: makeRegex ( $path , $paramPatterns );
2015-07-02 22:00:57 +09:00
2014-05-14 16:46:07 +09:00
foreach ( $m -> variables as $n => $v )
2015-07-02 22:00:57 +09:00
if ( $v [ 1 ] == $regex )
2014-05-14 16:46:07 +09:00
$m -> variables [ $n ][ 0 ][ 'action' ] = $newaction ;
}
}