replace all tabs with four spaces
The PEAR coding standards decree: no tabs, but indent by four spaces. I've done a global search-and-replace on all tabs, replacing them by four spaces. This is a huge change, but it will go a long way to getting us towards phpcs-compliance. And that means better code readability, and that means more participation. darcs-hash:20081223191907-84dde-21e8efe210e6d5d54e935a22d0cee5c7bbfc007d.gz
This commit is contained in:
@@ -54,100 +54,100 @@ require_once(INSTALLDIR.'/lib/language.php');
|
||||
|
||||
$config =
|
||||
array('site' =>
|
||||
array('name' => 'Just another Laconica microblog',
|
||||
'server' => 'localhost',
|
||||
'theme' => 'default',
|
||||
'path' => '/',
|
||||
'logfile' => NULL,
|
||||
'fancy' => false,
|
||||
'locale_path' => INSTALLDIR.'/locale',
|
||||
'language' => 'en_US',
|
||||
'languages' => get_all_languages(),
|
||||
'email' =>
|
||||
array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
|
||||
'broughtby' => NULL,
|
||||
'timezone' => 'UTC',
|
||||
'broughtbyurl' => NULL,
|
||||
'closed' => false,
|
||||
'inviteonly' => false,
|
||||
array('name' => 'Just another Laconica microblog',
|
||||
'server' => 'localhost',
|
||||
'theme' => 'default',
|
||||
'path' => '/',
|
||||
'logfile' => NULL,
|
||||
'fancy' => false,
|
||||
'locale_path' => INSTALLDIR.'/locale',
|
||||
'language' => 'en_US',
|
||||
'languages' => get_all_languages(),
|
||||
'email' =>
|
||||
array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
|
||||
'broughtby' => NULL,
|
||||
'timezone' => 'UTC',
|
||||
'broughtbyurl' => NULL,
|
||||
'closed' => false,
|
||||
'inviteonly' => false,
|
||||
'private' => false),
|
||||
'syslog' =>
|
||||
array('appname' => 'laconica', # for syslog
|
||||
'priority' => 'debug'), # XXX: currently ignored
|
||||
'queue' =>
|
||||
array('enabled' => false),
|
||||
'license' =>
|
||||
array('url' => 'http://creativecommons.org/licenses/by/3.0/',
|
||||
'title' => 'Creative Commons Attribution 3.0',
|
||||
'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'),
|
||||
'mail' =>
|
||||
array('backend' => 'mail',
|
||||
'params' => NULL),
|
||||
'nickname' =>
|
||||
array('blacklist' => array(),
|
||||
'featured' => array()),
|
||||
'profile' =>
|
||||
array('banned' => array()),
|
||||
'avatar' =>
|
||||
array('server' => NULL),
|
||||
'public' =>
|
||||
array('localonly' => true,
|
||||
'blacklist' => array()),
|
||||
'theme' =>
|
||||
array('server' => NULL),
|
||||
'throttle' =>
|
||||
'syslog' =>
|
||||
array('appname' => 'laconica', # for syslog
|
||||
'priority' => 'debug'), # XXX: currently ignored
|
||||
'queue' =>
|
||||
array('enabled' => false),
|
||||
'license' =>
|
||||
array('url' => 'http://creativecommons.org/licenses/by/3.0/',
|
||||
'title' => 'Creative Commons Attribution 3.0',
|
||||
'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'),
|
||||
'mail' =>
|
||||
array('backend' => 'mail',
|
||||
'params' => NULL),
|
||||
'nickname' =>
|
||||
array('blacklist' => array(),
|
||||
'featured' => array()),
|
||||
'profile' =>
|
||||
array('banned' => array()),
|
||||
'avatar' =>
|
||||
array('server' => NULL),
|
||||
'public' =>
|
||||
array('localonly' => true,
|
||||
'blacklist' => array()),
|
||||
'theme' =>
|
||||
array('server' => NULL),
|
||||
'throttle' =>
|
||||
array('enabled' => false, // whether to throttle edits; false by default
|
||||
'count' => 20, // number of allowed messages in timespan
|
||||
'timespan' => 600), // timespan for throttling
|
||||
'xmpp' =>
|
||||
array('enabled' => false,
|
||||
'server' => 'INVALID SERVER',
|
||||
'port' => 5222,
|
||||
'user' => 'update',
|
||||
'encryption' => true,
|
||||
'resource' => 'uniquename',
|
||||
'password' => 'blahblahblah',
|
||||
'host' => NULL, # only set if != server
|
||||
'debug' => false, # print extra debug info
|
||||
'public' => array()), # JIDs of users who want to receive the public stream
|
||||
'xmpp' =>
|
||||
array('enabled' => false,
|
||||
'server' => 'INVALID SERVER',
|
||||
'port' => 5222,
|
||||
'user' => 'update',
|
||||
'encryption' => true,
|
||||
'resource' => 'uniquename',
|
||||
'password' => 'blahblahblah',
|
||||
'host' => NULL, # only set if != server
|
||||
'debug' => false, # print extra debug info
|
||||
'public' => array()), # JIDs of users who want to receive the public stream
|
||||
'sphinx' =>
|
||||
array('enabled' => false,
|
||||
'server' => 'localhost',
|
||||
'port' => 3312),
|
||||
'tag' =>
|
||||
array('dropoff' => 864000.0),
|
||||
'popular' =>
|
||||
array('dropoff' => 864000.0),
|
||||
'daemon' =>
|
||||
array('piddir' => '/var/run',
|
||||
'user' => false,
|
||||
'group' => false),
|
||||
'integration' =>
|
||||
array('source' => 'Laconica'), # source attribute for Twitter
|
||||
'memcached' =>
|
||||
array('enabled' => false,
|
||||
'server' => 'localhost',
|
||||
'port' => 11211),
|
||||
'inboxes' =>
|
||||
array('enabled' => true), # on by default for new sites
|
||||
);
|
||||
'tag' =>
|
||||
array('dropoff' => 864000.0),
|
||||
'popular' =>
|
||||
array('dropoff' => 864000.0),
|
||||
'daemon' =>
|
||||
array('piddir' => '/var/run',
|
||||
'user' => false,
|
||||
'group' => false),
|
||||
'integration' =>
|
||||
array('source' => 'Laconica'), # source attribute for Twitter
|
||||
'memcached' =>
|
||||
array('enabled' => false,
|
||||
'server' => 'localhost',
|
||||
'port' => 11211),
|
||||
'inboxes' =>
|
||||
array('enabled' => true), # on by default for new sites
|
||||
);
|
||||
|
||||
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
|
||||
|
||||
$config['db'] =
|
||||
array('database' => 'YOU HAVE TO SET THIS IN config.php',
|
||||
'schema_location' => INSTALLDIR . '/classes',
|
||||
'class_location' => INSTALLDIR . '/classes',
|
||||
'require_prefix' => 'classes/',
|
||||
'class_prefix' => '',
|
||||
'mirror' => NULL,
|
||||
'schema_location' => INSTALLDIR . '/classes',
|
||||
'class_location' => INSTALLDIR . '/classes',
|
||||
'require_prefix' => 'classes/',
|
||||
'class_prefix' => '',
|
||||
'mirror' => NULL,
|
||||
'db_driver' => 'DB', # XXX: JanRain libs only work with DB
|
||||
'quote_identifiers' => false,
|
||||
'type' => 'mysql' );
|
||||
'quote_identifiers' => false,
|
||||
'type' => 'mysql' );
|
||||
|
||||
if (function_exists('date_default_timezone_set')) {
|
||||
/* Work internally in UTC */
|
||||
date_default_timezone_set('UTC');
|
||||
/* Work internally in UTC */
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
require_once(INSTALLDIR.'/config.php');
|
||||
@@ -164,9 +164,9 @@ require_once(INSTALLDIR.'/lib/Shorturl_api.php');
|
||||
require_once(INSTALLDIR.'/lib/twitter.php');
|
||||
|
||||
function __autoload($class) {
|
||||
if ($class == 'OAuthRequest') {
|
||||
require_once('OAuth.php');
|
||||
} else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) {
|
||||
if ($class == 'OAuthRequest') {
|
||||
require_once('OAuth.php');
|
||||
} else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) {
|
||||
require_once(INSTALLDIR.'/classes/' . $class . '.php');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,41 +21,41 @@ if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
class DeleteAction extends Action {
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
$user = common_current_user();
|
||||
$notice_id = $this->trimmed('notice');
|
||||
$notice = Notice::staticGet($notice_id);
|
||||
if (!$notice) {
|
||||
common_user_error(_('No such notice.'));
|
||||
exit;
|
||||
}
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
$user = common_current_user();
|
||||
$notice_id = $this->trimmed('notice');
|
||||
$notice = Notice::staticGet($notice_id);
|
||||
if (!$notice) {
|
||||
common_user_error(_('No such notice.'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$profile = $notice->getProfile();
|
||||
$user_profile = $user->getProfile();
|
||||
$profile = $notice->getProfile();
|
||||
$user_profile = $user->getProfile();
|
||||
|
||||
if (!common_logged_in()) {
|
||||
common_user_error(_('Not logged in.'));
|
||||
exit;
|
||||
} else if ($notice->profile_id != $user_profile->id) {
|
||||
common_user_error(_('Can\'t delete this notice.'));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if (!common_logged_in()) {
|
||||
common_user_error(_('Not logged in.'));
|
||||
exit;
|
||||
} else if ($notice->profile_id != $user_profile->id) {
|
||||
common_user_error(_('Can\'t delete this notice.'));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function show_top($arr=NULL) {
|
||||
$instr = $this->get_instructions();
|
||||
$output = common_markup_to_html($instr);
|
||||
common_element_start('div', 'instructions');
|
||||
common_raw($output);
|
||||
common_element_end('div');
|
||||
}
|
||||
function show_top($arr=NULL) {
|
||||
$instr = $this->get_instructions();
|
||||
$output = common_markup_to_html($instr);
|
||||
common_element_start('div', 'instructions');
|
||||
common_raw($output);
|
||||
common_element_end('div');
|
||||
}
|
||||
|
||||
function get_title() {
|
||||
return NULL;
|
||||
}
|
||||
function get_title() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function show_header() {
|
||||
return;
|
||||
}
|
||||
function show_header() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
*
|
||||
* 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
|
||||
* 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/>.
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
@@ -23,261 +23,261 @@ require_once(INSTALLDIR.'/extlib/facebook/facebook.php');
|
||||
|
||||
class FacebookAction extends Action {
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
}
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
}
|
||||
|
||||
function get_facebook() {
|
||||
$apikey = common_config('facebook', 'apikey');
|
||||
$secret = common_config('facebook', 'secret');
|
||||
return new Facebook($apikey, $secret);
|
||||
}
|
||||
function get_facebook() {
|
||||
$apikey = common_config('facebook', 'apikey');
|
||||
$secret = common_config('facebook', 'secret');
|
||||
return new Facebook($apikey, $secret);
|
||||
}
|
||||
|
||||
function update_profile_box($facebook, $fbuid, $user) {
|
||||
function update_profile_box($facebook, $fbuid, $user) {
|
||||
|
||||
$notice = $user->getCurrentNotice();
|
||||
$notice = $user->getCurrentNotice();
|
||||
|
||||
# Need to include inline CSS for styling the Profile box
|
||||
# Need to include inline CSS for styling the Profile box
|
||||
|
||||
$style = '<style>
|
||||
#notices {
|
||||
clear: both;
|
||||
margin: 0 auto;
|
||||
padding: 0;
|
||||
list-style-type: none;
|
||||
width: 600px;
|
||||
border-top: 1px solid #dec5b5;
|
||||
}
|
||||
#notices a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.notice_single {
|
||||
clear: both;
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 5px 5px 5px 0;
|
||||
min-height: 48px;
|
||||
font-family: Georgia, "Times New Roman", Times, serif;
|
||||
font-size: 13px;
|
||||
line-height: 16px;
|
||||
border-bottom: 1px solid #dec5b5;
|
||||
background-color:#FCFFF5;
|
||||
opacity:1;
|
||||
}
|
||||
.notice_single:hover {
|
||||
background-color: #f7ebcc;
|
||||
}
|
||||
.notice_single p {
|
||||
display: inline;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>';
|
||||
$style = '<style>
|
||||
#notices {
|
||||
clear: both;
|
||||
margin: 0 auto;
|
||||
padding: 0;
|
||||
list-style-type: none;
|
||||
width: 600px;
|
||||
border-top: 1px solid #dec5b5;
|
||||
}
|
||||
#notices a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.notice_single {
|
||||
clear: both;
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 5px 5px 5px 0;
|
||||
min-height: 48px;
|
||||
font-family: Georgia, "Times New Roman", Times, serif;
|
||||
font-size: 13px;
|
||||
line-height: 16px;
|
||||
border-bottom: 1px solid #dec5b5;
|
||||
background-color:#FCFFF5;
|
||||
opacity:1;
|
||||
}
|
||||
.notice_single:hover {
|
||||
background-color: #f7ebcc;
|
||||
}
|
||||
.notice_single p {
|
||||
display: inline;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>';
|
||||
|
||||
$html = $this->render_notice($notice);
|
||||
$html = $this->render_notice($notice);
|
||||
|
||||
$fbml = "<fb:wide>$content $html</fb:wide>";
|
||||
$fbml .= "<fb:narrow>$content $html</fb:narrow>";
|
||||
$fbml = "<fb:wide>$content $html</fb:wide>";
|
||||
$fbml .= "<fb:narrow>$content $html</fb:narrow>";
|
||||
|
||||
$fbml_main = "<fb:narrow>$content $html</fb:narrow>";
|
||||
$fbml_main = "<fb:narrow>$content $html</fb:narrow>";
|
||||
|
||||
$facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
|
||||
}
|
||||
$facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
|
||||
}
|
||||
|
||||
# Display methods
|
||||
# Display methods
|
||||
|
||||
function show_header($selected ='Home') {
|
||||
function show_header($selected ='Home') {
|
||||
|
||||
# Add a timestamp to the CSS file so Facebook cache wont ignore our changes
|
||||
$ts = filemtime(theme_file('facebookapp.css'));
|
||||
$cssurl = theme_path('facebookapp.css') . "?ts=$ts";
|
||||
# Add a timestamp to the CSS file so Facebook cache wont ignore our changes
|
||||
$ts = filemtime(theme_file('facebookapp.css'));
|
||||
$cssurl = theme_path('facebookapp.css') . "?ts=$ts";
|
||||
|
||||
$header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />';
|
||||
# $header .='<script src="" ></script>';
|
||||
$header .= '<fb:dashboard/>';
|
||||
$header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />';
|
||||
# $header .='<script src="" ></script>';
|
||||
$header .= '<fb:dashboard/>';
|
||||
|
||||
$header .=
|
||||
'<fb:tabs>'
|
||||
.'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
|
||||
.'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />'
|
||||
.'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />'
|
||||
.'</fb:tabs>';
|
||||
$header .= '<div id="main_body">';
|
||||
$header .=
|
||||
'<fb:tabs>'
|
||||
.'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
|
||||
.'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />'
|
||||
.'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />'
|
||||
.'</fb:tabs>';
|
||||
$header .= '<div id="main_body">';
|
||||
|
||||
echo $header;
|
||||
echo $header;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function show_footer() {
|
||||
$footer = '</div>';
|
||||
echo $footer;
|
||||
}
|
||||
function show_footer() {
|
||||
$footer = '</div>';
|
||||
echo $footer;
|
||||
}
|
||||
|
||||
function show_login_form() {
|
||||
function show_login_form() {
|
||||
|
||||
$loginform =
|
||||
' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
|
||||
.'<a href="http://identi.ca/">'
|
||||
.' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
|
||||
.'</a>'
|
||||
.'<h1 class="pagetitle">Login</h1>'
|
||||
.'<div class="instructions">'
|
||||
.' <p>Login with your username and password. Don\'t have a username yet?'
|
||||
.' <a href="http://identi.ca/main/register">Register</a> a new account.'
|
||||
.' </p>'
|
||||
.'</div>'
|
||||
.'<div id="content">'
|
||||
.' <form method="post" id="login">'
|
||||
.' <p>'
|
||||
.' <label for="nickname">Nickname</label>'
|
||||
.' <input name="nickname" type="text" class="input_text" id="nickname"/>'
|
||||
.' </p>'
|
||||
.' <p>'
|
||||
.' <label for="password">Password</label>'
|
||||
.' <input name="password" type="password" class="password" id="password"/>'
|
||||
.' </p>'
|
||||
.' <p>'
|
||||
.' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
|
||||
.' </p>'
|
||||
.' </form>'
|
||||
.' <p>'
|
||||
.' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
|
||||
.' </p>'
|
||||
.'</div';
|
||||
$loginform =
|
||||
' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
|
||||
.'<a href="http://identi.ca/">'
|
||||
.' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
|
||||
.'</a>'
|
||||
.'<h1 class="pagetitle">Login</h1>'
|
||||
.'<div class="instructions">'
|
||||
.' <p>Login with your username and password. Don\'t have a username yet?'
|
||||
.' <a href="http://identi.ca/main/register">Register</a> a new account.'
|
||||
.' </p>'
|
||||
.'</div>'
|
||||
.'<div id="content">'
|
||||
.' <form method="post" id="login">'
|
||||
.' <p>'
|
||||
.' <label for="nickname">Nickname</label>'
|
||||
.' <input name="nickname" type="text" class="input_text" id="nickname"/>'
|
||||
.' </p>'
|
||||
.' <p>'
|
||||
.' <label for="password">Password</label>'
|
||||
.' <input name="password" type="password" class="password" id="password"/>'
|
||||
.' </p>'
|
||||
.' <p>'
|
||||
.' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
|
||||
.' </p>'
|
||||
.' </form>'
|
||||
.' <p>'
|
||||
.' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
|
||||
.' </p>'
|
||||
.'</div';
|
||||
|
||||
echo $loginform;
|
||||
}
|
||||
echo $loginform;
|
||||
}
|
||||
|
||||
function render_notice($notice) {
|
||||
function render_notice($notice) {
|
||||
|
||||
global $config;
|
||||
global $config;
|
||||
|
||||
$profile = $notice->getProfile();
|
||||
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
|
||||
$profile = $notice->getProfile();
|
||||
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
|
||||
|
||||
$noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
|
||||
$noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
|
||||
|
||||
# XXX: we need to figure this out better. Is this right?
|
||||
if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
|
||||
$noticeurl = $notice->uri;
|
||||
}
|
||||
# XXX: we need to figure this out better. Is this right?
|
||||
if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
|
||||
$noticeurl = $notice->uri;
|
||||
}
|
||||
|
||||
$html =
|
||||
'<li class="notice_single" id="' . $notice->id . '">'
|
||||
.'<a href="' . $profile->profileurl . '">'
|
||||
.'<img src="';
|
||||
$html =
|
||||
'<li class="notice_single" id="' . $notice->id . '">'
|
||||
.'<a href="' . $profile->profileurl . '">'
|
||||
.'<img src="';
|
||||
|
||||
if ($avatar) {
|
||||
$html .= common_avatar_display_url($avatar);
|
||||
} else {
|
||||
$html .= common_default_avatar(AVATAR_STREAM_SIZE);
|
||||
}
|
||||
if ($avatar) {
|
||||
$html .= common_avatar_display_url($avatar);
|
||||
} else {
|
||||
$html .= common_default_avatar(AVATAR_STREAM_SIZE);
|
||||
}
|
||||
|
||||
$html .=
|
||||
'" class="avatar stream" width="'
|
||||
. AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
|
||||
.' alt="';
|
||||
$html .=
|
||||
'" class="avatar stream" width="'
|
||||
. AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
|
||||
.' alt="';
|
||||
|
||||
if ($profile->fullname) {
|
||||
$html .= $profile->fullname;
|
||||
} else {
|
||||
$html .= $profile->nickname;
|
||||
}
|
||||
if ($profile->fullname) {
|
||||
$html .= $profile->fullname;
|
||||
} else {
|
||||
$html .= $profile->nickname;
|
||||
}
|
||||
|
||||
$html .=
|
||||
'"></a>'
|
||||
.'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
|
||||
.'<p class="content">' . $notice->rendered . '</p>'
|
||||
.'<p class="time">'
|
||||
.'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
|
||||
$html .=
|
||||
'"></a>'
|
||||
.'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
|
||||
.'<p class="content">' . $notice->rendered . '</p>'
|
||||
.'<p class="time">'
|
||||
.'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
|
||||
|
||||
if ($notice->source) {
|
||||
$html .= _(' from ');
|
||||
$html .= $this->source_link($notice->source);
|
||||
}
|
||||
if ($notice->source) {
|
||||
$html .= _(' from ');
|
||||
$html .= $this->source_link($notice->source);
|
||||
}
|
||||
|
||||
if ($notice->reply_to) {
|
||||
$replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
|
||||
$html .=
|
||||
' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
|
||||
}
|
||||
if ($notice->reply_to) {
|
||||
$replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
|
||||
$html .=
|
||||
' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
|
||||
}
|
||||
|
||||
$html .= '</p></li>';
|
||||
$html .= '</p></li>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function source_link($source) {
|
||||
$source_name = _($source);
|
||||
function source_link($source) {
|
||||
$source_name = _($source);
|
||||
|
||||
$html = '<span class="noticesource">';
|
||||
$html = '<span class="noticesource">';
|
||||
|
||||
switch ($source) {
|
||||
case 'web':
|
||||
case 'xmpp':
|
||||
case 'mail':
|
||||
case 'omb':
|
||||
case 'api':
|
||||
$html .= $source_name;
|
||||
break;
|
||||
default:
|
||||
$ns = Notice_source::staticGet($source);
|
||||
if ($ns) {
|
||||
$html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
|
||||
} else {
|
||||
$html .= $source_name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch ($source) {
|
||||
case 'web':
|
||||
case 'xmpp':
|
||||
case 'mail':
|
||||
case 'omb':
|
||||
case 'api':
|
||||
$html .= $source_name;
|
||||
break;
|
||||
default:
|
||||
$ns = Notice_source::staticGet($source);
|
||||
if ($ns) {
|
||||
$html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
|
||||
} else {
|
||||
$html .= $source_name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$html .= '</span>';
|
||||
$html .= '</span>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
|
||||
function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
|
||||
|
||||
$html = '';
|
||||
$html = '';
|
||||
|
||||
if ($have_before || $have_after) {
|
||||
$html = '<div id="pagination">';
|
||||
$html .'<ul id="nav_pagination">';
|
||||
}
|
||||
if ($have_before || $have_after) {
|
||||
$html = '<div id="pagination">';
|
||||
$html .'<ul id="nav_pagination">';
|
||||
}
|
||||
|
||||
if ($have_before) {
|
||||
$pargs = array('page' => $page-1);
|
||||
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
|
||||
$html .= '<li class="before">';
|
||||
$html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
|
||||
$html .'</li>';
|
||||
}
|
||||
if ($have_before) {
|
||||
$pargs = array('page' => $page-1);
|
||||
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
|
||||
$html .= '<li class="before">';
|
||||
$html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
|
||||
$html .'</li>';
|
||||
}
|
||||
|
||||
if ($have_after) {
|
||||
$pargs = array('page' => $page+1);
|
||||
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
|
||||
$html .= '<li class="after">';
|
||||
$html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
|
||||
$html .'</li>';
|
||||
}
|
||||
if ($have_after) {
|
||||
$pargs = array('page' => $page+1);
|
||||
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
|
||||
$html .= '<li class="after">';
|
||||
$html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
|
||||
$html .'</li>';
|
||||
}
|
||||
|
||||
if ($have_before || $have_after) {
|
||||
$html .= '<ul>';
|
||||
$html .'<div>';
|
||||
}
|
||||
}
|
||||
if ($have_before || $have_after) {
|
||||
$html .= '<ul>';
|
||||
$html .'<div>';
|
||||
}
|
||||
}
|
||||
|
||||
function pagination_url($fbaction, $args=NULL) {
|
||||
global $config;
|
||||
function pagination_url($fbaction, $args=NULL) {
|
||||
global $config;
|
||||
|
||||
$extra = '';
|
||||
$extra = '';
|
||||
|
||||
if ($args) {
|
||||
foreach ($args as $key => $value) {
|
||||
$extra .= "&${key}=${value}";
|
||||
}
|
||||
}
|
||||
if ($args) {
|
||||
foreach ($args as $key => $value) {
|
||||
$extra .= "&${key}=${value}";
|
||||
}
|
||||
}
|
||||
|
||||
return "$fbaction?${extra}";
|
||||
}
|
||||
return "$fbaction?${extra}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,122 +23,122 @@ require_once(INSTALLDIR.'/lib/omb.php');
|
||||
|
||||
class LaconicaOAuthDataStore extends OAuthDataStore {
|
||||
|
||||
# We keep a record of who's contacted us
|
||||
# We keep a record of who's contacted us
|
||||
|
||||
function lookup_consumer($consumer_key) {
|
||||
$con = Consumer::staticGet('consumer_key', $consumer_key);
|
||||
if (!$con) {
|
||||
$con = new Consumer();
|
||||
$con->consumer_key = $consumer_key;
|
||||
$con->seed = common_good_rand(16);
|
||||
$con->created = DB_DataObject_Cast::dateTime();
|
||||
if (!$con->insert()) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return new OAuthConsumer($con->consumer_key, '');
|
||||
}
|
||||
function lookup_consumer($consumer_key) {
|
||||
$con = Consumer::staticGet('consumer_key', $consumer_key);
|
||||
if (!$con) {
|
||||
$con = new Consumer();
|
||||
$con->consumer_key = $consumer_key;
|
||||
$con->seed = common_good_rand(16);
|
||||
$con->created = DB_DataObject_Cast::dateTime();
|
||||
if (!$con->insert()) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return new OAuthConsumer($con->consumer_key, '');
|
||||
}
|
||||
|
||||
function lookup_token($consumer, $token_type, $token_key) {
|
||||
$t = new Token();
|
||||
$t->consumer_key = $consumer->key;
|
||||
$t->tok = $token_key;
|
||||
$t->type = ($token_type == 'access') ? 1 : 0;
|
||||
if ($t->find(true)) {
|
||||
return new OAuthToken($t->tok, $t->secret);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
function lookup_token($consumer, $token_type, $token_key) {
|
||||
$t = new Token();
|
||||
$t->consumer_key = $consumer->key;
|
||||
$t->tok = $token_key;
|
||||
$t->type = ($token_type == 'access') ? 1 : 0;
|
||||
if ($t->find(true)) {
|
||||
return new OAuthToken($t->tok, $t->secret);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
|
||||
$n = new Nonce();
|
||||
$n->consumer_key = $consumer->key;
|
||||
$n->tok = $token->key;
|
||||
$n->nonce = $nonce;
|
||||
if ($n->find(TRUE)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
$n->timestamp = $timestamp;
|
||||
$n->created = DB_DataObject_Cast::dateTime();
|
||||
$n->insert();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
|
||||
$n = new Nonce();
|
||||
$n->consumer_key = $consumer->key;
|
||||
$n->tok = $token->key;
|
||||
$n->nonce = $nonce;
|
||||
if ($n->find(TRUE)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
$n->timestamp = $timestamp;
|
||||
$n->created = DB_DataObject_Cast::dateTime();
|
||||
$n->insert();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function new_request_token($consumer) {
|
||||
$t = new Token();
|
||||
$t->consumer_key = $consumer->key;
|
||||
$t->tok = common_good_rand(16);
|
||||
$t->secret = common_good_rand(16);
|
||||
$t->type = 0; # request
|
||||
$t->state = 0; # unauthorized
|
||||
$t->created = DB_DataObject_Cast::dateTime();
|
||||
if (!$t->insert()) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new OAuthToken($t->tok, $t->secret);
|
||||
}
|
||||
}
|
||||
function new_request_token($consumer) {
|
||||
$t = new Token();
|
||||
$t->consumer_key = $consumer->key;
|
||||
$t->tok = common_good_rand(16);
|
||||
$t->secret = common_good_rand(16);
|
||||
$t->type = 0; # request
|
||||
$t->state = 0; # unauthorized
|
||||
$t->created = DB_DataObject_Cast::dateTime();
|
||||
if (!$t->insert()) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new OAuthToken($t->tok, $t->secret);
|
||||
}
|
||||
}
|
||||
|
||||
# defined in OAuthDataStore, but not implemented anywhere
|
||||
# defined in OAuthDataStore, but not implemented anywhere
|
||||
|
||||
function fetch_request_token($consumer) {
|
||||
return $this->new_request_token($consumer);
|
||||
}
|
||||
function fetch_request_token($consumer) {
|
||||
return $this->new_request_token($consumer);
|
||||
}
|
||||
|
||||
function new_access_token($token, $consumer) {
|
||||
common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__);
|
||||
$rt = new Token();
|
||||
$rt->consumer_key = $consumer->key;
|
||||
$rt->tok = $token->key;
|
||||
$rt->type = 0; # request
|
||||
if ($rt->find(TRUE) && $rt->state == 1) { # authorized
|
||||
common_debug('request token found.', __FILE__);
|
||||
$at = new Token();
|
||||
$at->consumer_key = $consumer->key;
|
||||
$at->tok = common_good_rand(16);
|
||||
$at->secret = common_good_rand(16);
|
||||
$at->type = 1; # access
|
||||
$at->created = DB_DataObject_Cast::dateTime();
|
||||
if (!$at->insert()) {
|
||||
$e = $at->_lastError;
|
||||
common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__);
|
||||
return NULL;
|
||||
} else {
|
||||
common_debug('access token "'.$at->tok.'" inserted', __FILE__);
|
||||
# burn the old one
|
||||
$orig_rt = clone($rt);
|
||||
$rt->state = 2; # used
|
||||
if (!$rt->update($orig_rt)) {
|
||||
return NULL;
|
||||
}
|
||||
common_debug('request token "'.$rt->tok.'" updated', __FILE__);
|
||||
# Update subscription
|
||||
# XXX: mixing levels here
|
||||
$sub = Subscription::staticGet('token', $rt->tok);
|
||||
if (!$sub) {
|
||||
return NULL;
|
||||
}
|
||||
common_debug('subscription for request token found', __FILE__);
|
||||
$orig_sub = clone($sub);
|
||||
$sub->token = $at->tok;
|
||||
$sub->secret = $at->secret;
|
||||
if (!$sub->update($orig_sub)) {
|
||||
return NULL;
|
||||
} else {
|
||||
common_debug('subscription updated to use access token', __FILE__);
|
||||
return new OAuthToken($at->tok, $at->secret);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
function new_access_token($token, $consumer) {
|
||||
common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__);
|
||||
$rt = new Token();
|
||||
$rt->consumer_key = $consumer->key;
|
||||
$rt->tok = $token->key;
|
||||
$rt->type = 0; # request
|
||||
if ($rt->find(TRUE) && $rt->state == 1) { # authorized
|
||||
common_debug('request token found.', __FILE__);
|
||||
$at = new Token();
|
||||
$at->consumer_key = $consumer->key;
|
||||
$at->tok = common_good_rand(16);
|
||||
$at->secret = common_good_rand(16);
|
||||
$at->type = 1; # access
|
||||
$at->created = DB_DataObject_Cast::dateTime();
|
||||
if (!$at->insert()) {
|
||||
$e = $at->_lastError;
|
||||
common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__);
|
||||
return NULL;
|
||||
} else {
|
||||
common_debug('access token "'.$at->tok.'" inserted', __FILE__);
|
||||
# burn the old one
|
||||
$orig_rt = clone($rt);
|
||||
$rt->state = 2; # used
|
||||
if (!$rt->update($orig_rt)) {
|
||||
return NULL;
|
||||
}
|
||||
common_debug('request token "'.$rt->tok.'" updated', __FILE__);
|
||||
# Update subscription
|
||||
# XXX: mixing levels here
|
||||
$sub = Subscription::staticGet('token', $rt->tok);
|
||||
if (!$sub) {
|
||||
return NULL;
|
||||
}
|
||||
common_debug('subscription for request token found', __FILE__);
|
||||
$orig_sub = clone($sub);
|
||||
$sub->token = $at->tok;
|
||||
$sub->secret = $at->secret;
|
||||
if (!$sub->update($orig_sub)) {
|
||||
return NULL;
|
||||
} else {
|
||||
common_debug('subscription updated to use access token', __FILE__);
|
||||
return new OAuthToken($at->tok, $at->secret);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
# defined in OAuthDataStore, but not implemented anywhere
|
||||
# defined in OAuthDataStore, but not implemented anywhere
|
||||
|
||||
function fetch_access_token($consumer) {
|
||||
return $this->new_access_token($consumer);
|
||||
}
|
||||
function fetch_access_token($consumer) {
|
||||
return $this->new_access_token($consumer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,256 +44,256 @@ define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
|
||||
define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
|
||||
|
||||
function omb_oauth_consumer() {
|
||||
static $con = NULL;
|
||||
if (!$con) {
|
||||
$con = new OAuthConsumer(common_root_url(), '');
|
||||
}
|
||||
return $con;
|
||||
static $con = NULL;
|
||||
if (!$con) {
|
||||
$con = new OAuthConsumer(common_root_url(), '');
|
||||
}
|
||||
return $con;
|
||||
}
|
||||
|
||||
function omb_oauth_server() {
|
||||
static $server = null;
|
||||
if (!$server) {
|
||||
$server = new OAuthServer(omb_oauth_datastore());
|
||||
$server->add_signature_method(omb_hmac_sha1());
|
||||
}
|
||||
return $server;
|
||||
static $server = null;
|
||||
if (!$server) {
|
||||
$server = new OAuthServer(omb_oauth_datastore());
|
||||
$server->add_signature_method(omb_hmac_sha1());
|
||||
}
|
||||
return $server;
|
||||
}
|
||||
|
||||
function omb_oauth_datastore() {
|
||||
static $store = NULL;
|
||||
if (!$store) {
|
||||
$store = new LaconicaOAuthDataStore();
|
||||
}
|
||||
return $store;
|
||||
static $store = NULL;
|
||||
if (!$store) {
|
||||
$store = new LaconicaOAuthDataStore();
|
||||
}
|
||||
return $store;
|
||||
}
|
||||
|
||||
function omb_hmac_sha1() {
|
||||
static $hmac_method = NULL;
|
||||
if (!$hmac_method) {
|
||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||
}
|
||||
return $hmac_method;
|
||||
static $hmac_method = NULL;
|
||||
if (!$hmac_method) {
|
||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||
}
|
||||
return $hmac_method;
|
||||
}
|
||||
|
||||
function omb_get_services($xrd, $type) {
|
||||
return $xrd->services(array(omb_service_filter($type)));
|
||||
return $xrd->services(array(omb_service_filter($type)));
|
||||
}
|
||||
|
||||
function omb_service_filter($type) {
|
||||
return create_function('$s',
|
||||
'return omb_match_service($s, \''.$type.'\');');
|
||||
return create_function('$s',
|
||||
'return omb_match_service($s, \''.$type.'\');');
|
||||
}
|
||||
|
||||
function omb_match_service($service, $type) {
|
||||
return in_array($type, $service->getTypes());
|
||||
return in_array($type, $service->getTypes());
|
||||
}
|
||||
|
||||
function omb_service_uri($service) {
|
||||
if (!$service) {
|
||||
return NULL;
|
||||
}
|
||||
$uris = $service->getURIs();
|
||||
if (!$uris) {
|
||||
return NULL;
|
||||
}
|
||||
return $uris[0];
|
||||
if (!$service) {
|
||||
return NULL;
|
||||
}
|
||||
$uris = $service->getURIs();
|
||||
if (!$uris) {
|
||||
return NULL;
|
||||
}
|
||||
return $uris[0];
|
||||
}
|
||||
|
||||
function omb_local_id($service) {
|
||||
if (!$service) {
|
||||
return NULL;
|
||||
}
|
||||
$els = $service->getElements('xrd:LocalID');
|
||||
if (!$els) {
|
||||
return NULL;
|
||||
}
|
||||
$el = $els[0];
|
||||
return $service->parser->content($el);
|
||||
if (!$service) {
|
||||
return NULL;
|
||||
}
|
||||
$els = $service->getElements('xrd:LocalID');
|
||||
if (!$els) {
|
||||
return NULL;
|
||||
}
|
||||
$el = $els[0];
|
||||
return $service->parser->content($el);
|
||||
}
|
||||
|
||||
function omb_broadcast_remote_subscribers($notice) {
|
||||
|
||||
# First, get remote users subscribed to this profile
|
||||
$rp = new Remote_profile();
|
||||
# First, get remote users subscribed to this profile
|
||||
$rp = new Remote_profile();
|
||||
|
||||
$rp->query('SELECT postnoticeurl, token, secret ' .
|
||||
'FROM subscription JOIN remote_profile ' .
|
||||
'ON subscription.subscriber = remote_profile.id ' .
|
||||
'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
|
||||
$rp->query('SELECT postnoticeurl, token, secret ' .
|
||||
'FROM subscription JOIN remote_profile ' .
|
||||
'ON subscription.subscriber = remote_profile.id ' .
|
||||
'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
|
||||
|
||||
$posted = array();
|
||||
$posted = array();
|
||||
|
||||
while ($rp->fetch()) {
|
||||
if (!$posted[$rp->postnoticeurl]) {
|
||||
common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl);
|
||||
if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) {
|
||||
common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl);
|
||||
$posted[$rp->postnoticeurl] = TRUE;
|
||||
} else {
|
||||
common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl);
|
||||
}
|
||||
}
|
||||
}
|
||||
while ($rp->fetch()) {
|
||||
if (!$posted[$rp->postnoticeurl]) {
|
||||
common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl);
|
||||
if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) {
|
||||
common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl);
|
||||
$posted[$rp->postnoticeurl] = TRUE;
|
||||
} else {
|
||||
common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rp->free();
|
||||
unset($rp);
|
||||
$rp->free();
|
||||
unset($rp);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function omb_post_notice($notice, $remote_profile, $subscription) {
|
||||
return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret);
|
||||
return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret);
|
||||
}
|
||||
|
||||
function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret) {
|
||||
|
||||
common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__);
|
||||
common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__);
|
||||
|
||||
$user = User::staticGet('id', $notice->profile_id);
|
||||
$user = User::staticGet('id', $notice->profile_id);
|
||||
|
||||
if (!$user) {
|
||||
common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__);
|
||||
return false;
|
||||
}
|
||||
if (!$user) {
|
||||
common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
$con = omb_oauth_consumer();
|
||||
$con = omb_oauth_consumer();
|
||||
|
||||
$token = new OAuthToken($tk, $secret);
|
||||
$token = new OAuthToken($tk, $secret);
|
||||
|
||||
$url = $postnoticeurl;
|
||||
$parsed = parse_url($url);
|
||||
$params = array();
|
||||
parse_str($parsed['query'], $params);
|
||||
$url = $postnoticeurl;
|
||||
$parsed = parse_url($url);
|
||||
$params = array();
|
||||
parse_str($parsed['query'], $params);
|
||||
|
||||
$req = OAuthRequest::from_consumer_and_token($con, $token,
|
||||
'POST', $url, $params);
|
||||
$req = OAuthRequest::from_consumer_and_token($con, $token,
|
||||
'POST', $url, $params);
|
||||
|
||||
$req->set_parameter('omb_version', OMB_VERSION_01);
|
||||
$req->set_parameter('omb_listenee', $user->uri);
|
||||
$req->set_parameter('omb_notice', $notice->uri);
|
||||
$req->set_parameter('omb_notice_content', $notice->content);
|
||||
$req->set_parameter('omb_notice_url', common_local_url('shownotice',
|
||||
array('notice' =>
|
||||
$notice->id)));
|
||||
$req->set_parameter('omb_notice_license', common_config('license', 'url'));
|
||||
$req->set_parameter('omb_version', OMB_VERSION_01);
|
||||
$req->set_parameter('omb_listenee', $user->uri);
|
||||
$req->set_parameter('omb_notice', $notice->uri);
|
||||
$req->set_parameter('omb_notice_content', $notice->content);
|
||||
$req->set_parameter('omb_notice_url', common_local_url('shownotice',
|
||||
array('notice' =>
|
||||
$notice->id)));
|
||||
$req->set_parameter('omb_notice_license', common_config('license', 'url'));
|
||||
|
||||
$user->free();
|
||||
unset($user);
|
||||
$user->free();
|
||||
unset($user);
|
||||
|
||||
$req->sign_request(omb_hmac_sha1(), $con, $token);
|
||||
$req->sign_request(omb_hmac_sha1(), $con, $token);
|
||||
|
||||
# We re-use this tool's fetcher, since it's pretty good
|
||||
# We re-use this tool's fetcher, since it's pretty good
|
||||
|
||||
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
||||
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
||||
|
||||
if (!$fetcher) {
|
||||
common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
|
||||
return false;
|
||||
}
|
||||
if (!$fetcher) {
|
||||
common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $fetcher->post($req->get_normalized_http_url(),
|
||||
$req->to_postdata(),
|
||||
$result = $fetcher->post($req->get_normalized_http_url(),
|
||||
$req->to_postdata(),
|
||||
array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
|
||||
|
||||
common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
|
||||
common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
|
||||
|
||||
if ($result->status == 403) { # not authorized, don't send again
|
||||
common_debug('403 result, deleting subscription', __FILE__);
|
||||
# FIXME: figure out how to delete this
|
||||
# $subscription->delete();
|
||||
return false;
|
||||
} else if ($result->status != 200) {
|
||||
common_debug('Error status '.$result->status, __FILE__);
|
||||
return false;
|
||||
} else { # success!
|
||||
parse_str($result->body, $return);
|
||||
if ($return['omb_version'] == OMB_VERSION_01) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($result->status == 403) { # not authorized, don't send again
|
||||
common_debug('403 result, deleting subscription', __FILE__);
|
||||
# FIXME: figure out how to delete this
|
||||
# $subscription->delete();
|
||||
return false;
|
||||
} else if ($result->status != 200) {
|
||||
common_debug('Error status '.$result->status, __FILE__);
|
||||
return false;
|
||||
} else { # success!
|
||||
parse_str($result->body, $return);
|
||||
if ($return['omb_version'] == OMB_VERSION_01) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function omb_broadcast_profile($profile) {
|
||||
# First, get remote users subscribed to this profile
|
||||
# XXX: use a join here rather than looping through results
|
||||
$sub = new Subscription();
|
||||
$sub->subscribed = $profile->id;
|
||||
if ($sub->find()) {
|
||||
$updated = array();
|
||||
while ($sub->fetch()) {
|
||||
$rp = Remote_profile::staticGet('id', $sub->subscriber);
|
||||
if ($rp) {
|
||||
if (!$updated[$rp->updateprofileurl]) {
|
||||
if (omb_update_profile($profile, $rp, $sub)) {
|
||||
$updated[$rp->updateprofileurl] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# First, get remote users subscribed to this profile
|
||||
# XXX: use a join here rather than looping through results
|
||||
$sub = new Subscription();
|
||||
$sub->subscribed = $profile->id;
|
||||
if ($sub->find()) {
|
||||
$updated = array();
|
||||
while ($sub->fetch()) {
|
||||
$rp = Remote_profile::staticGet('id', $sub->subscriber);
|
||||
if ($rp) {
|
||||
if (!$updated[$rp->updateprofileurl]) {
|
||||
if (omb_update_profile($profile, $rp, $sub)) {
|
||||
$updated[$rp->updateprofileurl] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function omb_update_profile($profile, $remote_profile, $subscription) {
|
||||
global $config; # for license URL
|
||||
$user = User::staticGet($profile->id);
|
||||
$con = omb_oauth_consumer();
|
||||
$token = new OAuthToken($subscription->token, $subscription->secret);
|
||||
$url = $remote_profile->updateprofileurl;
|
||||
$parsed = parse_url($url);
|
||||
$params = array();
|
||||
parse_str($parsed['query'], $params);
|
||||
$req = OAuthRequest::from_consumer_and_token($con, $token,
|
||||
"POST", $url, $params);
|
||||
$req->set_parameter('omb_version', OMB_VERSION_01);
|
||||
$req->set_parameter('omb_listenee', $user->uri);
|
||||
$req->set_parameter('omb_listenee_profile', common_profile_url($profile->nickname));
|
||||
$req->set_parameter('omb_listenee_nickname', $profile->nickname);
|
||||
global $config; # for license URL
|
||||
$user = User::staticGet($profile->id);
|
||||
$con = omb_oauth_consumer();
|
||||
$token = new OAuthToken($subscription->token, $subscription->secret);
|
||||
$url = $remote_profile->updateprofileurl;
|
||||
$parsed = parse_url($url);
|
||||
$params = array();
|
||||
parse_str($parsed['query'], $params);
|
||||
$req = OAuthRequest::from_consumer_and_token($con, $token,
|
||||
"POST", $url, $params);
|
||||
$req->set_parameter('omb_version', OMB_VERSION_01);
|
||||
$req->set_parameter('omb_listenee', $user->uri);
|
||||
$req->set_parameter('omb_listenee_profile', common_profile_url($profile->nickname));
|
||||
$req->set_parameter('omb_listenee_nickname', $profile->nickname);
|
||||
|
||||
# We use blanks to force emptying any existing values in these optional fields
|
||||
# We use blanks to force emptying any existing values in these optional fields
|
||||
|
||||
$req->set_parameter('omb_listenee_fullname',
|
||||
($profile->fullname) ? $profile->fullname : '');
|
||||
$req->set_parameter('omb_listenee_homepage',
|
||||
($profile->homepage) ? $profile->homepage : '');
|
||||
$req->set_parameter('omb_listenee_bio',
|
||||
($profile->bio) ? $profile->bio : '');
|
||||
$req->set_parameter('omb_listenee_location',
|
||||
($profile->location) ? $profile->location : '');
|
||||
$req->set_parameter('omb_listenee_fullname',
|
||||
($profile->fullname) ? $profile->fullname : '');
|
||||
$req->set_parameter('omb_listenee_homepage',
|
||||
($profile->homepage) ? $profile->homepage : '');
|
||||
$req->set_parameter('omb_listenee_bio',
|
||||
($profile->bio) ? $profile->bio : '');
|
||||
$req->set_parameter('omb_listenee_location',
|
||||
($profile->location) ? $profile->location : '');
|
||||
|
||||
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
$req->set_parameter('omb_listenee_avatar',
|
||||
($avatar) ? $avatar->url : '');
|
||||
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
$req->set_parameter('omb_listenee_avatar',
|
||||
($avatar) ? $avatar->url : '');
|
||||
|
||||
$req->sign_request(omb_hmac_sha1(), $con, $token);
|
||||
$req->sign_request(omb_hmac_sha1(), $con, $token);
|
||||
|
||||
# We re-use this tool's fetcher, since it's pretty good
|
||||
# We re-use this tool's fetcher, since it's pretty good
|
||||
|
||||
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
||||
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
||||
|
||||
common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__);
|
||||
common_debug('postdata = '.$req->to_postdata(), __FILE__);
|
||||
$result = $fetcher->post($req->get_normalized_http_url(),
|
||||
$req->to_postdata(),
|
||||
common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__);
|
||||
common_debug('postdata = '.$req->to_postdata(), __FILE__);
|
||||
$result = $fetcher->post($req->get_normalized_http_url(),
|
||||
$req->to_postdata(),
|
||||
array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
|
||||
|
||||
common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
|
||||
common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
|
||||
|
||||
if ($result->status == 403) { # not authorized, don't send again
|
||||
common_debug('403 result, deleting subscription', __FILE__);
|
||||
$subscription->delete();
|
||||
return false;
|
||||
} else if ($result->status != 200) {
|
||||
common_debug('Error status '.$result->status, __FILE__);
|
||||
return false;
|
||||
} else { # success!
|
||||
parse_str($result->body, $return);
|
||||
if ($return['omb_version'] == OMB_VERSION_01) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($result->status == 403) { # not authorized, don't send again
|
||||
common_debug('403 result, deleting subscription', __FILE__);
|
||||
$subscription->delete();
|
||||
return false;
|
||||
} else if ($result->status != 200) {
|
||||
common_debug('Error status '.$result->status, __FILE__);
|
||||
return false;
|
||||
} else { # success!
|
||||
parse_str($result->body, $return);
|
||||
if ($return['omb_version'] == OMB_VERSION_01) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,210 +33,210 @@ define('OPENID_COOKIE_KEY', 'lastusedopenid');
|
||||
|
||||
function oid_store() {
|
||||
static $store = NULL;
|
||||
if (!$store) {
|
||||
# Can't be called statically
|
||||
$user = new User();
|
||||
$conn = $user->getDatabaseConnection();
|
||||
$store = new Auth_OpenID_MySQLStore($conn);
|
||||
}
|
||||
return $store;
|
||||
if (!$store) {
|
||||
# Can't be called statically
|
||||
$user = new User();
|
||||
$conn = $user->getDatabaseConnection();
|
||||
$store = new Auth_OpenID_MySQLStore($conn);
|
||||
}
|
||||
return $store;
|
||||
}
|
||||
|
||||
function oid_consumer() {
|
||||
$store = oid_store();
|
||||
$consumer = new Auth_OpenID_Consumer($store);
|
||||
return $consumer;
|
||||
$store = oid_store();
|
||||
$consumer = new Auth_OpenID_Consumer($store);
|
||||
return $consumer;
|
||||
}
|
||||
|
||||
function oid_clear_last() {
|
||||
oid_set_last('');
|
||||
oid_set_last('');
|
||||
}
|
||||
|
||||
function oid_set_last($openid_url) {
|
||||
common_set_cookie(OPENID_COOKIE_KEY,
|
||||
$openid_url,
|
||||
time() + OPENID_COOKIE_EXPIRY);
|
||||
common_set_cookie(OPENID_COOKIE_KEY,
|
||||
$openid_url,
|
||||
time() + OPENID_COOKIE_EXPIRY);
|
||||
}
|
||||
|
||||
function oid_get_last() {
|
||||
$openid_url = $_COOKIE[OPENID_COOKIE_KEY];
|
||||
if ($openid_url && strlen($openid_url) > 0) {
|
||||
return $openid_url;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
$openid_url = $_COOKIE[OPENID_COOKIE_KEY];
|
||||
if ($openid_url && strlen($openid_url) > 0) {
|
||||
return $openid_url;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function oid_link_user($id, $canonical, $display) {
|
||||
|
||||
$oid = new User_openid();
|
||||
$oid->user_id = $id;
|
||||
$oid->canonical = $canonical;
|
||||
$oid->display = $display;
|
||||
$oid->created = DB_DataObject_Cast::dateTime();
|
||||
$oid = new User_openid();
|
||||
$oid->user_id = $id;
|
||||
$oid->canonical = $canonical;
|
||||
$oid->display = $display;
|
||||
$oid->created = DB_DataObject_Cast::dateTime();
|
||||
|
||||
if (!$oid->insert()) {
|
||||
$err = PEAR::getStaticProperty('DB_DataObject','lastError');
|
||||
common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__);
|
||||
return false;
|
||||
}
|
||||
if (!$oid->insert()) {
|
||||
$err = PEAR::getStaticProperty('DB_DataObject','lastError');
|
||||
common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function oid_get_user($openid_url) {
|
||||
$user = NULL;
|
||||
$oid = User_openid::staticGet('canonical', $openid_url);
|
||||
if ($oid) {
|
||||
$user = User::staticGet('id', $oid->user_id);
|
||||
}
|
||||
return $user;
|
||||
$user = NULL;
|
||||
$oid = User_openid::staticGet('canonical', $openid_url);
|
||||
if ($oid) {
|
||||
$user = User::staticGet('id', $oid->user_id);
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
function oid_check_immediate($openid_url, $backto=NULL) {
|
||||
if (!$backto) {
|
||||
$action = $_REQUEST['action'];
|
||||
$args = common_copy_args($_GET);
|
||||
unset($args['action']);
|
||||
$backto = common_local_url($action, $args);
|
||||
}
|
||||
common_debug('going back to "' . $backto . '"', __FILE__);
|
||||
if (!$backto) {
|
||||
$action = $_REQUEST['action'];
|
||||
$args = common_copy_args($_GET);
|
||||
unset($args['action']);
|
||||
$backto = common_local_url($action, $args);
|
||||
}
|
||||
common_debug('going back to "' . $backto . '"', __FILE__);
|
||||
|
||||
common_ensure_session();
|
||||
common_ensure_session();
|
||||
|
||||
$_SESSION['openid_immediate_backto'] = $backto;
|
||||
common_debug('passed-in variable is "' . $backto . '"', __FILE__);
|
||||
common_debug('session variable is "' . $_SESSION['openid_immediate_backto'] . '"', __FILE__);
|
||||
$_SESSION['openid_immediate_backto'] = $backto;
|
||||
common_debug('passed-in variable is "' . $backto . '"', __FILE__);
|
||||
common_debug('session variable is "' . $_SESSION['openid_immediate_backto'] . '"', __FILE__);
|
||||
|
||||
oid_authenticate($openid_url,
|
||||
'finishimmediate',
|
||||
true);
|
||||
oid_authenticate($openid_url,
|
||||
'finishimmediate',
|
||||
true);
|
||||
}
|
||||
|
||||
function oid_authenticate($openid_url, $returnto, $immediate=false) {
|
||||
|
||||
$consumer = oid_consumer();
|
||||
$consumer = oid_consumer();
|
||||
|
||||
if (!$consumer) {
|
||||
common_server_error(_('Cannot instantiate OpenID consumer object.'));
|
||||
return false;
|
||||
}
|
||||
if (!$consumer) {
|
||||
common_server_error(_('Cannot instantiate OpenID consumer object.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
common_ensure_session();
|
||||
common_ensure_session();
|
||||
|
||||
$auth_request = $consumer->begin($openid_url);
|
||||
$auth_request = $consumer->begin($openid_url);
|
||||
|
||||
// Handle failure status return values.
|
||||
if (!$auth_request) {
|
||||
return _('Not a valid OpenID.');
|
||||
} else if (Auth_OpenID::isFailure($auth_request)) {
|
||||
return sprintf(_('OpenID failure: %s'), $auth_request->message);
|
||||
}
|
||||
// Handle failure status return values.
|
||||
if (!$auth_request) {
|
||||
return _('Not a valid OpenID.');
|
||||
} else if (Auth_OpenID::isFailure($auth_request)) {
|
||||
return sprintf(_('OpenID failure: %s'), $auth_request->message);
|
||||
}
|
||||
|
||||
$sreg_request = Auth_OpenID_SRegRequest::build(// Required
|
||||
array(),
|
||||
// Optional
|
||||
array('nickname',
|
||||
'email',
|
||||
'fullname',
|
||||
'language',
|
||||
'timezone',
|
||||
'postcode',
|
||||
'country'));
|
||||
$sreg_request = Auth_OpenID_SRegRequest::build(// Required
|
||||
array(),
|
||||
// Optional
|
||||
array('nickname',
|
||||
'email',
|
||||
'fullname',
|
||||
'language',
|
||||
'timezone',
|
||||
'postcode',
|
||||
'country'));
|
||||
|
||||
if ($sreg_request) {
|
||||
$auth_request->addExtension($sreg_request);
|
||||
}
|
||||
if ($sreg_request) {
|
||||
$auth_request->addExtension($sreg_request);
|
||||
}
|
||||
|
||||
$trust_root = common_local_url('public');
|
||||
$process_url = common_local_url($returnto);
|
||||
$trust_root = common_local_url('public');
|
||||
$process_url = common_local_url($returnto);
|
||||
|
||||
if ($auth_request->shouldSendRedirect()) {
|
||||
$redirect_url = $auth_request->redirectURL($trust_root,
|
||||
$process_url,
|
||||
$immediate);
|
||||
if (!$redirect_url) {
|
||||
} else if (Auth_OpenID::isFailure($redirect_url)) {
|
||||
return sprintf(_('Could not redirect to server: %s'), $redirect_url->message);
|
||||
} else {
|
||||
common_redirect($redirect_url);
|
||||
}
|
||||
} else {
|
||||
// Generate form markup and render it.
|
||||
$form_id = 'openid_message';
|
||||
$form_html = $auth_request->formMarkup($trust_root, $process_url,
|
||||
$immediate, array('id' => $form_id));
|
||||
if ($auth_request->shouldSendRedirect()) {
|
||||
$redirect_url = $auth_request->redirectURL($trust_root,
|
||||
$process_url,
|
||||
$immediate);
|
||||
if (!$redirect_url) {
|
||||
} else if (Auth_OpenID::isFailure($redirect_url)) {
|
||||
return sprintf(_('Could not redirect to server: %s'), $redirect_url->message);
|
||||
} else {
|
||||
common_redirect($redirect_url);
|
||||
}
|
||||
} else {
|
||||
// Generate form markup and render it.
|
||||
$form_id = 'openid_message';
|
||||
$form_html = $auth_request->formMarkup($trust_root, $process_url,
|
||||
$immediate, array('id' => $form_id));
|
||||
|
||||
# XXX: This is cheap, but things choke if we don't escape ampersands
|
||||
# in the HTML attributes
|
||||
# XXX: This is cheap, but things choke if we don't escape ampersands
|
||||
# in the HTML attributes
|
||||
|
||||
$form_html = preg_replace('/&/', '&', $form_html);
|
||||
$form_html = preg_replace('/&/', '&', $form_html);
|
||||
|
||||
// Display an error if the form markup couldn't be generated;
|
||||
// otherwise, render the HTML.
|
||||
if (Auth_OpenID::isFailure($form_html)) {
|
||||
$this->show_form(sprintf(_('Could not create OpenID form: %s'), $form_html->message));
|
||||
} else {
|
||||
common_show_header(_('OpenID Auto-Submit'), NULL, NULL, '_oid_print_instructions');
|
||||
common_raw($form_html);
|
||||
common_element('script', NULL,
|
||||
'$(document).ready(function() { ' .
|
||||
' $("#'. $form_id .'").submit(); '.
|
||||
'});');
|
||||
common_show_footer();
|
||||
}
|
||||
}
|
||||
// Display an error if the form markup couldn't be generated;
|
||||
// otherwise, render the HTML.
|
||||
if (Auth_OpenID::isFailure($form_html)) {
|
||||
$this->show_form(sprintf(_('Could not create OpenID form: %s'), $form_html->message));
|
||||
} else {
|
||||
common_show_header(_('OpenID Auto-Submit'), NULL, NULL, '_oid_print_instructions');
|
||||
common_raw($form_html);
|
||||
common_element('script', NULL,
|
||||
'$(document).ready(function() { ' .
|
||||
' $("#'. $form_id .'").submit(); '.
|
||||
'});');
|
||||
common_show_footer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Half-assed attempt at a module-private function
|
||||
|
||||
function _oid_print_instructions() {
|
||||
common_element('div', 'instructions',
|
||||
_('This form should automatically submit itself. '.
|
||||
'If not, click the submit button to go to your '.
|
||||
'OpenID provider.'));
|
||||
common_element('div', 'instructions',
|
||||
_('This form should automatically submit itself. '.
|
||||
'If not, click the submit button to go to your '.
|
||||
'OpenID provider.'));
|
||||
}
|
||||
|
||||
# update a user from sreg parameters
|
||||
|
||||
function oid_update_user(&$user, &$sreg) {
|
||||
|
||||
$profile = $user->getProfile();
|
||||
$profile = $user->getProfile();
|
||||
|
||||
$orig_profile = clone($profile);
|
||||
$orig_profile = clone($profile);
|
||||
|
||||
if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
|
||||
$profile->fullname = $sreg['fullname'];
|
||||
}
|
||||
if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
|
||||
$profile->fullname = $sreg['fullname'];
|
||||
}
|
||||
|
||||
if ($sreg['country']) {
|
||||
if ($sreg['postcode']) {
|
||||
# XXX: use postcode to get city and region
|
||||
# XXX: also, store postcode somewhere -- it's valuable!
|
||||
$profile->location = $sreg['postcode'] . ', ' . $sreg['country'];
|
||||
} else {
|
||||
$profile->location = $sreg['country'];
|
||||
}
|
||||
}
|
||||
if ($sreg['country']) {
|
||||
if ($sreg['postcode']) {
|
||||
# XXX: use postcode to get city and region
|
||||
# XXX: also, store postcode somewhere -- it's valuable!
|
||||
$profile->location = $sreg['postcode'] . ', ' . $sreg['country'];
|
||||
} else {
|
||||
$profile->location = $sreg['country'];
|
||||
}
|
||||
}
|
||||
|
||||
# XXX save language if it's passed
|
||||
# XXX save timezone if it's passed
|
||||
# XXX save language if it's passed
|
||||
# XXX save timezone if it's passed
|
||||
|
||||
if (!$profile->update($orig_profile)) {
|
||||
common_server_error(_('Error saving the profile.'));
|
||||
return false;
|
||||
}
|
||||
if (!$profile->update($orig_profile)) {
|
||||
common_server_error(_('Error saving the profile.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$orig_user = clone($user);
|
||||
$orig_user = clone($user);
|
||||
|
||||
if ($sreg['email'] && Validate::email($sreg['email'], true)) {
|
||||
$user->email = $sreg['email'];
|
||||
}
|
||||
if ($sreg['email'] && Validate::email($sreg['email'], true)) {
|
||||
$user->email = $sreg['email'];
|
||||
}
|
||||
|
||||
if (!$user->update($orig_user)) {
|
||||
common_server_error(_('Error saving the user.'));
|
||||
return false;
|
||||
}
|
||||
if (!$user->update($orig_user)) {
|
||||
common_server_error(_('Error saving the user.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,187 +20,187 @@
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
class PersonalAction extends Action {
|
||||
|
||||
function is_readonly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
common_set_returnto($this->self_url());
|
||||
}
|
||||
|
||||
function is_readonly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
common_set_returnto($this->self_url());
|
||||
}
|
||||
|
||||
function views_menu() {
|
||||
function views_menu() {
|
||||
|
||||
$user = NULL;
|
||||
$action = $this->trimmed('action');
|
||||
$nickname = $this->trimmed('nickname');
|
||||
$user = NULL;
|
||||
$action = $this->trimmed('action');
|
||||
$nickname = $this->trimmed('nickname');
|
||||
|
||||
if ($nickname) {
|
||||
$user = User::staticGet('nickname', $nickname);
|
||||
$user_profile = $user->getProfile();
|
||||
} else {
|
||||
$user_profile = false;
|
||||
}
|
||||
if ($nickname) {
|
||||
$user = User::staticGet('nickname', $nickname);
|
||||
$user_profile = $user->getProfile();
|
||||
} else {
|
||||
$user_profile = false;
|
||||
}
|
||||
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
|
||||
common_menu_item(common_local_url('all', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Personal'),
|
||||
sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
|
||||
$action == 'all');
|
||||
common_menu_item(common_local_url('replies', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Replies'),
|
||||
sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
|
||||
$action == 'replies');
|
||||
common_menu_item(common_local_url('showstream', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Profile'),
|
||||
($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname,
|
||||
$action == 'showstream');
|
||||
common_menu_item(common_local_url('showfavorites', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Favorites'),
|
||||
sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')),
|
||||
$action == 'showfavorites');
|
||||
|
||||
$cur = common_current_user();
|
||||
|
||||
if ($cur && $cur->id == $user->id) {
|
||||
|
||||
common_menu_item(common_local_url('inbox', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Inbox'),
|
||||
_('Your incoming messages'),
|
||||
$action == 'inbox');
|
||||
common_menu_item(common_local_url('outbox', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Outbox'),
|
||||
_('Your sent messages'),
|
||||
$action == 'outbox');
|
||||
}
|
||||
|
||||
common_element_end('ul');
|
||||
}
|
||||
common_menu_item(common_local_url('all', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Personal'),
|
||||
sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
|
||||
$action == 'all');
|
||||
common_menu_item(common_local_url('replies', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Replies'),
|
||||
sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
|
||||
$action == 'replies');
|
||||
common_menu_item(common_local_url('showstream', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Profile'),
|
||||
($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname,
|
||||
$action == 'showstream');
|
||||
common_menu_item(common_local_url('showfavorites', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Favorites'),
|
||||
sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')),
|
||||
$action == 'showfavorites');
|
||||
|
||||
$cur = common_current_user();
|
||||
|
||||
if ($cur && $cur->id == $user->id) {
|
||||
|
||||
common_menu_item(common_local_url('inbox', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Inbox'),
|
||||
_('Your incoming messages'),
|
||||
$action == 'inbox');
|
||||
common_menu_item(common_local_url('outbox', array('nickname' =>
|
||||
$nickname)),
|
||||
_('Outbox'),
|
||||
_('Your sent messages'),
|
||||
$action == 'outbox');
|
||||
}
|
||||
|
||||
common_element_end('ul');
|
||||
}
|
||||
|
||||
function show_feeds_list($feeds) {
|
||||
common_element_start('div', array('class' => 'feeds'));
|
||||
common_element('p', null, 'Feeds:');
|
||||
common_element_start('ul', array('class' => 'xoxo'));
|
||||
function show_feeds_list($feeds) {
|
||||
common_element_start('div', array('class' => 'feeds'));
|
||||
common_element('p', null, 'Feeds:');
|
||||
common_element_start('ul', array('class' => 'xoxo'));
|
||||
|
||||
foreach ($feeds as $key => $value) {
|
||||
$this->common_feed_item($feeds[$key]);
|
||||
}
|
||||
common_element_end('ul');
|
||||
common_element_end('div');
|
||||
}
|
||||
foreach ($feeds as $key => $value) {
|
||||
$this->common_feed_item($feeds[$key]);
|
||||
}
|
||||
common_element_end('ul');
|
||||
common_element_end('div');
|
||||
}
|
||||
|
||||
function common_feed_item($feed) {
|
||||
$nickname = $this->trimmed('nickname');
|
||||
function common_feed_item($feed) {
|
||||
$nickname = $this->trimmed('nickname');
|
||||
|
||||
switch($feed['item']) {
|
||||
case 'notices': default:
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "$nickname's ".$feed['version']." notice feed";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
switch($feed['item']) {
|
||||
case 'notices': default:
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "$nickname's ".$feed['version']." notice feed";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'allrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = $feed['version']." feed for $nickname and friends";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
case 'allrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = $feed['version']." feed for $nickname and friends";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'repliesrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = $feed['version']." feed for replies to $nickname";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
case 'repliesrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = $feed['version']." feed for replies to $nickname";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'publicrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Public timeline ".$feed['version']." feed";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
case 'publicrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Public timeline ".$feed['version']." feed";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'publicatom':
|
||||
$feed_classname = "atom";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Public timeline ".$feed['version']." feed";
|
||||
$feed['textContent'] = "Atom";
|
||||
break;
|
||||
case 'publicatom':
|
||||
$feed_classname = "atom";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Public timeline ".$feed['version']." feed";
|
||||
$feed['textContent'] = "Atom";
|
||||
break;
|
||||
|
||||
case 'tagrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = $feed['version']." feed for this tag";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
case 'tagrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = $feed['version']." feed for this tag";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'favoritedrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Favorited ".$feed['version']." feed";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
case 'favoritedrss':
|
||||
$feed_classname = $feed['type'];
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Favorited ".$feed['version']." feed";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'foaf':
|
||||
$feed_classname = "foaf";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "$nickname's FOAF file";
|
||||
$feed['textContent'] = "FOAF";
|
||||
break;
|
||||
case 'foaf':
|
||||
$feed_classname = "foaf";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "$nickname's FOAF file";
|
||||
$feed['textContent'] = "FOAF";
|
||||
break;
|
||||
|
||||
case 'favoritesrss':
|
||||
$feed_classname = "favorites";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Feed for favorites of $nickname";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
case 'favoritesrss':
|
||||
$feed_classname = "favorites";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "Feed for favorites of $nickname";
|
||||
$feed['textContent'] = "RSS";
|
||||
break;
|
||||
|
||||
case 'usertimeline':
|
||||
$feed_classname = "atom";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "$nickname's ".$feed['version']." notice feed";
|
||||
$feed['textContent'] = "Atom";
|
||||
break;
|
||||
}
|
||||
common_element_start('li');
|
||||
common_element('a', array('href' => $feed['href'],
|
||||
'class' => $feed_classname,
|
||||
'type' => $feed_mimetype,
|
||||
'title' => $feed_title),
|
||||
$feed['textContent']);
|
||||
common_element_end('li');
|
||||
}
|
||||
case 'usertimeline':
|
||||
$feed_classname = "atom";
|
||||
$feed_mimetype = "application/".$feed['type']."+xml";
|
||||
$feed_title = "$nickname's ".$feed['version']." notice feed";
|
||||
$feed['textContent'] = "Atom";
|
||||
break;
|
||||
}
|
||||
common_element_start('li');
|
||||
common_element('a', array('href' => $feed['href'],
|
||||
'class' => $feed_classname,
|
||||
'type' => $feed_mimetype,
|
||||
'title' => $feed_title),
|
||||
$feed['textContent']);
|
||||
common_element_end('li');
|
||||
}
|
||||
|
||||
|
||||
function source_link($source) {
|
||||
$source_name = _($source);
|
||||
switch ($source) {
|
||||
case 'web':
|
||||
case 'xmpp':
|
||||
case 'mail':
|
||||
case 'omb':
|
||||
case 'api':
|
||||
common_element('span', 'noticesource', $source_name);
|
||||
break;
|
||||
default:
|
||||
$ns = Notice_source::staticGet($source);
|
||||
if ($ns) {
|
||||
common_element('a', array('href' => $ns->url),
|
||||
$ns->name);
|
||||
} else {
|
||||
common_element('span', 'noticesource', $source_name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function source_link($source) {
|
||||
$source_name = _($source);
|
||||
switch ($source) {
|
||||
case 'web':
|
||||
case 'xmpp':
|
||||
case 'mail':
|
||||
case 'omb':
|
||||
case 'api':
|
||||
common_element('span', 'noticesource', $source_name);
|
||||
break;
|
||||
default:
|
||||
$ns = Notice_source::staticGet($source);
|
||||
if ($ns) {
|
||||
common_element('a', array('href' => $ns->url),
|
||||
$ns->name);
|
||||
} else {
|
||||
common_element('span', 'noticesource', $source_name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,138 +24,138 @@ define('PROFILES_PER_PAGE', 20);
|
||||
|
||||
class ProfileList {
|
||||
|
||||
var $profile = NULL;
|
||||
var $owner = NULL;
|
||||
var $action = NULL;
|
||||
var $profile = NULL;
|
||||
var $owner = NULL;
|
||||
var $action = NULL;
|
||||
|
||||
function __construct($profile, $owner=NULL, $action=NULL) {
|
||||
$this->profile = $profile;
|
||||
$this->owner = $owner;
|
||||
$this->action = $action;
|
||||
}
|
||||
function __construct($profile, $owner=NULL, $action=NULL) {
|
||||
$this->profile = $profile;
|
||||
$this->owner = $owner;
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
function show_list() {
|
||||
function show_list() {
|
||||
|
||||
common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list'));
|
||||
common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list'));
|
||||
|
||||
$cnt = 0;
|
||||
$cnt = 0;
|
||||
|
||||
while ($this->profile->fetch()) {
|
||||
$cnt++;
|
||||
if($cnt > PROFILES_PER_PAGE) {
|
||||
break;
|
||||
}
|
||||
$this->show();
|
||||
}
|
||||
while ($this->profile->fetch()) {
|
||||
$cnt++;
|
||||
if($cnt > PROFILES_PER_PAGE) {
|
||||
break;
|
||||
}
|
||||
$this->show();
|
||||
}
|
||||
|
||||
common_element_end('ul');
|
||||
common_element_end('ul');
|
||||
|
||||
return $cnt;
|
||||
}
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
function show() {
|
||||
function show() {
|
||||
|
||||
common_element_start('li', array('class' => 'profile_single',
|
||||
'id' => 'profile-' . $this->profile->id));
|
||||
common_element_start('li', array('class' => 'profile_single',
|
||||
'id' => 'profile-' . $this->profile->id));
|
||||
|
||||
$user = common_current_user();
|
||||
$user = common_current_user();
|
||||
|
||||
if ($user && $user->id != $this->profile->id) {
|
||||
# XXX: special-case for user looking at own
|
||||
# subscriptions page
|
||||
if ($user->isSubscribed($this->profile)) {
|
||||
common_unsubscribe_form($this->profile);
|
||||
} else {
|
||||
common_subscribe_form($this->profile);
|
||||
}
|
||||
}
|
||||
if ($user && $user->id != $this->profile->id) {
|
||||
# XXX: special-case for user looking at own
|
||||
# subscriptions page
|
||||
if ($user->isSubscribed($this->profile)) {
|
||||
common_unsubscribe_form($this->profile);
|
||||
} else {
|
||||
common_subscribe_form($this->profile);
|
||||
}
|
||||
}
|
||||
|
||||
$avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
|
||||
common_element_start('a', array('href' => $this->profile->profileurl));
|
||||
common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
|
||||
'class' => 'avatar stream',
|
||||
'width' => AVATAR_STREAM_SIZE,
|
||||
'height' => AVATAR_STREAM_SIZE,
|
||||
'alt' =>
|
||||
($this->profile->fullname) ? $this->profile->fullname :
|
||||
$this->profile->nickname));
|
||||
common_element_end('a');
|
||||
common_element_start('p');
|
||||
common_element_start('a', array('href' => $this->profile->profileurl,
|
||||
'class' => 'nickname'));
|
||||
common_raw($this->highlight($this->profile->nickname));
|
||||
common_element_end('a');
|
||||
if ($this->profile->fullname) {
|
||||
common_text(' | ');
|
||||
common_element_start('span', 'fullname');
|
||||
common_raw($this->highlight($this->profile->fullname));
|
||||
common_element_end('span');
|
||||
}
|
||||
if ($this->profile->location) {
|
||||
common_text(' | ');
|
||||
common_element_start('span', 'location');
|
||||
common_raw($this->highlight($this->profile->location));
|
||||
common_element_end('span');
|
||||
}
|
||||
common_element_end('p');
|
||||
if ($this->profile->homepage) {
|
||||
common_element_start('p', 'website');
|
||||
common_element_start('a', array('href' => $this->profile->homepage));
|
||||
common_raw($this->highlight($this->profile->homepage));
|
||||
common_element_end('a');
|
||||
common_element_end('p');
|
||||
}
|
||||
if ($this->profile->bio) {
|
||||
common_element_start('p', 'bio');
|
||||
common_raw($this->highlight($this->profile->bio));
|
||||
common_element_end('p');
|
||||
}
|
||||
$avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
|
||||
common_element_start('a', array('href' => $this->profile->profileurl));
|
||||
common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
|
||||
'class' => 'avatar stream',
|
||||
'width' => AVATAR_STREAM_SIZE,
|
||||
'height' => AVATAR_STREAM_SIZE,
|
||||
'alt' =>
|
||||
($this->profile->fullname) ? $this->profile->fullname :
|
||||
$this->profile->nickname));
|
||||
common_element_end('a');
|
||||
common_element_start('p');
|
||||
common_element_start('a', array('href' => $this->profile->profileurl,
|
||||
'class' => 'nickname'));
|
||||
common_raw($this->highlight($this->profile->nickname));
|
||||
common_element_end('a');
|
||||
if ($this->profile->fullname) {
|
||||
common_text(' | ');
|
||||
common_element_start('span', 'fullname');
|
||||
common_raw($this->highlight($this->profile->fullname));
|
||||
common_element_end('span');
|
||||
}
|
||||
if ($this->profile->location) {
|
||||
common_text(' | ');
|
||||
common_element_start('span', 'location');
|
||||
common_raw($this->highlight($this->profile->location));
|
||||
common_element_end('span');
|
||||
}
|
||||
common_element_end('p');
|
||||
if ($this->profile->homepage) {
|
||||
common_element_start('p', 'website');
|
||||
common_element_start('a', array('href' => $this->profile->homepage));
|
||||
common_raw($this->highlight($this->profile->homepage));
|
||||
common_element_end('a');
|
||||
common_element_end('p');
|
||||
}
|
||||
if ($this->profile->bio) {
|
||||
common_element_start('p', 'bio');
|
||||
common_raw($this->highlight($this->profile->bio));
|
||||
common_element_end('p');
|
||||
}
|
||||
|
||||
# If we're on a list with an owner (subscriptions or subscribers)...
|
||||
# If we're on a list with an owner (subscriptions or subscribers)...
|
||||
|
||||
if ($this->owner) {
|
||||
# Get tags
|
||||
$tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
|
||||
if ($this->owner) {
|
||||
# Get tags
|
||||
$tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
|
||||
|
||||
common_element_start('div', 'tags_user');
|
||||
common_element_start('dl');
|
||||
common_element_start('dt');
|
||||
if ($user->id == $this->owner->id) {
|
||||
common_element('a', array('href' => common_local_url('tagother',
|
||||
array('id' => $this->profile->id))),
|
||||
_('Tags'));
|
||||
} else {
|
||||
common_text(_('Tags'));
|
||||
}
|
||||
common_text(":");
|
||||
common_element_end('dt');
|
||||
common_element_start('dd');
|
||||
if ($tags) {
|
||||
common_element_start('ul', 'tags xoxo');
|
||||
foreach ($tags as $tag) {
|
||||
common_element_start('li');
|
||||
common_element('a', array('rel' => 'tag',
|
||||
'href' => common_local_url($this->action,
|
||||
array('nickname' => $this->owner->nickname,
|
||||
'tag' => $tag))),
|
||||
$tag);
|
||||
common_element_end('li');
|
||||
}
|
||||
common_element_end('ul');
|
||||
} else {
|
||||
common_text(_('(none)'));
|
||||
}
|
||||
common_element_end('dd');
|
||||
common_element_end('dl');
|
||||
common_element_end('div');
|
||||
}
|
||||
common_element_start('div', 'tags_user');
|
||||
common_element_start('dl');
|
||||
common_element_start('dt');
|
||||
if ($user->id == $this->owner->id) {
|
||||
common_element('a', array('href' => common_local_url('tagother',
|
||||
array('id' => $this->profile->id))),
|
||||
_('Tags'));
|
||||
} else {
|
||||
common_text(_('Tags'));
|
||||
}
|
||||
common_text(":");
|
||||
common_element_end('dt');
|
||||
common_element_start('dd');
|
||||
if ($tags) {
|
||||
common_element_start('ul', 'tags xoxo');
|
||||
foreach ($tags as $tag) {
|
||||
common_element_start('li');
|
||||
common_element('a', array('rel' => 'tag',
|
||||
'href' => common_local_url($this->action,
|
||||
array('nickname' => $this->owner->nickname,
|
||||
'tag' => $tag))),
|
||||
$tag);
|
||||
common_element_end('li');
|
||||
}
|
||||
common_element_end('ul');
|
||||
} else {
|
||||
common_text(_('(none)'));
|
||||
}
|
||||
common_element_end('dd');
|
||||
common_element_end('dl');
|
||||
common_element_end('div');
|
||||
}
|
||||
|
||||
if ($user && $user->id == $this->owner->id) {
|
||||
$this->show_owner_controls($this->profile);
|
||||
}
|
||||
|
||||
common_element_end('li');
|
||||
}
|
||||
common_element_end('li');
|
||||
}
|
||||
|
||||
/* Override this in subclasses. */
|
||||
|
||||
@@ -163,7 +163,7 @@ class ProfileList {
|
||||
return;
|
||||
}
|
||||
|
||||
function highlight($text) {
|
||||
return htmlspecialchars($text);
|
||||
}
|
||||
function highlight($text) {
|
||||
return htmlspecialchars($text);
|
||||
}
|
||||
}
|
||||
@@ -27,106 +27,106 @@ require_once(INSTALLDIR.'/classes/Notice.php');
|
||||
|
||||
class QueueHandler extends Daemon {
|
||||
|
||||
var $_id = 'generic';
|
||||
var $_id = 'generic';
|
||||
|
||||
function QueueHandler($id=NULL) {
|
||||
if ($id) {
|
||||
$this->set_id($id);
|
||||
}
|
||||
}
|
||||
|
||||
function class_name() {
|
||||
return ucfirst($this->transport()) . 'Handler';
|
||||
}
|
||||
function QueueHandler($id=NULL) {
|
||||
if ($id) {
|
||||
$this->set_id($id);
|
||||
}
|
||||
}
|
||||
|
||||
function class_name() {
|
||||
return ucfirst($this->transport()) . 'Handler';
|
||||
}
|
||||
|
||||
function name() {
|
||||
return strtolower($this->class_name().'.'.$this->get_id());
|
||||
}
|
||||
|
||||
function get_id() {
|
||||
return $this->_id;
|
||||
}
|
||||
function name() {
|
||||
return strtolower($this->class_name().'.'.$this->get_id());
|
||||
}
|
||||
|
||||
function get_id() {
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
function set_id($id) {
|
||||
$this->_id = $id;
|
||||
}
|
||||
|
||||
function transport() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function start() {
|
||||
}
|
||||
|
||||
function finish() {
|
||||
}
|
||||
function set_id($id) {
|
||||
$this->_id = $id;
|
||||
}
|
||||
|
||||
function transport() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function start() {
|
||||
}
|
||||
|
||||
function finish() {
|
||||
}
|
||||
|
||||
function handle_notice($notice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function run() {
|
||||
if (!$this->start()) {
|
||||
return false;
|
||||
}
|
||||
$this->log(LOG_INFO, 'checking for queued notices');
|
||||
$transport = $this->transport();
|
||||
do {
|
||||
$qi = Queue_item::top($transport);
|
||||
if ($qi) {
|
||||
$this->log(LOG_INFO, 'Got item enqueued '.common_exact_date($qi->created));
|
||||
$notice = Notice::staticGet($qi->notice_id);
|
||||
if ($notice) {
|
||||
$this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id);
|
||||
# XXX: what to do if broadcast fails?
|
||||
$result = $this->handle_notice($notice);
|
||||
if (!$result) {
|
||||
$this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id);
|
||||
$orig = $qi;
|
||||
$qi->claimed = NULL;
|
||||
$qi->update($orig);
|
||||
$this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id);
|
||||
continue;
|
||||
}
|
||||
$this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id);
|
||||
$notice->free();
|
||||
unset($notice);
|
||||
$notice = NULL;
|
||||
} else {
|
||||
$this->log(LOG_WARNING, 'queue item for notice that does not exist');
|
||||
}
|
||||
$qi->delete();
|
||||
$qi->free();
|
||||
unset($qi);
|
||||
$this->idle(0);
|
||||
} else {
|
||||
$this->clear_old_claims();
|
||||
$this->idle(5);
|
||||
}
|
||||
} while (true);
|
||||
if (!$this->finish()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function handle_notice($notice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function run() {
|
||||
if (!$this->start()) {
|
||||
return false;
|
||||
}
|
||||
$this->log(LOG_INFO, 'checking for queued notices');
|
||||
$transport = $this->transport();
|
||||
do {
|
||||
$qi = Queue_item::top($transport);
|
||||
if ($qi) {
|
||||
$this->log(LOG_INFO, 'Got item enqueued '.common_exact_date($qi->created));
|
||||
$notice = Notice::staticGet($qi->notice_id);
|
||||
if ($notice) {
|
||||
$this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id);
|
||||
# XXX: what to do if broadcast fails?
|
||||
$result = $this->handle_notice($notice);
|
||||
if (!$result) {
|
||||
$this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id);
|
||||
$orig = $qi;
|
||||
$qi->claimed = NULL;
|
||||
$qi->update($orig);
|
||||
$this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id);
|
||||
continue;
|
||||
}
|
||||
$this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id);
|
||||
$notice->free();
|
||||
unset($notice);
|
||||
$notice = NULL;
|
||||
} else {
|
||||
$this->log(LOG_WARNING, 'queue item for notice that does not exist');
|
||||
}
|
||||
$qi->delete();
|
||||
$qi->free();
|
||||
unset($qi);
|
||||
$this->idle(0);
|
||||
} else {
|
||||
$this->clear_old_claims();
|
||||
$this->idle(5);
|
||||
}
|
||||
} while (true);
|
||||
if (!$this->finish()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function idle($timeout=0) {
|
||||
if ($timeout>0) {
|
||||
sleep($timeout);
|
||||
}
|
||||
}
|
||||
|
||||
function clear_old_claims() {
|
||||
$qi = new Queue_item();
|
||||
$qi->transport = $this->transport();
|
||||
$qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
|
||||
$qi->update(DB_DATAOBJECT_WHEREADD_ONLY);
|
||||
$qi->free();
|
||||
unset($qi);
|
||||
}
|
||||
|
||||
function log($level, $msg) {
|
||||
common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg);
|
||||
}
|
||||
function idle($timeout=0) {
|
||||
if ($timeout>0) {
|
||||
sleep($timeout);
|
||||
}
|
||||
}
|
||||
|
||||
function clear_old_claims() {
|
||||
$qi = new Queue_item();
|
||||
$qi->transport = $this->transport();
|
||||
$qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
|
||||
$qi->update(DB_DATAOBJECT_WHEREADD_ONLY);
|
||||
$qi->free();
|
||||
unset($qi);
|
||||
}
|
||||
|
||||
function log($level, $msg) {
|
||||
common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,167 +23,167 @@ define('DEFAULT_RSS_LIMIT', 48);
|
||||
|
||||
class Rss10Action extends Action {
|
||||
|
||||
# This will contain the details of each feed item's author and be used to generate SIOC data.
|
||||
var $creators = array();
|
||||
# This will contain the details of each feed item's author and be used to generate SIOC data.
|
||||
var $creators = array();
|
||||
|
||||
function is_readonly() {
|
||||
return true;
|
||||
}
|
||||
function is_readonly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
$limit = (int) $this->trimmed('limit');
|
||||
if ($limit == 0) {
|
||||
$limit = DEFAULT_RSS_LIMIT;
|
||||
}
|
||||
$this->show_rss($limit);
|
||||
}
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
$limit = (int) $this->trimmed('limit');
|
||||
if ($limit == 0) {
|
||||
$limit = DEFAULT_RSS_LIMIT;
|
||||
}
|
||||
$this->show_rss($limit);
|
||||
}
|
||||
|
||||
function init() {
|
||||
return true;
|
||||
}
|
||||
function init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_notices() {
|
||||
return array();
|
||||
}
|
||||
function get_notices() {
|
||||
return array();
|
||||
}
|
||||
|
||||
function get_channel() {
|
||||
return array('url' => '',
|
||||
'title' => '',
|
||||
'link' => '',
|
||||
'description' => '');
|
||||
}
|
||||
function get_channel() {
|
||||
return array('url' => '',
|
||||
'title' => '',
|
||||
'link' => '',
|
||||
'description' => '');
|
||||
}
|
||||
|
||||
function get_image() {
|
||||
return NULL;
|
||||
}
|
||||
function get_image() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function show_rss($limit=0) {
|
||||
function show_rss($limit=0) {
|
||||
|
||||
if (!$this->init()) {
|
||||
return;
|
||||
}
|
||||
if (!$this->init()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notices = $this->get_notices($limit);
|
||||
$notices = $this->get_notices($limit);
|
||||
|
||||
$this->init_rss();
|
||||
$this->show_channel($notices);
|
||||
$this->show_image();
|
||||
$this->init_rss();
|
||||
$this->show_channel($notices);
|
||||
$this->show_image();
|
||||
|
||||
foreach ($notices as $n) {
|
||||
$this->show_item($n);
|
||||
}
|
||||
foreach ($notices as $n) {
|
||||
$this->show_item($n);
|
||||
}
|
||||
|
||||
$this->show_creators();
|
||||
$this->end_rss();
|
||||
}
|
||||
$this->show_creators();
|
||||
$this->end_rss();
|
||||
}
|
||||
|
||||
function show_channel($notices) {
|
||||
function show_channel($notices) {
|
||||
|
||||
$channel = $this->get_channel();
|
||||
$image = $this->get_image();
|
||||
$channel = $this->get_channel();
|
||||
$image = $this->get_image();
|
||||
|
||||
common_element_start('channel', array('rdf:about' => $channel['url']));
|
||||
common_element('title', NULL, $channel['title']);
|
||||
common_element('link', NULL, $channel['link']);
|
||||
common_element('description', NULL, $channel['description']);
|
||||
common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
|
||||
common_element_start('channel', array('rdf:about' => $channel['url']));
|
||||
common_element('title', NULL, $channel['title']);
|
||||
common_element('link', NULL, $channel['link']);
|
||||
common_element('description', NULL, $channel['description']);
|
||||
common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
|
||||
|
||||
if ($image) {
|
||||
common_element('image', array('rdf:resource' => $image));
|
||||
}
|
||||
if ($image) {
|
||||
common_element('image', array('rdf:resource' => $image));
|
||||
}
|
||||
|
||||
common_element_start('items');
|
||||
common_element_start('rdf:Seq');
|
||||
common_element_start('items');
|
||||
common_element_start('rdf:Seq');
|
||||
|
||||
foreach ($notices as $notice) {
|
||||
common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
|
||||
}
|
||||
foreach ($notices as $notice) {
|
||||
common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
|
||||
}
|
||||
|
||||
common_element_end('rdf:Seq');
|
||||
common_element_end('items');
|
||||
common_element_end('rdf:Seq');
|
||||
common_element_end('items');
|
||||
|
||||
common_element_end('channel');
|
||||
}
|
||||
common_element_end('channel');
|
||||
}
|
||||
|
||||
function show_image() {
|
||||
$image = $this->get_image();
|
||||
if ($image) {
|
||||
$channel = $this->get_channel();
|
||||
common_element_start('image', array('rdf:about' => $image));
|
||||
common_element('title', NULL, $channel['title']);
|
||||
common_element('link', NULL, $channel['link']);
|
||||
common_element('url', NULL, $image);
|
||||
common_element_end('image');
|
||||
}
|
||||
}
|
||||
function show_image() {
|
||||
$image = $this->get_image();
|
||||
if ($image) {
|
||||
$channel = $this->get_channel();
|
||||
common_element_start('image', array('rdf:about' => $image));
|
||||
common_element('title', NULL, $channel['title']);
|
||||
common_element('link', NULL, $channel['link']);
|
||||
common_element('url', NULL, $image);
|
||||
common_element_end('image');
|
||||
}
|
||||
}
|
||||
|
||||
function show_item($notice) {
|
||||
$profile = Profile::staticGet($notice->profile_id);
|
||||
$nurl = common_local_url('shownotice', array('notice' => $notice->id));
|
||||
$creator_uri = common_profile_uri($profile);
|
||||
common_element_start('item', array('rdf:about' => $notice->uri));
|
||||
$title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
|
||||
common_element('title', NULL, $title);
|
||||
common_element('link', NULL, $nurl);
|
||||
common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
|
||||
common_element('dc:date', NULL, common_date_w3dtf($notice->created));
|
||||
common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
|
||||
common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
|
||||
common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
|
||||
common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
|
||||
common_element_end('item');
|
||||
$this->creators[$creator_uri] = $profile;
|
||||
}
|
||||
function show_item($notice) {
|
||||
$profile = Profile::staticGet($notice->profile_id);
|
||||
$nurl = common_local_url('shownotice', array('notice' => $notice->id));
|
||||
$creator_uri = common_profile_uri($profile);
|
||||
common_element_start('item', array('rdf:about' => $notice->uri));
|
||||
$title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
|
||||
common_element('title', NULL, $title);
|
||||
common_element('link', NULL, $nurl);
|
||||
common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
|
||||
common_element('dc:date', NULL, common_date_w3dtf($notice->created));
|
||||
common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
|
||||
common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
|
||||
common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
|
||||
common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
|
||||
common_element_end('item');
|
||||
$this->creators[$creator_uri] = $profile;
|
||||
}
|
||||
|
||||
function show_creators() {
|
||||
foreach ($this->creators as $uri => $profile) {
|
||||
$id = $profile->id;
|
||||
$nickname = $profile->nickname;
|
||||
common_element_start('sioc:User', array('rdf:about' => $uri));
|
||||
common_element('foaf:nick', NULL, $nickname);
|
||||
if ($profile->fullname) {
|
||||
common_element('foaf:name', NULL, $profile->fullname);
|
||||
}
|
||||
common_element('sioc:id', NULL, $id);
|
||||
$avatar = common_profile_avatar_url($profile);
|
||||
common_element('sioc:avatar', array('rdf:resource' => $avatar));
|
||||
common_element_end('sioc:User');
|
||||
}
|
||||
}
|
||||
function show_creators() {
|
||||
foreach ($this->creators as $uri => $profile) {
|
||||
$id = $profile->id;
|
||||
$nickname = $profile->nickname;
|
||||
common_element_start('sioc:User', array('rdf:about' => $uri));
|
||||
common_element('foaf:nick', NULL, $nickname);
|
||||
if ($profile->fullname) {
|
||||
common_element('foaf:name', NULL, $profile->fullname);
|
||||
}
|
||||
common_element('sioc:id', NULL, $id);
|
||||
$avatar = common_profile_avatar_url($profile);
|
||||
common_element('sioc:avatar', array('rdf:resource' => $avatar));
|
||||
common_element_end('sioc:User');
|
||||
}
|
||||
}
|
||||
|
||||
function init_rss() {
|
||||
$channel = $this->get_channel();
|
||||
header('Content-Type: application/rdf+xml');
|
||||
function init_rss() {
|
||||
$channel = $this->get_channel();
|
||||
header('Content-Type: application/rdf+xml');
|
||||
|
||||
common_start_xml();
|
||||
common_element_start('rdf:RDF', array('xmlns:rdf' =>
|
||||
'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
||||
'xmlns:dc' =>
|
||||
'http://purl.org/dc/elements/1.1/',
|
||||
'xmlns:cc' =>
|
||||
'http://web.resource.org/cc/',
|
||||
common_start_xml();
|
||||
common_element_start('rdf:RDF', array('xmlns:rdf' =>
|
||||
'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
||||
'xmlns:dc' =>
|
||||
'http://purl.org/dc/elements/1.1/',
|
||||
'xmlns:cc' =>
|
||||
'http://web.resource.org/cc/',
|
||||
'xmlns:content' =>
|
||||
'http://purl.org/rss/1.0/modules/content/',
|
||||
'xmlns:foaf' =>
|
||||
'http://xmlns.com/foaf/0.1/',
|
||||
'xmlns:sioc' =>
|
||||
'http://rdfs.org/sioc/ns#',
|
||||
'xmlns:sioct' =>
|
||||
'http://rdfs.org/sioc/types#',
|
||||
'xmlns:laconica' =>
|
||||
'http://laconi.ca/ont/',
|
||||
'xmlns' => 'http://purl.org/rss/1.0/'));
|
||||
common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
|
||||
common_element('sioc:name', NULL, common_config('site', 'name'));
|
||||
common_element_start('sioc:container_of');
|
||||
common_element('sioc:Container', array('rdf:about' =>
|
||||
$channel['url']));
|
||||
common_element_end('sioc:container_of');
|
||||
common_element_end('sioc:Site');
|
||||
}
|
||||
'xmlns:foaf' =>
|
||||
'http://xmlns.com/foaf/0.1/',
|
||||
'xmlns:sioc' =>
|
||||
'http://rdfs.org/sioc/ns#',
|
||||
'xmlns:sioct' =>
|
||||
'http://rdfs.org/sioc/types#',
|
||||
'xmlns:laconica' =>
|
||||
'http://laconi.ca/ont/',
|
||||
'xmlns' => 'http://purl.org/rss/1.0/'));
|
||||
common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
|
||||
common_element('sioc:name', NULL, common_config('site', 'name'));
|
||||
common_element_start('sioc:container_of');
|
||||
common_element('sioc:Container', array('rdf:about' =>
|
||||
$channel['url']));
|
||||
common_element_end('sioc:container_of');
|
||||
common_element_end('sioc:Site');
|
||||
}
|
||||
|
||||
function end_rss() {
|
||||
common_element_end('rdf:RDF');
|
||||
}
|
||||
function end_rss() {
|
||||
common_element_end('rdf:RDF');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,10 +98,10 @@ class MySQLSearch extends SearchEngine {
|
||||
function query($q) {
|
||||
if ('identica_people' === $this->table)
|
||||
return $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
|
||||
'against (\''.addslashes($q).'\')');
|
||||
'against (\''.addslashes($q).'\')');
|
||||
if ('identica_notices' === $this->table)
|
||||
return $this->target->whereAdd('MATCH(content) ' .
|
||||
'against (\''.addslashes($q).'\')');
|
||||
'against (\''.addslashes($q).'\')');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,90 +21,90 @@ if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
class SearchAction extends Action {
|
||||
|
||||
function is_readonly() {
|
||||
return true;
|
||||
}
|
||||
function is_readonly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
$this->show_form();
|
||||
}
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
$this->show_form();
|
||||
}
|
||||
|
||||
function show_top($arr=NULL) {
|
||||
if ($arr) {
|
||||
$error = $arr[1];
|
||||
}
|
||||
if ($error) {
|
||||
common_element('p', 'error', $error);
|
||||
} else {
|
||||
$instr = $this->get_instructions();
|
||||
$output = common_markup_to_html($instr);
|
||||
common_element_start('div', 'instructions');
|
||||
common_raw($output);
|
||||
common_element_end('div');
|
||||
}
|
||||
$this->search_menu();
|
||||
}
|
||||
function show_top($arr=NULL) {
|
||||
if ($arr) {
|
||||
$error = $arr[1];
|
||||
}
|
||||
if ($error) {
|
||||
common_element('p', 'error', $error);
|
||||
} else {
|
||||
$instr = $this->get_instructions();
|
||||
$output = common_markup_to_html($instr);
|
||||
common_element_start('div', 'instructions');
|
||||
common_raw($output);
|
||||
common_element_end('div');
|
||||
}
|
||||
$this->search_menu();
|
||||
}
|
||||
|
||||
function get_title() {
|
||||
return NULL;
|
||||
}
|
||||
function get_title() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function show_header($arr) {
|
||||
return;
|
||||
}
|
||||
function show_header($arr) {
|
||||
return;
|
||||
}
|
||||
|
||||
function show_form($error=NULL) {
|
||||
global $config;
|
||||
function show_form($error=NULL) {
|
||||
global $config;
|
||||
|
||||
$q = $this->trimmed('q');
|
||||
$page = $this->trimmed('page', 1);
|
||||
$q = $this->trimmed('q');
|
||||
$page = $this->trimmed('page', 1);
|
||||
|
||||
common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error),
|
||||
array($this, 'show_top'));
|
||||
common_element_start('form', array('method' => 'get',
|
||||
'id' => 'login',
|
||||
'action' => common_local_url($this->trimmed('action'))));
|
||||
common_element_start('p');
|
||||
if (!isset($config['site']['fancy']) || !$config['site']['fancy']) {
|
||||
common_element('input', array('name' => 'action',
|
||||
'type' => 'hidden',
|
||||
'value' => $this->trimmed('action')));
|
||||
}
|
||||
common_element('input', array('name' => 'q',
|
||||
'id' => 'q',
|
||||
'type' => 'text',
|
||||
'class' => 'input_text',
|
||||
'value' => ($q) ? $q : ''));
|
||||
common_text(' ');
|
||||
common_element('input', array('type' => 'submit',
|
||||
'id' => 'search',
|
||||
'name' => 'search',
|
||||
'class' => 'submit',
|
||||
'value' => _('Search')));
|
||||
common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error),
|
||||
array($this, 'show_top'));
|
||||
common_element_start('form', array('method' => 'get',
|
||||
'id' => 'login',
|
||||
'action' => common_local_url($this->trimmed('action'))));
|
||||
common_element_start('p');
|
||||
if (!isset($config['site']['fancy']) || !$config['site']['fancy']) {
|
||||
common_element('input', array('name' => 'action',
|
||||
'type' => 'hidden',
|
||||
'value' => $this->trimmed('action')));
|
||||
}
|
||||
common_element('input', array('name' => 'q',
|
||||
'id' => 'q',
|
||||
'type' => 'text',
|
||||
'class' => 'input_text',
|
||||
'value' => ($q) ? $q : ''));
|
||||
common_text(' ');
|
||||
common_element('input', array('type' => 'submit',
|
||||
'id' => 'search',
|
||||
'name' => 'search',
|
||||
'class' => 'submit',
|
||||
'value' => _('Search')));
|
||||
|
||||
common_element_end('p');
|
||||
common_element_end('form');
|
||||
if ($q) {
|
||||
$this->show_results($q, $page);
|
||||
}
|
||||
common_show_footer();
|
||||
}
|
||||
common_element_end('p');
|
||||
common_element_end('form');
|
||||
if ($q) {
|
||||
$this->show_results($q, $page);
|
||||
}
|
||||
common_show_footer();
|
||||
}
|
||||
|
||||
function search_menu() {
|
||||
# action => array('prompt', 'title', $args)
|
||||
$action = $this->trimmed('action');
|
||||
$menu =
|
||||
array('peoplesearch' =>
|
||||
array(
|
||||
_('People'),
|
||||
_('Find people on this site'),
|
||||
($action != 'peoplesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL),
|
||||
'noticesearch' =>
|
||||
array( _('Text'),
|
||||
_('Find content of notices'),
|
||||
($action != 'noticesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL)
|
||||
);
|
||||
$this->nav_menu($menu);
|
||||
}
|
||||
function search_menu() {
|
||||
# action => array('prompt', 'title', $args)
|
||||
$action = $this->trimmed('action');
|
||||
$menu =
|
||||
array('peoplesearch' =>
|
||||
array(
|
||||
_('People'),
|
||||
_('Find people on this site'),
|
||||
($action != 'peoplesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL),
|
||||
'noticesearch' =>
|
||||
array( _('Text'),
|
||||
_('Find content of notices'),
|
||||
($action != 'noticesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL)
|
||||
);
|
||||
$this->nav_menu($menu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ class SettingsAction extends Action {
|
||||
common_user_error(_('Not logged in.'));
|
||||
return;
|
||||
} else if (!common_is_real_login()) {
|
||||
# Cookie theft means that automatic logins can't
|
||||
# change important settings or see private info, and
|
||||
# _all_ our settings are important
|
||||
# Cookie theft means that automatic logins can't
|
||||
# change important settings or see private info, and
|
||||
# _all_ our settings are important
|
||||
common_set_returnto($this->self_url());
|
||||
common_redirect(common_local_url('login'));
|
||||
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
@@ -55,60 +55,60 @@ class SettingsAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
function form_header($title, $msg=NULL, $success=false) {
|
||||
common_show_header($title,
|
||||
NULL,
|
||||
array($msg, $success),
|
||||
array($this, 'show_top'));
|
||||
}
|
||||
function form_header($title, $msg=NULL, $success=false) {
|
||||
common_show_header($title,
|
||||
NULL,
|
||||
array($msg, $success),
|
||||
array($this, 'show_top'));
|
||||
}
|
||||
|
||||
function show_top($arr) {
|
||||
$msg = $arr[0];
|
||||
$success = $arr[1];
|
||||
if ($msg) {
|
||||
$this->message($msg, $success);
|
||||
} else {
|
||||
$inst = $this->get_instructions();
|
||||
$output = common_markup_to_html($inst);
|
||||
common_element_start('div', 'instructions');
|
||||
common_raw($output);
|
||||
common_element_end('div');
|
||||
}
|
||||
$this->settings_menu();
|
||||
}
|
||||
function show_top($arr) {
|
||||
$msg = $arr[0];
|
||||
$success = $arr[1];
|
||||
if ($msg) {
|
||||
$this->message($msg, $success);
|
||||
} else {
|
||||
$inst = $this->get_instructions();
|
||||
$output = common_markup_to_html($inst);
|
||||
common_element_start('div', 'instructions');
|
||||
common_raw($output);
|
||||
common_element_end('div');
|
||||
}
|
||||
$this->settings_menu();
|
||||
}
|
||||
|
||||
function settings_menu() {
|
||||
# action => array('prompt', 'title')
|
||||
$menu =
|
||||
array('profilesettings' =>
|
||||
array(_('Profile'),
|
||||
_('Change your profile settings')),
|
||||
'emailsettings' =>
|
||||
array(_('Email'),
|
||||
_('Change email handling')),
|
||||
'openidsettings' =>
|
||||
array(_('OpenID'),
|
||||
_('Add or remove OpenIDs')),
|
||||
'smssettings' =>
|
||||
array(_('SMS'),
|
||||
_('Updates by SMS')),
|
||||
'imsettings' =>
|
||||
array(_('IM'),
|
||||
_('Updates by instant messenger (IM)')),
|
||||
'twittersettings' =>
|
||||
array(_('Twitter'),
|
||||
_('Twitter integration options')),
|
||||
'othersettings' =>
|
||||
array(_('Other'),
|
||||
_('Other options')));
|
||||
|
||||
$menu =
|
||||
array('profilesettings' =>
|
||||
array(_('Profile'),
|
||||
_('Change your profile settings')),
|
||||
'emailsettings' =>
|
||||
array(_('Email'),
|
||||
_('Change email handling')),
|
||||
'openidsettings' =>
|
||||
array(_('OpenID'),
|
||||
_('Add or remove OpenIDs')),
|
||||
'smssettings' =>
|
||||
array(_('SMS'),
|
||||
_('Updates by SMS')),
|
||||
'imsettings' =>
|
||||
array(_('IM'),
|
||||
_('Updates by instant messenger (IM)')),
|
||||
'twittersettings' =>
|
||||
array(_('Twitter'),
|
||||
_('Twitter integration options')),
|
||||
'othersettings' =>
|
||||
array(_('Other'),
|
||||
_('Other options')));
|
||||
|
||||
$action = $this->trimmed('action');
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
foreach ($menu as $menuaction => $menudesc) {
|
||||
if ($menuaction == 'imsettings' &&
|
||||
!common_config('xmpp', 'enabled')) {
|
||||
continue;
|
||||
}
|
||||
if ($menuaction == 'imsettings' &&
|
||||
!common_config('xmpp', 'enabled')) {
|
||||
continue;
|
||||
}
|
||||
common_menu_item(common_local_url($menuaction),
|
||||
$menudesc[0],
|
||||
$menudesc[1],
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
*
|
||||
* 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
|
||||
* 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/>.
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
@@ -24,29 +24,29 @@ require_once(INSTALLDIR.'/lib/noticelist.php');
|
||||
|
||||
class StreamAction extends PersonalAction {
|
||||
|
||||
function public_views_menu() {
|
||||
function public_views_menu() {
|
||||
|
||||
$action = $this->trimmed('action');
|
||||
$action = $this->trimmed('action');
|
||||
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
|
||||
common_menu_item(common_local_url('public'), _('Public'),
|
||||
_('Public timeline'), $action == 'public');
|
||||
common_menu_item(common_local_url('public'), _('Public'),
|
||||
_('Public timeline'), $action == 'public');
|
||||
|
||||
common_menu_item(common_local_url('tag'), _('Recent tags'),
|
||||
_('Recent tags'), $action == 'tag');
|
||||
common_menu_item(common_local_url('tag'), _('Recent tags'),
|
||||
_('Recent tags'), $action == 'tag');
|
||||
|
||||
if (count(common_config('nickname', 'featured')) > 0) {
|
||||
common_menu_item(common_local_url('featured'), _('Featured'),
|
||||
_('Featured users'), $action == 'featured');
|
||||
}
|
||||
if (count(common_config('nickname', 'featured')) > 0) {
|
||||
common_menu_item(common_local_url('featured'), _('Featured'),
|
||||
_('Featured users'), $action == 'featured');
|
||||
}
|
||||
|
||||
common_menu_item(common_local_url('favorited'), _('Popular'),
|
||||
_("Popular notices"), $action == 'favorited');
|
||||
common_menu_item(common_local_url('favorited'), _('Popular'),
|
||||
_("Popular notices"), $action == 'favorited');
|
||||
|
||||
common_element_end('ul');
|
||||
common_element_end('ul');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function show_notice_list($notice) {
|
||||
$nl = new NoticeList($notice);
|
||||
|
||||
@@ -27,13 +27,13 @@ require_once('XMPPHP/XMPP.php');
|
||||
|
||||
function subs_subscribe_user($user, $other_nickname) {
|
||||
|
||||
$other = User::staticGet('nickname', $other_nickname);
|
||||
$other = User::staticGet('nickname', $other_nickname);
|
||||
|
||||
if (!$other) {
|
||||
return _('No such user.');
|
||||
}
|
||||
if (!$other) {
|
||||
return _('No such user.');
|
||||
}
|
||||
|
||||
return subs_subscribe_to($user, $other);
|
||||
return subs_subscribe_to($user, $other);
|
||||
}
|
||||
|
||||
/* Subscribe user $user to other user $other.
|
||||
@@ -43,54 +43,54 @@ function subs_subscribe_user($user, $other_nickname) {
|
||||
|
||||
function subs_subscribe_to($user, $other) {
|
||||
|
||||
if ($user->isSubscribed($other)) {
|
||||
return _('Already subscribed!.');
|
||||
}
|
||||
|
||||
if ($other->hasBlocked($user)) {
|
||||
return _('User has blocked you.');
|
||||
if ($user->isSubscribed($other)) {
|
||||
return _('Already subscribed!.');
|
||||
}
|
||||
|
||||
if (!$user->subscribeTo($other)) {
|
||||
return _('Could not subscribe.');
|
||||
return;
|
||||
}
|
||||
if ($other->hasBlocked($user)) {
|
||||
return _('User has blocked you.');
|
||||
}
|
||||
|
||||
if (!$user->subscribeTo($other)) {
|
||||
return _('Could not subscribe.');
|
||||
return;
|
||||
}
|
||||
|
||||
subs_notify($other, $user);
|
||||
|
||||
if (common_config('memcached', 'enabled')) {
|
||||
$cache = new Memcache();
|
||||
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
|
||||
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
|
||||
}
|
||||
}
|
||||
if (common_config('memcached', 'enabled')) {
|
||||
$cache = new Memcache();
|
||||
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
|
||||
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
|
||||
}
|
||||
}
|
||||
|
||||
if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) {
|
||||
if (!$other->subscribeTo($user)) {
|
||||
return _('Could not subscribe other to you.');
|
||||
}
|
||||
if (common_config('memcached', 'enabled')) {
|
||||
$cache = new Memcache();
|
||||
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
|
||||
$cache->delete(common_cache_key('user:notices_with_friends:' . $other->id));
|
||||
}
|
||||
}
|
||||
if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) {
|
||||
if (!$other->subscribeTo($user)) {
|
||||
return _('Could not subscribe other to you.');
|
||||
}
|
||||
if (common_config('memcached', 'enabled')) {
|
||||
$cache = new Memcache();
|
||||
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
|
||||
$cache->delete(common_cache_key('user:notices_with_friends:' . $other->id));
|
||||
}
|
||||
}
|
||||
|
||||
subs_notify($user, $other);
|
||||
}
|
||||
subs_notify($user, $other);
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function subs_notify($listenee, $listener) {
|
||||
# XXX: add other notifications (Jabber, SMS) here
|
||||
# XXX: queue this and handle it offline
|
||||
# XXX: Whatever happens, do it in Twitter-like API, too
|
||||
subs_notify_email($listenee, $listener);
|
||||
# XXX: add other notifications (Jabber, SMS) here
|
||||
# XXX: queue this and handle it offline
|
||||
# XXX: Whatever happens, do it in Twitter-like API, too
|
||||
subs_notify_email($listenee, $listener);
|
||||
}
|
||||
|
||||
function subs_notify_email($listenee, $listener) {
|
||||
mail_subscribe_notify($listenee, $listener);
|
||||
mail_subscribe_notify($listenee, $listener);
|
||||
}
|
||||
|
||||
/* Unsubscribe $user from nickname $other_nickname
|
||||
@@ -99,13 +99,13 @@ function subs_notify_email($listenee, $listener) {
|
||||
|
||||
function subs_unsubscribe_user($user, $other_nickname) {
|
||||
|
||||
$other = User::staticGet('nickname', $other_nickname);
|
||||
$other = User::staticGet('nickname', $other_nickname);
|
||||
|
||||
if (!$other) {
|
||||
return _('No such user.');
|
||||
}
|
||||
if (!$other) {
|
||||
return _('No such user.');
|
||||
}
|
||||
|
||||
return subs_unsubscribe_to($user, $other->getProfile());
|
||||
return subs_unsubscribe_to($user, $other->getProfile());
|
||||
}
|
||||
|
||||
/* Unsubscribe user $user from profile $other
|
||||
@@ -113,28 +113,28 @@ function subs_unsubscribe_user($user, $other_nickname) {
|
||||
|
||||
function subs_unsubscribe_to($user, $other) {
|
||||
|
||||
if (!$user->isSubscribed($other))
|
||||
return _('Not subscribed!.');
|
||||
if (!$user->isSubscribed($other))
|
||||
return _('Not subscribed!.');
|
||||
|
||||
$sub = DB_DataObject::factory('subscription');
|
||||
$sub = DB_DataObject::factory('subscription');
|
||||
|
||||
$sub->subscriber = $user->id;
|
||||
$sub->subscribed = $other->id;
|
||||
$sub->subscriber = $user->id;
|
||||
$sub->subscribed = $other->id;
|
||||
|
||||
$sub->find(true);
|
||||
$sub->find(true);
|
||||
|
||||
// note we checked for existence above
|
||||
// note we checked for existence above
|
||||
|
||||
if (!$sub->delete())
|
||||
return _('Couldn\'t delete subscription.');
|
||||
if (!$sub->delete())
|
||||
return _('Couldn\'t delete subscription.');
|
||||
|
||||
if (common_config('memcached', 'enabled')) {
|
||||
$cache = new Memcache();
|
||||
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
|
||||
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
|
||||
}
|
||||
}
|
||||
if (common_config('memcached', 'enabled')) {
|
||||
$cache = new Memcache();
|
||||
if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
|
||||
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,16 @@
|
||||
if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
function theme_file($relative) {
|
||||
$theme = common_config('site', 'theme');
|
||||
return INSTALLDIR.'/theme/'.$theme.'/'.$relative;
|
||||
$theme = common_config('site', 'theme');
|
||||
return INSTALLDIR.'/theme/'.$theme.'/'.$relative;
|
||||
}
|
||||
|
||||
function theme_path($relative) {
|
||||
$theme = common_config('site', 'theme');
|
||||
$server = common_config('theme', 'server');
|
||||
if ($server) {
|
||||
return 'http://'.$server.'/'.$theme.'/'.$relative;
|
||||
} else {
|
||||
return common_path('theme/'.$theme.'/'.$relative);
|
||||
}
|
||||
$theme = common_config('site', 'theme');
|
||||
$server = common_config('theme', 'server');
|
||||
if ($server) {
|
||||
return 'http://'.$server.'/'.$theme.'/'.$relative;
|
||||
} else {
|
||||
return common_path('theme/'.$theme.'/'.$relative);
|
||||
}
|
||||
}
|
||||
@@ -21,179 +21,179 @@ if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
function get_twitter_data($uri, $screen_name, $password) {
|
||||
|
||||
$options = array(
|
||||
CURLOPT_USERPWD => sprintf("%s:%s", $screen_name, $password),
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FAILONERROR => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
// CURLOPT_USERAGENT => "identi.ca",
|
||||
CURLOPT_CONNECTTIMEOUT => 120,
|
||||
CURLOPT_TIMEOUT => 120
|
||||
);
|
||||
$options = array(
|
||||
CURLOPT_USERPWD => sprintf("%s:%s", $screen_name, $password),
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FAILONERROR => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
// CURLOPT_USERAGENT => "identi.ca",
|
||||
CURLOPT_CONNECTTIMEOUT => 120,
|
||||
CURLOPT_TIMEOUT => 120
|
||||
);
|
||||
|
||||
|
||||
$ch = curl_init($uri);
|
||||
$ch = curl_init($uri);
|
||||
curl_setopt_array($ch, $options);
|
||||
$data = curl_exec($ch);
|
||||
$errmsg = curl_error($ch);
|
||||
|
||||
if ($errmsg) {
|
||||
common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $twit_user.",
|
||||
__FILE__);
|
||||
}
|
||||
if ($errmsg) {
|
||||
common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $twit_user.",
|
||||
__FILE__);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $data;
|
||||
return $data;
|
||||
}
|
||||
|
||||
function twitter_user_info($screen_name, $password) {
|
||||
|
||||
$uri = "http://twitter.com/users/show/$screen_name.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) {
|
||||
return false;
|
||||
}
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$twit_user = json_decode($data);
|
||||
$twit_user = json_decode($data);
|
||||
|
||||
if (!$twit_user) {
|
||||
return false;
|
||||
}
|
||||
if (!$twit_user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $twit_user;
|
||||
return $twit_user;
|
||||
}
|
||||
|
||||
function update_twitter_user($fuser, $twitter_id, $screen_name) {
|
||||
|
||||
$original = clone($fuser);
|
||||
$fuser->nickname = $screen_name;
|
||||
$fuser->uri = 'http://twitter.com/' . $screen_name;
|
||||
$result = $fuser->updateKeys($original);
|
||||
$original = clone($fuser);
|
||||
$fuser->nickname = $screen_name;
|
||||
$fuser->uri = 'http://twitter.com/' . $screen_name;
|
||||
$result = $fuser->updateKeys($original);
|
||||
|
||||
if (!$result) {
|
||||
common_log_db_error($fuser, 'UPDATE', __FILE__);
|
||||
return false;
|
||||
}
|
||||
if (!$result) {
|
||||
common_log_db_error($fuser, 'UPDATE', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function add_twitter_user($twitter_id, $screen_name) {
|
||||
|
||||
// Otherwise, create a new Twitter user
|
||||
$fuser = DB_DataObject::factory('foreign_user');
|
||||
// Otherwise, create a new Twitter user
|
||||
$fuser = DB_DataObject::factory('foreign_user');
|
||||
|
||||
$fuser->nickname = $screen_name;
|
||||
$fuser->uri = 'http://twitter.com/' . $screen_name;
|
||||
$fuser->id = $twitter_id;
|
||||
$fuser->service = 1; // Twitter
|
||||
$fuser->created = common_sql_now();
|
||||
$result = $fuser->insert();
|
||||
$fuser->nickname = $screen_name;
|
||||
$fuser->uri = 'http://twitter.com/' . $screen_name;
|
||||
$fuser->id = $twitter_id;
|
||||
$fuser->service = 1; // Twitter
|
||||
$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_db_error($fuser, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
if (!$result) {
|
||||
common_debug("Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
|
||||
common_log_db_error($fuser, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
|
||||
common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Creates or Updates a Twitter user
|
||||
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);
|
||||
// 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);
|
||||
|
||||
if ($fuser) {
|
||||
if ($fuser) {
|
||||
|
||||
// Only update if Twitter screen name has changed
|
||||
if ($fuser->nickname != $screen_name) {
|
||||
// Only update if Twitter screen name has changed
|
||||
if ($fuser->nickname != $screen_name) {
|
||||
|
||||
common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' .
|
||||
"$fuser->id to $screen_name, was $fuser->nickname");
|
||||
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);
|
||||
}
|
||||
return update_twitter_user($fuser, $twitter_id, $screen_name);
|
||||
}
|
||||
|
||||
} else {
|
||||
return add_twitter_user($twitter_id, $screen_name);
|
||||
}
|
||||
} else {
|
||||
return add_twitter_user($twitter_id, $screen_name);
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function retreive_twitter_friends($twitter_id, $screen_name, $password) {
|
||||
|
||||
$uri = "http://twitter.com/statuses/friends/$twitter_id.json?page=";
|
||||
$twitter_user = twitter_user_info($screen_name, $password);
|
||||
$uri = "http://twitter.com/statuses/friends/$twitter_id.json?page=";
|
||||
$twitter_user = twitter_user_info($screen_name, $password);
|
||||
|
||||
// Calculate how many pages to get...
|
||||
$pages = ceil($twitter_user->friends_count / 100);
|
||||
// Calculate how many pages to get...
|
||||
$pages = ceil($twitter_user->friends_count / 100);
|
||||
|
||||
if ($pages == 0) {
|
||||
common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame.");
|
||||
}
|
||||
if ($pages == 0) {
|
||||
common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame.");
|
||||
}
|
||||
|
||||
$friends = array();
|
||||
$friends = array();
|
||||
|
||||
for ($i = 1; $i <= $pages; $i++) {
|
||||
for ($i = 1; $i <= $pages; $i++) {
|
||||
|
||||
$data = get_twitter_data($uri . $i, $screen_name, $password);
|
||||
$data = get_twitter_data($uri . $i, $screen_name, $password);
|
||||
|
||||
if (!$data) {
|
||||
return NULL;
|
||||
}
|
||||
if (!$data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$more_friends = json_decode($data);
|
||||
$more_friends = json_decode($data);
|
||||
|
||||
if (!$more_friends) {
|
||||
return NULL;
|
||||
}
|
||||
if (!$more_friends) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$friends = array_merge($friends, $more_friends);
|
||||
}
|
||||
$friends = array_merge($friends, $more_friends);
|
||||
}
|
||||
|
||||
return $friends;
|
||||
return $friends;
|
||||
}
|
||||
|
||||
function save_twitter_friends($user, $twitter_id, $screen_name, $password) {
|
||||
|
||||
$friends = retreive_twitter_friends($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.");
|
||||
return false;
|
||||
}
|
||||
if (is_null($friends)) {
|
||||
common_debug("Twitter bridge - Couldn't get friends data from Twitter.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
|
||||
$friend_name = $friend->screen_name;
|
||||
$friend_id = $friend->id;
|
||||
$friend_name = $friend->screen_name;
|
||||
$friend_id = $friend->id;
|
||||
|
||||
// Update or create the Foreign_user record
|
||||
if (!save_twitter_user($friend_id, $friend_name)) {
|
||||
return false;
|
||||
}
|
||||
// Update or create the Foreign_user record
|
||||
if (!save_twitter_user($friend_id, $friend_name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check to see if there's a related local user
|
||||
$flink = Foreign_link::getByForeignID($friend_id, 1);
|
||||
// Check to see if there's a related local user
|
||||
$flink = Foreign_link::getByForeignID($friend_id, 1);
|
||||
|
||||
if ($flink) {
|
||||
if ($flink) {
|
||||
|
||||
// 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.");
|
||||
}
|
||||
}
|
||||
// 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.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,63 +29,63 @@ require_once(INSTALLDIR.'/lib/queuehandler.php');
|
||||
*/
|
||||
|
||||
class XmppQueueHandler extends QueueHandler {
|
||||
|
||||
function start() {
|
||||
# Low priority; we don't want to receive messages
|
||||
$this->log(LOG_INFO, "INITIALIZE");
|
||||
$this->conn = jabber_connect($this->_id);
|
||||
if ($this->conn) {
|
||||
$this->conn->addEventHandler('message', 'forward_message', $this);
|
||||
$this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
|
||||
$this->conn->setReconnectTimeout(600);
|
||||
jabber_send_presence("Send me a message to post a notice", 'available', NULL, 'available', -1);
|
||||
}
|
||||
return !is_null($this->conn);
|
||||
}
|
||||
|
||||
function handle_reconnect(&$pl) {
|
||||
$this->conn->processUntil('session_start');
|
||||
$this->conn->presence(NULL, 'available', NULL, 'available', -1);
|
||||
}
|
||||
|
||||
function start() {
|
||||
# Low priority; we don't want to receive messages
|
||||
$this->log(LOG_INFO, "INITIALIZE");
|
||||
$this->conn = jabber_connect($this->_id);
|
||||
if ($this->conn) {
|
||||
$this->conn->addEventHandler('message', 'forward_message', $this);
|
||||
$this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
|
||||
$this->conn->setReconnectTimeout(600);
|
||||
jabber_send_presence("Send me a message to post a notice", 'available', NULL, 'available', -1);
|
||||
}
|
||||
return !is_null($this->conn);
|
||||
}
|
||||
|
||||
function handle_reconnect(&$pl) {
|
||||
$this->conn->processUntil('session_start');
|
||||
$this->conn->presence(NULL, 'available', NULL, 'available', -1);
|
||||
}
|
||||
|
||||
function idle($timeout=0) {
|
||||
# Process the queue for as long as needed
|
||||
try {
|
||||
if ($this->conn) {
|
||||
$this->conn->processTime($timeout);
|
||||
}
|
||||
} catch (XMPPHP_Exception $e) {
|
||||
$this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
|
||||
die($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function forward_message(&$pl) {
|
||||
if ($pl['type'] != 'chat') {
|
||||
$this->log(LOG_DEBUG, 'Ignoring message of type ' . $pl['type'] . ' from ' . $pl['from']);
|
||||
return;
|
||||
}
|
||||
$listener = $this->listener();
|
||||
if (strtolower($listener) == strtolower($pl['from'])) {
|
||||
$this->log(LOG_WARNING, 'Ignoring loop message.');
|
||||
return;
|
||||
}
|
||||
$this->log(LOG_INFO, 'Forwarding message from ' . $pl['from'] . ' to ' . $listener);
|
||||
$this->conn->message($this->listener(), $pl['body'], 'chat', NULL, $this->ofrom($pl['from']));
|
||||
}
|
||||
function idle($timeout=0) {
|
||||
# Process the queue for as long as needed
|
||||
try {
|
||||
if ($this->conn) {
|
||||
$this->conn->processTime($timeout);
|
||||
}
|
||||
} catch (XMPPHP_Exception $e) {
|
||||
$this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
|
||||
die($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function forward_message(&$pl) {
|
||||
if ($pl['type'] != 'chat') {
|
||||
$this->log(LOG_DEBUG, 'Ignoring message of type ' . $pl['type'] . ' from ' . $pl['from']);
|
||||
return;
|
||||
}
|
||||
$listener = $this->listener();
|
||||
if (strtolower($listener) == strtolower($pl['from'])) {
|
||||
$this->log(LOG_WARNING, 'Ignoring loop message.');
|
||||
return;
|
||||
}
|
||||
$this->log(LOG_INFO, 'Forwarding message from ' . $pl['from'] . ' to ' . $listener);
|
||||
$this->conn->message($this->listener(), $pl['body'], 'chat', NULL, $this->ofrom($pl['from']));
|
||||
}
|
||||
|
||||
function ofrom($from) {
|
||||
$address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
|
||||
$address .= "<address type='ofrom' jid='$from' />\n";
|
||||
$address .= "</addresses>\n";
|
||||
return $address;
|
||||
}
|
||||
function ofrom($from) {
|
||||
$address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
|
||||
$address .= "<address type='ofrom' jid='$from' />\n";
|
||||
$address .= "</addresses>\n";
|
||||
return $address;
|
||||
}
|
||||
|
||||
function listener() {
|
||||
if (common_config('xmpp', 'listener')) {
|
||||
return common_config('xmpp', 'listener');
|
||||
} else {
|
||||
return jabber_daemon_address() . '/' . common_config('xmpp','resource') . '-listener';
|
||||
}
|
||||
}
|
||||
function listener() {
|
||||
if (common_config('xmpp', 'listener')) {
|
||||
return common_config('xmpp', 'listener');
|
||||
} else {
|
||||
return jabber_daemon_address() . '/' . common_config('xmpp','resource') . '-listener';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user