summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Diekershoff <tobias.diekershoff@gmx.net>2009-04-10 14:25:25 +0200
committerTobias Diekershoff <tobias.diekershoff@gmx.net>2009-04-10 14:25:25 +0200
commit4277a6818c6ac66158dfba3b94bdc1b2eb06b594 (patch)
tree99149b95d0bd0bfaac4b2ad3d646e8cc1da7f51a /lib
parentd1bf8b2143f597d9d1b1e7ff472532c596200011 (diff)
parent6cdc2ff444b8c76a3cdc5b8c6e9e7e7539d9b6cc (diff)
Merge branch '0.7.x' of git://gitorious.org/laconica/dev into 0.7.x
Diffstat (limited to 'lib')
-rw-r--r--lib/action.php39
-rw-r--r--lib/common.php7
-rw-r--r--lib/featureduserssection.php9
-rw-r--r--lib/galleryaction.php7
-rw-r--r--lib/groupminilist.php7
-rw-r--r--lib/mailbox.php3
-rw-r--r--lib/noticelist.php9
-rw-r--r--lib/openid.php4
-rw-r--r--lib/profileaction.php242
-rw-r--r--lib/profileminilist.php2
-rw-r--r--lib/router.php3
-rw-r--r--lib/searchaction.php26
-rw-r--r--lib/settingsaction.php4
-rw-r--r--lib/twitter.php221
-rw-r--r--lib/util.php72
15 files changed, 571 insertions, 84 deletions
diff --git a/lib/action.php b/lib/action.php
index f0baa062c..cc98d4445 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -97,9 +97,18 @@ class Action extends HTMLOutputter // lawsuit
$this->startHTML();
Event::handle('EndShowHTML', array($this));
}
+ if (Event::handle('StartShowHead', array($this))) {
$this->showHead();
+ Event::handle('EndShowHead', array($this));
+ }
+ if (Event::handle('StartShowBody', array($this))) {
$this->showBody();
+ Event::handle('EndShowBody', array($this));
+ }
+ if (Event::handle('StartEndHTML', array($this))) {
$this->endHTML();
+ Event::handle('EndEndHTML', array($this));
+ }
}
/**
@@ -326,7 +335,9 @@ class Action extends HTMLOutputter // lawsuit
*/
function showBody()
{
- $this->elementStart('body', array('id' => $this->trimmed('action')));
+ $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'),
+ 'class' => 'user_in')
+ : array('id' => $this->trimmed('action')));
$this->elementStart('div', array('id' => 'wrap'));
if (Event::handle('StartShowHeader', array($this))) {
$this->showHeader();
@@ -400,13 +411,8 @@ class Action extends HTMLOutputter // lawsuit
if ($user) {
$this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
_('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
- }
- $this->menuItem(common_local_url('peoplesearch'),
- _('Search'), _('Search for people or text'), false, 'nav_search');
- if ($user) {
$this->menuItem(common_local_url('profilesettings'),
_('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
-
if (common_config('xmpp', 'enabled')) {
$this->menuItem(common_local_url('imsettings'),
_('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
@@ -414,20 +420,28 @@ class Action extends HTMLOutputter // lawsuit
$this->menuItem(common_local_url('smssettings'),
_('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
}
+ $this->menuItem(common_local_url('invite'),
+ _('Invite'),
+ sprintf(_('Invite friends and colleagues to join you on %s'),
+ common_config('site', 'name')),
+ false, 'nav_invitecontact');
$this->menuItem(common_local_url('logout'),
_('Logout'), _('Logout from the site'), false, 'nav_logout');
- } else {
- $this->menuItem(common_local_url('login'),
- _('Login'), _('Login to the site'), false, 'nav_login');
+ }
+ else {
if (!common_config('site', 'closed')) {
$this->menuItem(common_local_url('register'),
_('Register'), _('Create an account'), false, 'nav_register');
}
$this->menuItem(common_local_url('openidlogin'),
_('OpenID'), _('Login with OpenID'), false, 'nav_openid');
+ $this->menuItem(common_local_url('login'),
+ _('Login'), _('Login to the site'), false, 'nav_login');
}
$this->menuItem(common_local_url('doc', array('title' => 'help')),
_('Help'), _('Help me!'), false, 'nav_help');
+ $this->menuItem(common_local_url('peoplesearch'),
+ _('Search'), _('Search for people or text'), false, 'nav_search');
Event::handle('EndPrimaryNav', array($this));
}
$this->elementEnd('ul');
@@ -604,7 +618,10 @@ class Action extends HTMLOutputter // lawsuit
{
$this->elementStart('div', array('id' => 'aside_primary',
'class' => 'aside'));
+ if (Event::handle('StartShowExportData', array($this))) {
$this->showExportData();
+ Event::handle('EndShowExportData', array($this));
+ }
if (Event::handle('StartShowSections', array($this))) {
$this->showSections();
Event::handle('EndShowSections', array($this));
@@ -919,11 +936,15 @@ class Action extends HTMLOutputter // lawsuit
*
* @return string current URL
*/
+
function selfUrl()
{
$action = $this->trimmed('action');
$args = $this->args;
unset($args['action']);
+ if (array_key_exists('submit', $args)) {
+ unset($args['submit']);
+ }
foreach (array_keys($_COOKIE) as $cookie) {
unset($args[$cookie]);
}
diff --git a/lib/common.php b/lib/common.php
index 1ca9e521b..b3882d207 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
-define('LACONICA_VERSION', '0.7.2.1');
+define('LACONICA_VERSION', '0.7.3');
define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48);
@@ -87,6 +87,8 @@ $config =
'closed' => false,
'inviteonly' => false,
'private' => false,
+ 'ssl' => 'never',
+ 'sslserver' => null,
'dupelimit' => 60), # default for same person saying the same thing
'syslog' =>
array('appname' => 'laconica', # for syslog
@@ -151,6 +153,9 @@ $config =
array('notify' => array()),
'inboxes' =>
array('enabled' => true), # on by default for new sites
+ 'newuser' =>
+ array('subscribe' => null,
+ 'welcome' => null),
);
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
diff --git a/lib/featureduserssection.php b/lib/featureduserssection.php
index aed94b1a5..4b9238d47 100644
--- a/lib/featureduserssection.php
+++ b/lib/featureduserssection.php
@@ -57,9 +57,14 @@ class FeaturedUsersSection extends ProfileSection
$quoted[] = "'$nick'";
}
+ $table = "user";
+ if(common_config('db','quote_identifiers')) {
+ $table = '"' . $table . '"';
+ }
+
$qry = 'SELECT profile.* ' .
- 'FROM profile JOIN user on profile.id = user.id ' .
- 'WHERE user.nickname in (' . implode(',', $quoted) . ') ' .
+ 'FROM profile JOIN '. $table .' on profile.id = '. $table .'.id ' .
+ 'WHERE '. $table .'.nickname in (' . implode(',', $quoted) . ') ' .
'ORDER BY profile.created DESC ';
$limit = PROFILES_PER_SECTION + 1;
diff --git a/lib/galleryaction.php b/lib/galleryaction.php
index 25a5e3fd5..8e21d7393 100644
--- a/lib/galleryaction.php
+++ b/lib/galleryaction.php
@@ -50,7 +50,7 @@ class GalleryAction extends Action
if ($this->arg('page') && $this->arg('page') != 1) {
$args['page'] = $this->arg['page'];
}
- common_redirect(common_local_url('subscriptions', $args), 301);
+ common_redirect(common_local_url($this->trimmed('action'), $args), 301);
return false;
}
@@ -71,6 +71,7 @@ class GalleryAction extends Action
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
$this->tag = $this->trimmed('tag');
+ $this->q = $this->trimmed('q');
return true;
}
@@ -87,7 +88,7 @@ class GalleryAction extends Action
# Post from the tag dropdown; redirect to a GET
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- common_redirect($this->selfUrl(), 307);
+ common_redirect($this->selfUrl(), 303);
return;
}
@@ -136,7 +137,7 @@ class GalleryAction extends Action
'method' => 'post'));
$this->dropdown('tag', _('Tag'), $content,
_('Choose a tag to narrow list'), false, $tag);
- $this->submit('go', _('Go'));
+ $this->submit('submit', _('Go'));
$this->elementEnd('form');
$this->elementEnd('li');
$this->elementEnd('ul');
diff --git a/lib/groupminilist.php b/lib/groupminilist.php
index fe38d0340..ae2d237f1 100644
--- a/lib/groupminilist.php
+++ b/lib/groupminilist.php
@@ -33,7 +33,7 @@ if (!defined('LACONICA')) {
require_once INSTALLDIR.'/lib/grouplist.php';
-define('GROUPS_PER_MINILIST', 80);
+define('GROUPS_PER_MINILIST', 27);
/**
* Widget to show a list of groups, good for sidebar
@@ -75,8 +75,9 @@ class GroupMiniList extends GroupList
'href' => $this->group->homeUrl(),
'rel' => 'contact group',
'class' => 'url'));
- $logo = ($this->group->stream_logo) ?
- $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
+
+ $logo = ($this->group->mini_logo) ?
+ $this->group->mini_logo : User_group::defaultLogo(AVATAR_MINI_SIZE);
$this->out->element('img', array('src' => $logo,
'width' => AVATAR_MINI_SIZE,
diff --git a/lib/mailbox.php b/lib/mailbox.php
index d77234549..01bbf5721 100644
--- a/lib/mailbox.php
+++ b/lib/mailbox.php
@@ -137,6 +137,9 @@ class MailboxAction extends PersonalAction
$message->free();
unset($message);
}
+ else {
+ $this->element('p', 'guide', _('You have no private messages. You can send private message to engage other users in conversation. People can send you messages for your eyes only.'));
+ }
}
function getMessages()
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 9fc0126b3..4182d8808 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -258,8 +258,12 @@ class NoticeListItem extends Widget
function showAuthor()
{
$this->out->elementStart('span', 'vcard author');
- $this->out->elementStart('a', array('href' => $this->profile->profileurl,
- 'class' => 'url'));
+ $attrs = array('href' => $this->profile->profileurl,
+ 'class' => 'url');
+ if (!empty($this->profile->fullname)) {
+ $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ') ';
+ }
+ $this->out->elementStart('a', $attrs);
$this->showAvatar();
$this->showNickname();
$this->out->elementEnd('a');
@@ -387,6 +391,7 @@ class NoticeListItem extends Widget
case 'xmpp':
case 'mail':
case 'omb':
+ case 'system':
case 'api':
$this->out->element('dd', null, $source_name);
break;
diff --git a/lib/openid.php b/lib/openid.php
index 3aa488b6d..3af7a39cf 100644
--- a/lib/openid.php
+++ b/lib/openid.php
@@ -160,7 +160,7 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
$auth_request->addExtension($sreg_request);
}
- $trust_root = common_path('');
+ $trust_root = common_root_url(true);
$process_url = common_local_url($returnto);
if ($auth_request->shouldSendRedirect()) {
@@ -171,7 +171,7 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
} else if (Auth_OpenID::isFailure($redirect_url)) {
return sprintf(_('Could not redirect to server: %s'), $redirect_url->message);
} else {
- common_redirect($redirect_url);
+ common_redirect($redirect_url, 303);
}
} else {
// Generate form markup and render it.
diff --git a/lib/profileaction.php b/lib/profileaction.php
new file mode 100644
index 000000000..c81924e31
--- /dev/null
+++ b/lib/profileaction.php
@@ -0,0 +1,242 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Common parent of Personal and Profile actions
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Personal
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Sarven Capadisli <csarven@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/profileminilist.php';
+require_once INSTALLDIR.'/lib/groupminilist.php';
+
+/**
+ * Profile action common superclass
+ *
+ * Abstracts out common code from profile and personal tabs
+ *
+ * @category Personal
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+class ProfileAction extends Action
+{
+ var $user = null;
+ var $page = null;
+ var $profile = null;
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $nickname_arg = $this->arg('nickname');
+ $nickname = common_canonical_nickname($nickname_arg);
+
+ // Permanent redirect on non-canonical nickname
+
+ if ($nickname_arg != $nickname) {
+ $args = array('nickname' => $nickname);
+ if ($this->arg('page') && $this->arg('page') != 1) {
+ $args['page'] = $this->arg['page'];
+ }
+ common_redirect(common_local_url($this->trimmed('action'), $args), 301);
+ return false;
+ }
+
+ $this->user = User::staticGet('nickname', $nickname);
+
+ if (!$this->user) {
+ $this->clientError(_('No such user.'), 404);
+ return false;
+ }
+
+ $this->profile = $this->user->getProfile();
+
+ if (!$this->profile) {
+ $this->serverError(_('User has no profile.'));
+ return false;
+ }
+
+ $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+
+ common_set_returnto($this->selfUrl());
+
+ return true;
+ }
+
+ function showSections()
+ {
+ $this->showSubscriptions();
+ $this->showSubscribers();
+ $this->showGroups();
+ $this->showStatistics();
+ }
+
+ function showSubscriptions()
+ {
+ $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
+
+ $this->elementStart('div', array('id' => 'entity_subscriptions',
+ 'class' => 'section'));
+
+ $this->element('h2', null, _('Subscriptions'));
+
+ if ($profile) {
+ $pml = new ProfileMiniList($profile, $this->user, $this);
+ $cnt = $pml->show();
+ if ($cnt == 0) {
+ $this->element('p', null, _('(None)'));
+ }
+ }
+
+ if ($cnt > PROFILES_PER_MINILIST) {
+ $this->elementStart('p');
+ $this->element('a', array('href' => common_local_url('subscriptions',
+ array('nickname' => $this->profile->nickname)),
+ 'class' => 'more'),
+ _('All subscriptions'));
+ $this->elementEnd('p');
+ }
+
+ $this->elementEnd('div');
+ }
+
+ function showSubscribers()
+ {
+ $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
+
+ $this->elementStart('div', array('id' => 'entity_subscribers',
+ 'class' => 'section'));
+
+ $this->element('h2', null, _('Subscribers'));
+
+ if ($profile) {
+ $pml = new ProfileMiniList($profile, $this->user, $this);
+ $cnt = $pml->show();
+ if ($cnt == 0) {
+ $this->element('p', null, _('(None)'));
+ }
+ }
+
+ if ($cnt > PROFILES_PER_MINILIST) {
+ $this->elementStart('p');
+ $this->element('a', array('href' => common_local_url('subscribers',
+ array('nickname' => $this->profile->nickname)),
+ 'class' => 'more'),
+ _('All subscribers'));
+ $this->elementEnd('p');
+ }
+
+ $this->elementEnd('div');
+ }
+
+ function showStatistics()
+ {
+ // XXX: WORM cache this
+ $subs = new Subscription();
+ $subs->subscriber = $this->profile->id;
+ $subs_count = (int) $subs->count() - 1;
+
+ $subbed = new Subscription();
+ $subbed->subscribed = $this->profile->id;
+ $subbed_count = (int) $subbed->count() - 1;
+
+ $notices = new Notice();
+ $notices->profile_id = $this->profile->id;
+ $notice_count = (int) $notices->count();
+
+ $this->elementStart('div', array('id' => 'entity_statistics',
+ 'class' => 'section'));
+
+ $this->element('h2', null, _('Statistics'));
+
+ // Other stats...?
+ $this->elementStart('dl', 'entity_member-since');
+ $this->element('dt', null, _('Member since'));
+ $this->element('dd', null, date('j M Y',
+ strtotime($this->profile->created)));
+ $this->elementEnd('dl');
+
+ $this->elementStart('dl', 'entity_subscriptions');
+ $this->elementStart('dt');
+ $this->element('a', array('href' => common_local_url('subscriptions',
+ array('nickname' => $this->profile->nickname))),
+ _('Subscriptions'));
+ $this->elementEnd('dt');
+ $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
+ $this->elementEnd('dl');
+
+ $this->elementStart('dl', 'entity_subscribers');
+ $this->elementStart('dt');
+ $this->element('a', array('href' => common_local_url('subscribers',
+ array('nickname' => $this->profile->nickname))),
+ _('Subscribers'));
+ $this->elementEnd('dt');
+ $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
+ $this->elementEnd('dl');
+
+ $this->elementStart('dl', 'entity_notices');
+ $this->element('dt', null, _('Notices'));
+ $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
+ $this->elementEnd('dl');
+
+ $this->elementEnd('div');
+ }
+
+ function showGroups()
+ {
+ $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
+
+ $this->elementStart('div', array('id' => 'entity_groups',
+ 'class' => 'section'));
+
+ $this->element('h2', null, _('Groups'));
+
+ if ($groups) {
+ $gml = new GroupMiniList($groups, $this->user, $this);
+ $cnt = $gml->show();
+ if ($cnt == 0) {
+ $this->element('p', null, _('(None)'));
+ }
+ }
+
+ if ($cnt > GROUPS_PER_MINILIST) {
+ $this->elementStart('p');
+ $this->element('a', array('href' => common_local_url('usergroups',
+ array('nickname' => $this->profile->nickname)),
+ 'class' => 'more'),
+ _('All groups'));
+ $this->elementEnd('p');
+ }
+
+ $this->elementEnd('div');
+ }
+} \ No newline at end of file
diff --git a/lib/profileminilist.php b/lib/profileminilist.php
index 0d466bba8..57496d0e9 100644
--- a/lib/profileminilist.php
+++ b/lib/profileminilist.php
@@ -33,7 +33,7 @@ if (!defined('LACONICA')) {
require_once INSTALLDIR.'/lib/profilelist.php';
-define('PROFILES_PER_MINILIST', 80);
+define('PROFILES_PER_MINILIST', 27);
/**
* Widget to show a list of profiles, good for sidebar
diff --git a/lib/router.php b/lib/router.php
index ae5b5e16b..6fb2f9487 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -107,6 +107,9 @@ class Router
$m->connect('main/'.$a, array('action' => $a));
}
+ $m->connect('main/sup/:seconds', array('action' => 'sup'),
+ array('seconds' => '[0-9]+'));
+
$m->connect('main/tagother/:id', array('action' => 'tagother'));
// these take a code
diff --git a/lib/searchaction.php b/lib/searchaction.php
index c762db16f..e7ad4affd 100644
--- a/lib/searchaction.php
+++ b/lib/searchaction.php
@@ -133,5 +133,31 @@ class SearchAction extends Action
$this->showResults($q, $page);
}
}
+
+ function searchSuggestions($q) {
+ $qe = urlencode($q);
+ $message = sprintf(_(<<<E_O_T
+* Make sure all words are spelled correctly.
+* Try different keywords.
+* Try more general keywords.
+* Try fewer keywords.
+
+You can also try your search on other engines:
+
+* [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=identi.ca)
+* [Tweet scan](http://www.tweetscan.com/indexi.php?s=%s)
+* [Google](http://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s)
+* [Yahoo](http://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s)
+
+
+E_O_T
+), $qe, $qe, $qe, $qe);
+ $this->elementStart('dl', array('id' => 'help_search', 'class' => 'help'));
+ $this->element('dt', null, _('Search help'));
+ $this->elementStart('dd', 'instructions');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('dd');
+ $this->elementEnd('div');
+ }
}
diff --git a/lib/settingsaction.php b/lib/settingsaction.php
index 53c807c6f..db20c5804 100644
--- a/lib/settingsaction.php
+++ b/lib/settingsaction.php
@@ -78,9 +78,9 @@ class SettingsAction extends Action
common_set_returnto($this->selfUrl());
$user = common_current_user();
if ($user->hasOpenID()) {
- common_redirect(common_local_url('openidlogin'));
+ common_redirect(common_local_url('openidlogin'), 303);
} else {
- common_redirect(common_local_url('login'));
+ common_redirect(common_local_url('login'), 303);
}
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
diff --git a/lib/twitter.php b/lib/twitter.php
index 7abb40151..ccc6c93ca 100644
--- a/lib/twitter.php
+++ b/lib/twitter.php
@@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
-define("TWITTER_SERVICE", 1); // Twitter is foreign_service ID 1
+define('TWITTER_SERVICE', 1); // Twitter is foreign_service ID 1
function get_twitter_data($uri, $screen_name, $password)
{
@@ -45,6 +45,10 @@ function get_twitter_data($uri, $screen_name, $password)
if ($errmsg) {
common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $screen_name.",
__FILE__);
+
+ if (defined('SCRIPT_DEBUG')) {
+ print "cURL error: $errmsg - trying to load: $uri with user $screen_name.\n";
+ }
}
curl_close($ch);
@@ -52,63 +56,141 @@ function get_twitter_data($uri, $screen_name, $password)
return $data;
}
-function twitter_user_info($screen_name, $password)
+function twitter_json_data($uri, $screen_name, $password)
{
+ $json_data = get_twitter_data($uri, $screen_name, $password);
- $uri = "http://twitter.com/users/show/$screen_name.json";
- $data = get_twitter_data($uri, $screen_name, $password);
-
- if (!$data) {
+ if (!$json_data) {
return false;
}
- $twit_user = json_decode($data);
+ $data = json_decode($json_data);
- if (!$twit_user) {
+ if (!$data) {
return false;
}
- return $twit_user;
+ return $data;
}
-function update_twitter_user($fuser, $twitter_id, $screen_name)
+function twitter_user_info($screen_name, $password)
{
+ $uri = "http://twitter.com/users/show/$screen_name.json";
+ return twitter_json_data($uri, $screen_name, $password);
+}
- $original = clone($fuser);
- $fuser->nickname = $screen_name;
- $fuser->uri = 'http://twitter.com/' . $screen_name;
- $result = $fuser->updateKeys($original);
+function twitter_friends_ids($screen_name, $password)
+{
+ $uri = "http://twitter.com/friends/ids/$screen_name.json";
+ return twitter_json_data($uri, $screen_name, $password);
+}
+
+function update_twitter_user($twitter_id, $screen_name)
+{
+ $uri = 'http://twitter.com/' . $screen_name;
+
+ $fuser = new Foreign_user();
+
+ $fuser->query('BEGIN');
+
+ // Dropping down to SQL because regular db_object udpate stuff doesn't seem
+ // to work so good with tables that have multiple column primary keys
+
+ // Any time we update the uri for a forein user we have to make sure there
+ // are no dupe entries first -- unique constraint on the uri column
+
+ $qry = 'UPDATE foreign_user set uri = \'\' WHERE uri = ';
+ $qry .= '\'' . $uri . '\'' . ' AND service = ' . TWITTER_SERVICE;
+
+ $result = $fuser->query($qry);
+
+ if ($result) {
+ common_debug("Removed uri ($uri) from another foreign_user who was squatting on it.");
+ if (defined('SCRIPT_DEBUG')) {
+ print("Removed uri ($uri) from another Twitter user who was squatting on it.\n");
+ }
+ }
+
+ // Update the user
+ $qry = 'UPDATE foreign_user SET nickname = ';
+ $qry .= '\'' . $screen_name . '\'' . ', uri = \'' . $uri . '\' ';
+ $qry .= 'WHERE id = ' . $twitter_id . ' AND service = ' . TWITTER_SERVICE;
+
+ $result = $fuser->query($qry);
if (!$result) {
+ common_log(LOG_WARNING,
+ "Couldn't update foreign_user data for Twitter user: $screen_name");
common_log_db_error($fuser, 'UPDATE', __FILE__);
+ if (defined('SCRIPT_DEBUG')) {
+ print "UPDATE failed: for Twitter user: $twitter_id - $screen_name. - ";
+ print common_log_objstring($fuser) . "\n";
+ $error = &PEAR::getStaticProperty('DB_DataObject','lastError');
+ print "DB_DataObject Error: " . $error->getMessage() . "\n";
+ }
return false;
}
+ $fuser->query('COMMIT');
+
+ $fuser->free();
+ unset($fuser);
+
return true;
}
function add_twitter_user($twitter_id, $screen_name)
{
+ $new_uri = 'http://twitter.com/' . $screen_name;
+
+ // Clear out any bad old foreign_users with the new user's legit URL
+ // This can happen when users move around or fakester accounts get
+ // repoed, and things like that.
+ $luser = new Foreign_user();
+ $luser->uri = $new_uri;
+ $luser->service = TWITTER_SERVICE;
+ $result = $luser->delete();
+
+ if ($result) {
+ common_log(LOG_WARNING,
+ "Twitter bridge - removed invalid Twitter user squatting on uri: $new_uri");
+ if (defined('SCRIPT_DEBUG')) {
+ print "Removed invalid Twitter user squatting on uri: $new_uri\n";
+ }
+ }
+
+ $luser->free();
+ unset($luser);
+
// Otherwise, create a new Twitter user
- $fuser = DB_DataObject::factory('foreign_user');
+ $fuser = new Foreign_user();
$fuser->nickname = $screen_name;
$fuser->uri = 'http://twitter.com/' . $screen_name;
$fuser->id = $twitter_id;
- $fuser->service = TWITTER_SERVICE; // Twitter
+ $fuser->service = TWITTER_SERVICE;
$fuser->created = common_sql_now();
$result = $fuser->insert();
if (!$result) {
- common_debug("Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
+ common_log(LOG_WARNING,
+ "Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
common_log_db_error($fuser, 'INSERT', __FILE__);
- return false;
+ if (defined('SCRIPT_DEBUG')) {
+ print "INSERT failed: could not add new Twitter user: $twitter_id - $screen_name. - ";
+ print common_log_objstring($fuser) . "\n";
+ $error = &PEAR::getStaticProperty('DB_DataObject','lastError');
+ print "DB_DataObject Error: " . $error->getMessage() . "\n";
+ }
+ } else {
+ common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
+ if (defined('SCRIPT_DEBUG')) {
+ print "Added new Twitter user: $screen_name ($twitter_id).\n";
+ }
}
- common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
-
- return true;
+ return $result;
}
// Creates or Updates a Twitter user
@@ -117,53 +199,87 @@ function save_twitter_user($twitter_id, $screen_name)
// Check to see whether the Twitter user is already in the system,
// and update its screen name and uri if so.
- $fuser = Foreign_user::getForeignUser($twitter_id, 1);
+ $fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
if ($fuser) {
+ $result = true;
+
// Only update if Twitter screen name has changed
if ($fuser->nickname != $screen_name) {
+ $result = update_twitter_user($twitter_id, $screen_name);
common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' .
"$fuser->id to $screen_name, was $fuser->nickname");
- return update_twitter_user($fuser, $twitter_id, $screen_name);
+ if (defined('SCRIPT_DEBUG')) {
+ print 'Updated nickname (and URI) for Twitter user ' .
+ "$fuser->id to $screen_name, was $fuser->nickname\n";
+ }
}
+ return $result;
+
} else {
return add_twitter_user($twitter_id, $screen_name);
}
+ $fuser->free();
+ unset($fuser);
+
return true;
}
function retreive_twitter_friends($twitter_id, $screen_name, $password)
{
+ $friends = array();
$uri = "http://twitter.com/statuses/friends/$twitter_id.json?page=";
- $twitter_user = twitter_user_info($screen_name, $password);
+ $friends_ids = twitter_friends_ids($screen_name, $password);
+
+ if (!$friends_ids) {
+ return $friends;
+ }
+
+ if (defined('SCRIPT_DEBUG')) {
+ print "Twitter 'social graph' ids method says $screen_name has " .
+ count($friends_ids) . " friends.\n";
+ }
// Calculate how many pages to get...
- $pages = ceil($twitter_user->friends_count / 100);
+ $pages = ceil(count($friends_ids) / 100);
if ($pages == 0) {
- common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame.");
+ common_log(LOG_WARNING,
+ "Twitter bridge - $screen_name seems to have no friends.");
+ if (defined('SCRIPT_DEBUG')) {
+ print "$screen_name seems to have no friends.\n";
+ }
}
- $friends = array();
-
for ($i = 1; $i <= $pages; $i++) {
$data = get_twitter_data($uri . $i, $screen_name, $password);
if (!$data) {
- return null;
+ common_log(LOG_WARNING,
+ "Twitter bridge - Couldn't retrieve page $i of $screen_name's friends.");
+ if (defined('SCRIPT_DEBUG')) {
+ print "Couldn't retrieve page $i of $screen_name's friends.\n";
+ }
+ continue;
}
$more_friends = json_decode($data);
if (!$more_friends) {
- return null;
+
+ common_log(LOG_WARNING,
+ "Twitter bridge - No data for page $i of $screen_name's friends.");
+ if (defined('SCRIPT_DEBUG')) {
+ print "No data for page $i of $screen_name's friends.\n";
+ }
+ continue;
}
$friends = array_merge($friends, $more_friends);
@@ -177,19 +293,27 @@ function save_twitter_friends($user, $twitter_id, $screen_name, $password)
$friends = retreive_twitter_friends($twitter_id, $screen_name, $password);
- if (is_null($friends)) {
- common_debug("Twitter bridge - Couldn't get friends data from Twitter.");
+ if (empty($friends)) {
+ common_debug("Twitter bridge - Couldn't get friends data from Twitter for $screen_name.");
+ if (defined('SCRIPT_DEBUG')) {
+ print "Couldn't get friends data from Twitter for $screen_name.\n";
+ }
return false;
}
foreach ($friends as $friend) {
$friend_name = $friend->screen_name;
- $friend_id = $friend->id;
+ $friend_id = (int) $friend->id;
// Update or create the Foreign_user record
if (!save_twitter_user($friend_id, $friend_name)) {
- return false;
+ common_log(LOG_WARNING,
+ "Twitter bridge - couldn't save $screen_name's friend, $friend_name.");
+ if (defined('SCRIPT_DEBUG')) {
+ print "Couldn't save $screen_name's friend, $friend_name.\n";
+ }
+ continue;
}
// Check to see if there's a related local user
@@ -199,8 +323,20 @@ function save_twitter_friends($user, $twitter_id, $screen_name, $password)
// Get associated user and subscribe her
$friend_user = User::staticGet('id', $flink->user_id);
- subs_subscribe_to($user, $friend_user);
- common_debug("Twitter bridge - subscribed $friend_user->nickname to $user->nickname.");
+ if (!empty($friend_user)) {
+ $result = subs_subscribe_to($user, $friend_user);
+
+ if ($result === true) {
+ common_debug("Twitter bridge - subscribed $friend_user->nickname to $user->nickname.");
+ if (defined('SCRIPT_DEBUG')) {
+ print("Subscribed $friend_user->nickname to $user->nickname.\n");
+ }
+ } else {
+ if (defined('SCRIPT_DEBUG')) {
+ print "$result ($friend_user->nickname to $user->nickname)\n";
+ }
+ }
+ }
}
}
@@ -218,7 +354,7 @@ function is_twitter_bound($notice, $flink) {
return true;
}
}
-
+
return false;
}
@@ -226,10 +362,10 @@ function broadcast_twitter($notice)
{
$success = true;
- $flink = Foreign_link::getByUserID($notice->profile_id,
+ $flink = Foreign_link::getByUserID($notice->profile_id,
TWITTER_SERVICE);
-
- // XXX: Not sure WHERE to check whether a notice should go to
+
+ // XXX: Not sure WHERE to check whether a notice should go to
// Twitter. Should we even put in the queue if it shouldn't? --Zach
if (!is_null($flink) && is_twitter_bound($notice, $flink)) {
@@ -244,7 +380,7 @@ function broadcast_twitter($notice)
$options = array(
CURLOPT_USERPWD => "$twitter_user:$twitter_password",
CURLOPT_POST => true,
- CURLOPT_POSTFIELDS =>
+ CURLOPT_POSTFIELDS =>
array(
'status' => $statustxt,
'source' => common_config('integration', 'source')
@@ -292,7 +428,6 @@ function broadcast_twitter($notice)
$success = false;
}
}
-
+
return $success;
}
-
diff --git a/lib/util.php b/lib/util.php
index a43666fa5..675ff51f0 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -581,10 +581,8 @@ function common_shorten_link($url, $reverse = false)
function common_xml_safe_str($str)
{
- $xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8');
-
- // Replace control, formatting, and surrogate characters with '*', ala Twitter
- return preg_replace('/[\p{Cc}\p{Cf}\p{Cs}]/u', '*', $str);
+ // Neutralize control codes and surrogates
+ return preg_replace('/[\p{Cc}\p{Cs}]/u', '*', $str);
}
function common_tag_link($tag)
@@ -622,9 +620,13 @@ function common_at_link($sender_id, $nickname)
$url = $recipient->profileurl;
}
$xs = new XMLStringer(false);
+ $attrs = array('href' => $url,
+ 'class' => 'url');
+ if (!empty($recipient->fullname)) {
+ $attrs['title'] = $recipient->fullname . ' (' . $recipient->nickname . ')';
+ }
$xs->elementStart('span', 'vcard');
- $xs->elementStart('a', array('href' => $url,
- 'class' => 'url'));
+ $xs->elementStart('a', $attrs);
$xs->element('span', 'fn nickname', $nickname);
$xs->elementEnd('a');
$xs->elementEnd('span');
@@ -639,10 +641,14 @@ function common_group_link($sender_id, $nickname)
$sender = Profile::staticGet($sender_id);
$group = User_group::staticGet('nickname', common_canonical_nickname($nickname));
if ($group && $sender->isMember($group)) {
+ $attrs = array('href' => $group->permalink(),
+ 'class' => 'url');
+ if (!empty($group->fullname)) {
+ $attrs['title'] = $group->fullname . ' (' . $group->nickname . ')';
+ }
$xs = new XMLStringer();
$xs->elementStart('span', 'vcard');
- $xs->elementStart('a', array('href' => $group->permalink(),
- 'class' => 'url'));
+ $xs->elementStart('a', $attrs);
$xs->element('span', 'fn nickname', $nickname);
$xs->elementEnd('a');
$xs->elementEnd('span');
@@ -713,25 +719,46 @@ function common_relative_profile($sender, $nickname, $dt=null)
function common_local_url($action, $args=null, $params=null, $fragment=null)
{
+ static $sensitive = array('login', 'register', 'passwordsettings',
+ 'twittersettings', 'finishopenidlogin',
+ 'finishaddopenid', 'api');
+
$r = Router::get();
$path = $r->build($action, $args, $params, $fragment);
+ $ssl = in_array($action, $sensitive);
+
if (common_config('site','fancy')) {
- $url = common_path(mb_substr($path, 1));
+ $url = common_path(mb_substr($path, 1), $ssl);
} else {
if (mb_strpos($path, '/index.php') === 0) {
- $url = common_path(mb_substr($path, 1));
+ $url = common_path(mb_substr($path, 1), $ssl);
} else {
- $url = common_path('index.php'.$path);
+ $url = common_path('index.php'.$path, $ssl);
}
}
return $url;
}
-function common_path($relative)
+function common_path($relative, $ssl=false)
{
$pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
- return "http://".common_config('site', 'server').'/'.$pathpart.$relative;
+
+ if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
+ || common_config('site', 'ssl') === 'always') {
+ $proto = 'https';
+ if (is_string(common_config('site', 'sslserver')) &&
+ mb_strlen(common_config('site', 'sslserver')) > 0) {
+ $serverpart = common_config('site', 'sslserver');
+ } else {
+ $serverpart = common_config('site', 'server');
+ }
+ } else {
+ $proto = 'http';
+ $serverpart = common_config('site', 'server');
+ }
+
+ return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
}
function common_date_string($dt)
@@ -821,7 +848,7 @@ function common_redirect($url, $code=307)
303 => "See Other",
307 => "Temporary Redirect");
- header("Status: ${code} $status[$code]");
+ header('HTTP/1.1 '.$code.' '.$status[$code]);
header("Location: $url");
$xo = new XMLOutputter();
@@ -923,9 +950,9 @@ function common_profile_url($nickname)
// Should make up a reasonable root URL
-function common_root_url()
+function common_root_url($ssl=false)
{
- return common_path('');
+ return common_path('', $ssl);
}
// returns $bytes bytes of random data as a hexadecimal string
@@ -1294,3 +1321,16 @@ function common_compatible_license($from, $to)
// XXX: better compatibility check needed here!
return ($from == $to);
}
+
+/**
+ * returns a quoted table name, if required according to config
+ */
+function common_database_tablename($tablename)
+{
+
+ if(common_config('db','quote_identifiers')) {
+ $tablename = '"'. $tablename .'"';
+ }
+ //table prefixes could be added here later
+ return $tablename;
+} \ No newline at end of file