\\\\_\ ·
· \\) \____) ·
· ·
· ·
· ·
· 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
Etc etc...
'; // $settings['customwelcometext']['en'] = 'Etc etc...
'; // TIME BETWEEN POLLING $settings['timebetweenpolling'] = 5000; // ms // URL SHORTENER $settings['urlshortenerapiurl'] = 'http://qttr.at/yourls-api.php'; $settings['urlshortenersignature'] = 'b6afeec983'; // CUSTOM TERMS OF USE $settings['customtermsofuse'] = false; // IP ADDRESSES BLOCKED FROM REGISTRATION $settings['blocked_ips'] = array(); // LINKIFY DOMAINS WITHOUT PROTOCOL AS DEFAULT $settings['linkify_bare_domains'] = true; /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · (o> >o) · · \\\\_\ /_//// . · \____) (____/ · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ // config.php settings override the settings in this file $configphpsettings = common_config('site','qvitter') ?: array(); foreach($configphpsettings as $configphpsetting=>$value) { $settings[$configphpsetting] = $value; } // set linkify setting common_config_set('linkify', 'bare_domains', $settings['linkify_bare_domains']); if(isset($settings[$setting])) { return $settings[$setting]; } else { return false; } } public function initialize() { // show qvitter link in the admin panel common_config_append('admin', 'panels', 'qvitteradm'); } function onCheckSchema() { $schema = Schema::get(); // make sure we have a notifications table $schema->ensureTable('qvitternotification', QvitterNotification::schemaDef()); // 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()); } } return true; } // route/reroute urls public function onRouterInitialized($m) { $m->connect('services/oembed.:format', array('action' => 'apiqvitteroembednotice', 'format' => '(xml|json)')); $m->connect('api/qvitter/check_email.json', array('action' => 'ApiQvitterCheckEmail')); $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]+')); $m->connect('api/qvitter/blocks.json', array('action' => 'ApiQvitterBlocks')); $m->connect('api/qvitter/hello.json', array('action' => 'ApiQvitterHello')); $m->connect('api/qvitter/mark_all_notifications_as_seen.json', array('action' => 'ApiQvitterMarkAllNotificationsAsSeen')); $m->connect('api/qvitter/favs_and_repeats/:notice_id.json', array('action' => 'ApiFavsAndRepeats'), array('notice_id' => '[0-9]+')); $m->connect('api/statuses/public_and_external_timeline.:format', array('action' => 'ApiTimelinePublicAndExternal', 'format' => '(xml|json|rss|atom|as)')); $m->connect('api/qvitter/update_bookmarks.json', array('action' => 'ApiQvitterUpdateBookmarks')); $m->connect('api/qvitter/set_profile_pref.json', array('action' => 'ApiQvitterSetProfilePref')); $m->connect('api/qvitter/update_link_color.json', array('action' => 'apiqvitterupdatelinkcolor')); $m->connect('api/qvitter/update_background_color.json', array('action' => 'apiqvitterupdatebackgroundcolor')); $m->connect('api/qvitter/checklogin.json', array('action' => 'apiqvitterchecklogin')); $m->connect('api/qvitter/allfollowing/:id.json', array('action' => 'apiqvitterallfollowing', 'id' => Nickname::INPUT_FMT)); $m->connect('api/qvitter/update_cover_photo.json', array('action' => 'ApiUpdateCoverPhoto')); $m->connect('api/qvitter/update_background_image.json', array('action' => 'ApiUpdateBackgroundImage')); $m->connect('api/qvitter/update_avatar.json', array('action' => 'ApiUpdateAvatar')); $m->connect('api/qvitter/upload_image.json', array('action' => 'ApiUploadImage')); $m->connect('api/qvitter/external_user_show.json', array('action' => 'ApiExternalUserShow')); $m->connect('api/qvitter/toggle_qvitter.json', array('action' => 'ApiToggleQvitter')); $m->connect('api/qvitter/statuses/notifications.json', array('action' => 'apiqvitternotifications')); $m->connect(':nickname/notifications', array('action' => 'qvitter', 'nickname' => Nickname::INPUT_FMT)); $m->connect('settings/qvitter', array('action' => 'qvittersettings')); $m->connect('panel/qvitter', array('action' => 'qvitteradminsettings')); $m->connect('main/qlogin', array('action' => 'qvitterlogin')); $m->connect('api/qvitter/statuses/update.:format', array('action' => 'ApiQvitterStatusesUpdate'), array('format' => '(xml|json)')); // 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; } if ($this->hijack_ui === true) { // other plugins might want to reroute to qvitter Event::handle('QvitterHijackUI', array($m)); $m->connect('', array('action' => 'qvitter')); $m->connect('main/all', array('action' => 'qvitter')); $m->connect('main/public', array('action' => 'qvitter')); $m->connect('search/notice', array('action' => 'qvitter')); // if the user wants the twitter style home stream with hidden replies to non-friends if ($this->qvitter_hide_replies == 1) { URLMapperOverwrite::overwrite_variable($m, 'api/statuses/friends_timeline.:format', array('action' => 'ApiTimelineFriends'), array('format' => '(xml|json|rss|atom|as)'), 'ApiTimelineFriendsHiddenReplies'); } URLMapperOverwrite::overwrite_variable($m, ':nickname', array('action' => 'showstream'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/', array('action' => 'showstream'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/all', array('action' => 'all'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/subscriptions', array('action' => 'subscriptions'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/subscribers', array('action' => 'subscribers'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/groups', array('action' => 'usergroups'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/replies', array('action' => 'replies'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/favorites', array('action' => 'showfavorites'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'group/:nickname', array('action' => 'showgroup'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'group/:nickname/members', array('action' => 'groupmembers'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); 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'); $m->connect('group/:nickname/admins', array('action' => 'qvitter'), array('nickname' => Nickname::DISPLAY_FMT)); URLMapperOverwrite::overwrite_variable($m, 'tag/:tag', array('action' => 'showstream'), array('tag' => Router::REGEX_TAG), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'notice/:notice', array('action' => 'shownotice'), array('notice' => '[0-9]+'), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'conversation/:id', array('action' => 'conversation'), array('id' => '[0-9]+'), 'qvitter'); } // if qvitter is opt-out, disable the default register page (if we don't have a valid invitation code) $valid_code = isset($_POST['code']) ? Invitation::getKV('code', $_POST['code']) : null; if(self::settings('enabledbydefault') && empty($valid_code)) { $m->connect('main/register', array('action' => 'qvitter')); } // 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 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': // add logged in user's user array if (common_logged_in() && !isset($_GET['screen_name']) && !isset($_GET['id'])) { $profilecurrent = Profile::current(); header('Qvitter-User-Array: '.json_encode($this->qvitterTwitterUserArray($profilecurrent))); } // add screen_name's user array elseif(isset($_GET['screen_name']) || isset($_GET['id'])){ if(isset($_GET['screen_name'])) { $user = User::getKV('nickname', $_GET['screen_name']); } elseif(isset($_GET['id'])) { $user = User::getKV('id', $_GET['id']); } if($user instanceof User) { header('Qvitter-User-Array: '.json_encode($this->qvitterTwitterUserArray($user->getProfile()))); } } break; } } /** * Add script to default ui, to be able to toggle Qvitter with one click * * @return boolean hook return */ function onEndShowScripts($action){ if (common_logged_in()) { $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'; } } $action->inlineScript(' var toggleQvitterAPIURL = \''.common_path('', true).'api/qvitter/toggle_qvitter.json\'; var toggleText = \''._('New').' '.str_replace("'","\'",common_config('site','name')).'\'; var qvitterEnabled = '.$qvitter_enabled.'; var qvitterAllLink = \''.common_local_url('all', array('nickname' => $user->nickname)).'\'; '); $action->script($this->path('js/toggleqvitter.js').'?changed='.date('YmdHis',filemtime(QVITTERDIR.'/js/toggleqvitter.js'))); } } /** * Menu item for Qvitter * * @param Action $action action being executed * * @return boolean hook return */ function onEndAccountSettingsNav($action) { $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. _m('Qvitter Settings'), $action_name === 'qvittersettings'); return true; } /** * Menu item for admin panel * * @param Action $action action being executed * * @return boolean hook return */ function onEndAdminPanelNav($action) { $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; } /** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach($notice_groups as $g) { $group_addressees[] = array('nickname'=>$g->nickname,'url'=>$g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // 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; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if(is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // Oembed if(array_key_exists('Oembed', StatusNet::getActivePlugins())) { $oembed = File_oembed::getKV('file_id',$attachment->id); if($oembed instanceof File_oembed) { $oembed_html = str_replace('<!--//-->','',$oembed->html); // trash left of wordpress' javascript after htmLawed removed the tags if($oembed->provider == 'Twitter' && strstr($oembed_html, '