reformatting for phpcs in lib/util.php

darcs-hash:20081221003016-84dde-0e80268e95235462e069d4d1e6b949bc891ccdbd.gz
This commit is contained in:
Evan Prodromou 2008-12-20 19:30:16 -05:00
parent b8c0091390
commit ee4db3d21c
5 changed files with 6447 additions and 3131 deletions

View File

@ -22,3 +22,5 @@ Sarven Capadisli <csarven@controlyourself.ca>**20081218003302
Evan Prodromou <evan@prodromou.name>**20081212171135]
[first step of phpcs-cleanup of index.php
Evan Prodromou <evan@prodromou.name>**20081221002332]
[reformatting for phpcs in lib/util.php
Evan Prodromou <evan@prodromou.name>**20081221003016]

View File

@ -19,7 +19,7 @@
/* XXX: break up into separate modules (HTTP, HTML, user, files) */
# Show a server error
// Show a server error
function common_server_error($msg, $code=500) {
static $status = array(500 => 'Internal Server Error',
@ -43,7 +43,7 @@ function common_server_error($msg, $code=500) {
exit();
}
# Show a user error
// Show a user error
function common_user_error($msg, $code=400) {
static $status = array(400 => 'Bad Request',
401 => 'Unauthorized',
@ -79,8 +79,8 @@ function common_user_error($msg, $code=400) {
$xw = null;
# Start an HTML element
function common_element_start($tag, $attrs=NULL) {
// Start an HTML element
function common_element_start($tag, $attrs=null) {
global $xw;
$xw->startElement($tag);
if (is_array($attrs)) {
@ -97,7 +97,7 @@ function common_element_end($tag) {
'br', 'param', 'img', 'area',
'input', 'col');
global $xw;
# XXX: check namespace
// XXX: check namespace
if (in_array($tag, $empty_tag)) {
$xw->endElement();
} else {
@ -105,7 +105,7 @@ function common_element_end($tag) {
}
}
function common_element($tag, $attrs=NULL, $content=NULL) {
function common_element($tag, $attrs=null, $content=null) {
common_element_start($tag, $attrs);
global $xw;
if (!is_null($content)) {
@ -114,7 +114,7 @@ function common_element($tag, $attrs=NULL, $content=NULL) {
common_element_end($tag);
}
function common_start_xml($doc=NULL, $public=NULL, $system=NULL, $indent=true) {
function common_start_xml($doc=null, $public=null, $system=null, $indent=true) {
global $xw;
$xw = new XMLWriter();
$xw->openURI('php://output');
@ -147,7 +147,7 @@ function common_init_locale($language=null) {
function common_init_language() {
mb_internal_encoding('UTF-8');
$language = common_language();
# So we don't have to make people install the gettext locales
// So we don't have to make people install the gettext locales
$locale_set = common_init_locale($language);
bindtextdomain("laconica", common_config('site','locale_path'));
bind_textdomain_codeset("laconica", "UTF-8");
@ -160,7 +160,7 @@ function common_init_language() {
define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2');
function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) {
function common_show_header($pagetitle, $callable=null, $data=null, $headercall=null) {
global $config, $xw;
global $action; /* XXX: kind of cheating here. */
@ -168,7 +168,7 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
common_start_html();
common_element_start('head');
common_element('title', NULL,
common_element('title', null,
$pagetitle . " - " . $config['site']['name']);
common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
@ -176,7 +176,7 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
'media' => 'screen, projection, tv'));
foreach (array(6,7) as $ver) {
if (file_exists(theme_file('ie'.$ver.'.css'))) {
# Yes, IE people should be put in jail.
// Yes, IE people should be put in jail.
$xw->writeComment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
'href="'.theme_path('ie'.$ver.'.css').'?version='.LACONICA_VERSION.'" /><![endif]');
}
@ -243,12 +243,12 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
common_element_start('div', array('id' => 'content'));
}
function common_start_html($type=NULL, $indent=true) {
function common_start_html($type=null, $indent=true) {
if (!$type) {
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL;
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
# XXX: allow content negotiation for RDF, RSS, or XRDS
// XXX: allow content negotiation for RDF, RSS, or XRDS
$type = common_negotiate_type(common_accept_to_prefs($httpaccept),
common_accept_to_prefs(PAGE_TYPE_PREFS));
@ -265,7 +265,7 @@ function common_start_html($type=NULL, $indent=true) {
'-//W3C//DTD XHTML 1.0 Strict//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd', $indent);
# FIXME: correct language for interface
// FIXME: correct language for interface
$language = common_language();
@ -276,7 +276,7 @@ function common_start_html($type=NULL, $indent=true) {
function common_show_footer() {
global $xw, $config;
common_element_end('div'); # content div
common_element_end('div'); // content div
common_foot_menu();
common_element_start('div', array('id' => 'footer'));
common_element_start('div', 'laconica');
@ -361,7 +361,7 @@ function common_foot_menu() {
common_element_end('ul');
}
function common_menu_item($url, $text, $title=NULL, $is_selected=false) {
function common_menu_item($url, $text, $title=null, $is_selected=false) {
$lattrs = array();
if ($is_selected) {
$lattrs['class'] = 'current';
@ -375,7 +375,7 @@ function common_menu_item($url, $text, $title=NULL, $is_selected=false) {
common_element_end('li');
}
function common_input($id, $label, $value=NULL,$instructions=NULL) {
function common_input($id, $label, $value=null,$instructions=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
$attrs = array('name' => $id,
@ -392,7 +392,7 @@ function common_input($id, $label, $value=NULL,$instructions=NULL) {
common_element_end('p');
}
function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value='true', $disabled=false)
function common_checkbox($id, $label, $checked=false, $instructions=null, $value='true', $disabled=false)
{
common_element_start('p');
$attrs = array('name' => $id,
@ -418,7 +418,7 @@ function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value
common_element_end('p');
}
function common_dropdown($id, $label, $content, $instructions=NULL, $blank_select=FALSE, $selected=NULL) {
function common_dropdown($id, $label, $content, $instructions=null, $blank_select=FALSE, $selected=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
common_element_start('select', array('id' => $id, 'name' => $id));
@ -445,7 +445,7 @@ function common_hidden($id, $value) {
'value' => $value));
}
function common_password($id, $label, $instructions=NULL) {
function common_password($id, $label, $instructions=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
$attrs = array('name' => $id,
@ -470,7 +470,7 @@ function common_submit($id, $label, $cls='submit') {
common_element_end('p');
}
function common_textarea($id, $label, $content=NULL, $instructions=NULL) {
function common_textarea($id, $label, $content=null, $instructions=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
common_element('textarea', array('rows' => 3,
@ -509,7 +509,7 @@ function common_language() {
// Otherwise, find the best match for the languages requested by the
// user's browser...
$httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL;
$httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
if (!empty($httplang)) {
$language = client_prefered_language($httplang);
if ($language)
@ -519,15 +519,15 @@ function common_language() {
// Finally, if none of the above worked, use the site's default...
return common_config('site', 'language');
}
# salted, hashed passwords are stored in the DB
// salted, hashed passwords are stored in the DB
function common_munge_password($password, $id) {
return md5($password . $id);
}
# check if a username exists and has matching password
// check if a username exists and has matching password
function common_check_user($nickname, $password) {
# NEVER allow blank passwords, even if they match the DB
// NEVER allow blank passwords, even if they match the DB
if (mb_strlen($password) == 0) {
return false;
}
@ -544,7 +544,7 @@ function common_check_user($nickname, $password) {
}
}
# is the current user logged in?
// is the current user logged in?
function common_logged_in() {
return (!is_null(common_current_user()));
}
@ -559,12 +559,12 @@ function common_ensure_session() {
}
}
# Three kinds of arguments:
# 1) a user object
# 2) a nickname
# 3) NULL to clear
// Three kinds of arguments:
// 1) a user object
// 2) a nickname
// 3) null to clear
# Initialize to false; set to NULL if none found
// Initialize to false; set to null if none found
$_cur = false;
@ -573,7 +573,7 @@ function common_set_user($user) {
global $_cur;
if (is_null($user) && common_have_session()) {
$_cur = NULL;
$_cur = null;
unset($_SESSION['userid']);
return true;
} else if (is_string($user)) {
@ -609,9 +609,9 @@ function common_set_cookie($key, $value, $expiration=0) {
}
define('REMEMBERME', 'rememberme');
define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); # 30 days
define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); // 30 days
function common_rememberme($user=NULL) {
function common_rememberme($user=null) {
if (!$user) {
$user = common_current_user();
if (!$user) {
@ -625,7 +625,7 @@ function common_rememberme($user=NULL) {
$rm->code = common_good_rand(16);
$rm->user_id = $user->id;
# Wrap the insert in some good ol' fashioned transaction code
// Wrap the insert in some good ol' fashioned transaction code
$rm->query('BEGIN');
@ -652,12 +652,12 @@ function common_rememberme($user=NULL) {
function common_remembered_user() {
$user = NULL;
$user = null;
$packed = isset($_COOKIE[REMEMBERME]) ? $_COOKIE[REMEMBERME] : NULL;
$packed = isset($_COOKIE[REMEMBERME]) ? $_COOKIE[REMEMBERME] : null;
if (!$packed) {
return NULL;
return null;
}
list($id, $code) = explode(':', $packed);
@ -665,7 +665,7 @@ function common_remembered_user() {
if (!$id || !$code) {
common_log(LOG_WARNING, 'Malformed rememberme cookie: ' . $packed);
common_forgetme();
return NULL;
return null;
}
$rm = Remember_me::staticGet($code);
@ -673,13 +673,13 @@ function common_remembered_user() {
if (!$rm) {
common_log(LOG_WARNING, 'No such remember code: ' . $code);
common_forgetme();
return NULL;
return null;
}
if ($rm->user_id != $id) {
common_log(LOG_WARNING, 'Rememberme code for wrong user: ' . $rm->user_id . ' != ' . $id);
common_forgetme();
return NULL;
return null;
}
$user = User::staticGet($rm->user_id);
@ -687,17 +687,17 @@ function common_remembered_user() {
if (!$user) {
common_log(LOG_WARNING, 'No such user for rememberme: ' . $rm->user_id);
common_forgetme();
return NULL;
return null;
}
# successful!
// successful!
$result = $rm->delete();
if (!$result) {
common_log_db_error($rm, 'DELETE', __FILE__);
common_log(LOG_WARNING, 'Could not delete rememberme: ' . $code);
common_forgetme();
return NULL;
return null;
}
common_log(LOG_INFO, 'logging in ' . $user->nickname . ' using rememberme code ' . $rm->code);
@ -705,21 +705,21 @@ function common_remembered_user() {
common_set_user($user);
common_real_login(false);
# We issue a new cookie, so they can log in
# automatically again after this session
// We issue a new cookie, so they can log in
// automatically again after this session
common_rememberme($user);
return $user;
}
# must be called with a valid user!
// must be called with a valid user!
function common_forgetme() {
common_set_cookie(REMEMBERME, '', 0);
}
# who is the current user?
// who is the current user?
function common_current_user() {
global $_cur;
@ -734,13 +734,13 @@ function common_current_user() {
}
}
# that didn't work; try to remember; will init $_cur to NULL on failure
// that didn't work; try to remember; will init $_cur to null on failure
$_cur = common_remembered_user();
if ($_cur) {
common_debug("Got User " . $_cur->nickname);
common_debug("Faking session on remembered user");
# XXX: Is this necessary?
// XXX: Is this necessary?
$_SESSION['userid'] = $_cur->id;
}
}
@ -748,9 +748,9 @@ function common_current_user() {
return $_cur;
}
# Logins that are 'remembered' aren't 'real' -- they're subject to
# cookie-stealing. So, we don't let them do certain things. New reg,
# OpenID, and password logins _are_ real.
// Logins that are 'remembered' aren't 'real' -- they're subject to
// cookie-stealing. So, we don't let them do certain things. New reg,
// OpenID, and password logins _are_ real.
function common_real_login($real=true) {
common_ensure_session();
@ -761,16 +761,16 @@ function common_is_real_login() {
return common_logged_in() && $_SESSION['real_login'];
}
# get canonical version of nickname for comparison
// get canonical version of nickname for comparison
function common_canonical_nickname($nickname) {
# XXX: UTF-8 canonicalization (like combining chars)
// XXX: UTF-8 canonicalization (like combining chars)
return strtolower($nickname);
}
# get canonical version of email for comparison
// get canonical version of email for comparison
function common_canonical_email($email) {
# XXX: canonicalize UTF-8
# XXX: lcase the domain part
// XXX: canonicalize UTF-8
// XXX: lcase the domain part
return $email;
}
@ -791,7 +791,7 @@ function common_render_text($text) {
$r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
$r = preg_replace_callback('@https?://[^\]>\s]+@', 'common_render_uri_thingy', $r);
$r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
# XXX: machine tags
// XXX: machine tags
return $r;
}
@ -799,16 +799,16 @@ function common_render_uri_thingy($matches) {
$uri = $matches[0];
$trailer = '';
# Some heuristics for extracting URIs from surrounding punctuation
# Strip from trailing text...
// Some heuristics for extracting URIs from surrounding punctuation
// Strip from trailing text...
if (preg_match('/^(.*)([,.:"\']+)$/', $uri, $matches)) {
$uri = $matches[1];
$trailer = $matches[2];
}
$pairs = array(
']' => '[', # technically disallowed in URIs, but used in Java docs
')' => '(', # far too frequent in Wikipedia and MSDN
']' => '[', // technically disallowed in URIs, but used in Java docs
')' => '(', // far too frequent in Wikipedia and MSDN
);
$final = substr($uri, -1, 1);
if (isset($pairs[$final])) {
@ -958,28 +958,28 @@ function common_at_hash_link($sender_id, $tag) {
}
}
function common_relative_profile($sender, $nickname, $dt=NULL) {
# Try to find profiles this profile is subscribed to that have this nickname
function common_relative_profile($sender, $nickname, $dt=null) {
// Try to find profiles this profile is subscribed to that have this nickname
$recipient = new Profile();
# XXX: use a join instead of a subquery
// XXX: use a join instead of a subquery
$recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender->id.' and subscribed = id)', 'AND');
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
if ($recipient->find(TRUE)) {
# XXX: should probably differentiate between profiles with
# the same name by date of most recent update
// XXX: should probably differentiate between profiles with
// the same name by date of most recent update
return $recipient;
}
# Try to find profiles that listen to this profile and that have this nickname
// Try to find profiles that listen to this profile and that have this nickname
$recipient = new Profile();
# XXX: use a join instead of a subquery
// XXX: use a join instead of a subquery
$recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender->id.' and subscriber = id)', 'AND');
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
if ($recipient->find(TRUE)) {
# XXX: should probably differentiate between profiles with
# the same name by date of most recent update
// XXX: should probably differentiate between profiles with
// the same name by date of most recent update
return $recipient;
}
# If this is a local user, try to find a local user with that nickname.
// If this is a local user, try to find a local user with that nickname.
$sender = User::staticGet($sender->id);
if ($sender) {
$recipient_user = User::staticGet('nickname', $nickname);
@ -987,15 +987,15 @@ function common_relative_profile($sender, $nickname, $dt=NULL) {
return $recipient_user->getProfile();
}
}
# Otherwise, no links. @messages from local users to remote users,
# or from remote users to other remote users, are just
# outside our ability to make intelligent guesses about
return NULL;
// Otherwise, no links. @messages from local users to remote users,
// or from remote users to other remote users, are just
// outside our ability to make intelligent guesses about
return null;
}
// where should the avatar go for this user?
function common_avatar_filename($id, $extension, $size=NULL, $extra=NULL) {
function common_avatar_filename($id, $extension, $size=null, $extra=null) {
global $config;
if ($size) {
@ -1030,8 +1030,8 @@ function common_default_avatar($size) {
return theme_path('default-avatar-'.$sizenames[$size].'.png');
}
function common_local_url($action, $args=NULL, $fragment=NULL) {
$url = NULL;
function common_local_url($action, $args=null, $fragment=null) {
$url = null;
if (common_config('site','fancy')) {
$url = common_fancy_url($action, $args);
} else {
@ -1043,7 +1043,7 @@ function common_local_url($action, $args=NULL, $fragment=NULL) {
return $url;
}
function common_fancy_url($action, $args=NULL) {
function common_fancy_url($action, $args=null) {
switch (strtolower($action)) {
case 'public':
if ($args && isset($args['page'])) {
@ -1229,7 +1229,7 @@ function common_fancy_url($action, $args=NULL) {
case 'newmessage':
return common_path('message/new' . (($args) ? ('?' . http_build_query($args)) : ''));
case 'api':
# XXX: do fancy URLs for all the API methods
// XXX: do fancy URLs for all the API methods
switch (strtolower($args['apiaction'])) {
case 'statuses':
switch (strtolower($args['method'])) {
@ -1256,7 +1256,7 @@ function common_fancy_url($action, $args=NULL) {
}
}
function common_simple_url($action, $args=NULL) {
function common_simple_url($action, $args=null) {
global $config;
/* XXX: pretty URLs */
$extra = '';
@ -1281,7 +1281,7 @@ function common_date_string($dt) {
$now = time();
$diff = $now - $t;
if ($now < $t) { # that shouldn't happen!
if ($now < $t) { // that shouldn't happen!
return common_exact_date($dt);
} else if ($diff < 60) {
return _('a few seconds ago');
@ -1365,18 +1365,18 @@ function common_redirect($url, $code=307) {
}
function common_save_replies($notice) {
# Alternative reply format
// Alternative reply format
$tname = false;
if (preg_match('/^T ([A-Z0-9]{1,64}) /', $notice->content, $match)) {
$tname = $match[1];
}
# extract all @messages
// extract all @messages
$cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
$names = array();
if ($cnt || $tname) {
# XXX: is there another way to make an array copy?
// XXX: is there another way to make an array copy?
$names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]);
}
@ -1384,8 +1384,8 @@ function common_save_replies($notice) {
$replied = array();
# store replied only for first @ (what user/notice what the reply directed,
# we assume first @ is it)
// store replied only for first @ (what user/notice what the reply directed,
// we assume first @ is it)
for ($i=0; $i<count($names); $i++) {
$nickname = $names[$i];
@ -1393,7 +1393,7 @@ function common_save_replies($notice) {
if (!$recipient) {
continue;
}
if ($i == 0 && ($recipient->id != $sender->id) && !$notice->reply_to) { # Don't save reply to self
if ($i == 0 && ($recipient->id != $sender->id) && !$notice->reply_to) { // Don't save reply to self
$reply_for = $recipient;
$recipient_notice = $reply_for->getCurrentNotice();
if ($recipient_notice) {
@ -1402,7 +1402,7 @@ function common_save_replies($notice) {
$notice->update($orig);
}
}
# Don't save replies from blocked profile to local user
// Don't save replies from blocked profile to local user
$recipient_user = User::staticGet('id', $recipient->id);
if ($recipient_user && $recipient_user->hasBlocked($sender)) {
continue;
@ -1421,14 +1421,14 @@ function common_save_replies($notice) {
}
}
# Hash format replies, too
// Hash format replies, too
$cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $notice->content, $match);
if ($cnt) {
foreach ($match[1] as $tag) {
$tagged = Profile_tag::getTagged($sender->id, $tag);
foreach ($tagged as $t) {
if (!$replied[$t->id]) {
# Don't save replies from blocked profile to local user
// Don't save replies from blocked profile to local user
$t_user = User::staticGet('id', $t->id);
if ($t_user && $t_user->hasBlocked($sender)) {
continue;
@ -1467,7 +1467,7 @@ function common_broadcast_notice($notice, $remote=false) {
}
if (common_config('queue', 'enabled')) {
# Do it later!
// Do it later!
return common_enqueue_notice($notice);
} else {
return common_real_broadcast($notice, $remote);
@ -1532,7 +1532,7 @@ function common_twitter_broadcast($notice, $flink) {
return $success;
}
# Stick the notice on the queue
// Stick the notice on the queue
function common_enqueue_notice($notice) {
foreach (array('jabber', 'omb', 'sms', 'public') as $transport) {
@ -1570,7 +1570,7 @@ function common_dequeue_notice($notice) {
function common_real_broadcast($notice, $remote=false) {
$success = true;
if (!$remote) {
# Make sure we have the OMB stuff
// Make sure we have the OMB stuff
require_once(INSTALLDIR.'/lib/omb.php');
$success = omb_broadcast_remote_subscribers($notice);
if (!$success) {
@ -1613,9 +1613,9 @@ function common_profile_url($nickname) {
return common_local_url('showstream', array('nickname' => $nickname));
}
# Don't call if nobody's logged in
// Don't call if nobody's logged in
function common_notice_form($action=NULL, $content=NULL) {
function common_notice_form($action=null, $content=null) {
$user = common_current_user();
assert(!is_null($user));
common_element_start('form', array('id' => 'status_form',
@ -1635,7 +1635,7 @@ function common_notice_form($action=NULL, $content=NULL) {
if ($action) {
common_hidden('returnto', $action);
}
# set by JavaScript
// set by JavaScript
common_hidden('inreplyto', 'false');
common_element('input', array('id' => 'status_submit',
'name' => 'status_submit',
@ -1645,27 +1645,27 @@ function common_notice_form($action=NULL, $content=NULL) {
common_element_end('form');
}
# Should make up a reasonable root URL
// Should make up a reasonable root URL
function common_root_url() {
return common_path('');
}
# returns $bytes bytes of random data as a hexadecimal string
# "good" here is a goal and not a guarantee
// returns $bytes bytes of random data as a hexadecimal string
// "good" here is a goal and not a guarantee
function common_good_rand($bytes) {
# XXX: use random.org...?
// XXX: use random.org...?
if (file_exists('/dev/urandom')) {
return common_urandom($bytes);
} else { # FIXME: this is probably not good enough
} else { // FIXME: this is probably not good enough
return common_mtrand($bytes);
}
}
function common_urandom($bytes) {
$h = fopen('/dev/urandom', 'rb');
# should not block
// should not block
$src = fread($h, $bytes);
fclose($h);
$enc = '';
@ -1706,7 +1706,7 @@ function common_ensure_syslog() {
}
}
function common_log($priority, $msg, $filename=NULL) {
function common_log($priority, $msg, $filename=null) {
$logfile = common_config('site', 'logfile');
if ($logfile) {
$log = fopen($logfile, "a");
@ -1723,7 +1723,7 @@ function common_log($priority, $msg, $filename=NULL) {
}
}
function common_debug($msg, $filename=NULL) {
function common_debug($msg, $filename=null) {
if ($filename) {
common_log(LOG_DEBUG, basename($filename).' - '.$msg);
} else {
@ -1731,7 +1731,7 @@ function common_debug($msg, $filename=NULL) {
}
}
function common_log_db_error(&$object, $verb, $filename=NULL) {
function common_log_db_error(&$object, $verb, $filename=null) {
$objstr = common_log_objstring($object);
$last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
common_log(LOG_ERR, $last_error->message . '(' . $verb . ' on ' . $objstr . ')', $filename);
@ -1739,7 +1739,7 @@ function common_log_db_error(&$object, $verb, $filename=NULL) {
function common_log_objstring(&$object) {
if (is_null($object)) {
return "NULL";
return "null";
}
$arr = $object->toArray();
$fields = array();
@ -1762,9 +1762,9 @@ function common_valid_tag($tag) {
return false;
}
# Does a little before-after block for next/prev page
// Does a little before-after block for next/prev page
function common_pagination($have_before, $have_after, $page, $action, $args=NULL) {
function common_pagination($have_before, $have_after, $page, $action, $args=null) {
if ($have_before || $have_after) {
common_element_start('div', array('id' => 'pagination'));
@ -1800,7 +1800,7 @@ function common_pagination($have_before, $have_after, $page, $action, $args=NULL
* and written by Evan Prodromou. */
function common_accept_to_prefs($accept, $def = '*/*') {
# No arg means accept anything (per HTTP spec)
// No arg means accept anything (per HTTP spec)
if(!$accept) {
return array($def => 1);
}
@ -1810,7 +1810,7 @@ function common_accept_to_prefs($accept, $def = '*/*') {
$parts = explode(',', $accept);
foreach($parts as $part) {
# FIXME: doesn't deal with params like 'text/html; level=1'
// FIXME: doesn't deal with params like 'text/html; level=1'
@list($value, $qpart) = explode(';', $part);
$match = array();
if(!isset($qpart)) {
@ -1833,7 +1833,7 @@ function common_mime_type_match($type, $avail) {
} elseif(array_key_exists('*/*', $avail)) {
return '*/*';
} else {
return NULL;
return null;
}
}
}
@ -1906,24 +1906,24 @@ function common_notice_uri(&$notice) {
array('notice' => $notice->id));
}
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
// 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
function common_confirmation_code($bits) {
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
// 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
static $codechars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$chars = ceil($bits/5);
$code = '';
for ($i = 0; $i < $chars; $i++) {
# XXX: convert to string and back
// XXX: convert to string and back
$num = hexdec(common_good_rand(1));
# XXX: randomness is too precious to throw away almost
# 40% of the bits we get!
// XXX: randomness is too precious to throw away almost
// 40% of the bits we get!
$code .= $codechars[$num%32];
}
return $code;
}
# convert markup to HTML
// convert markup to HTML
function common_markup_to_html($c) {
$c = preg_replace('/%%action.(\w+)%%/e', "common_local_url('\\1')", $c);
@ -1943,7 +1943,7 @@ function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) {
function common_profile_uri($profile) {
if (!$profile) {
return NULL;
return null;
}
$user = User::staticGet($profile->id);
if ($user) {
@ -1954,12 +1954,12 @@ function common_profile_uri($profile) {
if ($remote) {
return $remote->uri;
}
# XXX: this is a very bad profile!
return NULL;
// XXX: this is a very bad profile!
return null;
}
function common_canonical_sms($sms) {
# strip non-digits
// strip non-digits
preg_replace('/\D/', '', $sms);
return $sms;
}
@ -1980,7 +1980,7 @@ function common_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
break;
}
# FIXME: show error page if we're on the Web
// FIXME: show error page if we're on the Web
/* Don't execute PHP internal error handler */
return true;
}
@ -2139,7 +2139,7 @@ function common_message_form($content, $user, $to) {
$mutual_users->free();
unset($mutual_users);
common_dropdown('to', _('To'), $mutual, NULL, FALSE, $to->id);
common_dropdown('to', _('To'), $mutual, null, FALSE, $to->id);
common_element_start('p');
@ -2161,9 +2161,9 @@ function common_message_form($content, $user, $to) {
}
function common_memcache() {
static $cache = NULL;
static $cache = null;
if (!common_config('memcached', 'enabled')) {
return NULL;
return null;
} else {
if (!$cache) {
$cache = new Memcache();
@ -2181,21 +2181,21 @@ function common_memcache() {
}
function common_compatible_license($from, $to) {
# XXX: better compatibility check needed here!
// XXX: better compatibility check needed here!
return ($from == $to);
}
/* These are almost identical, so we use a helper function */
function common_block_form($profile, $args=NULL) {
function common_block_form($profile, $args=null) {
common_blocking_form('block', _('Block'), $profile, $args);
}
function common_unblock_form($profile, $args=NULL) {
function common_unblock_form($profile, $args=null) {
common_blocking_form('unblock', _('Unblock'), $profile, $args);
}
function common_blocking_form($type, $label, $profile, $args=NULL) {
function common_blocking_form($type, $label, $profile, $args=null) {
common_element_start('form', array('id' => $type . '-' . $profile->id,
'method' => 'post',
'class' => $type,
@ -2217,4 +2217,3 @@ function common_blocking_form($type, $label, $profile, $args=NULL) {
common_element_end('form');
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@
/* XXX: break up into separate modules (HTTP, HTML, user, files) */
# Show a server error
// Show a server error
function common_server_error($msg, $code=500) {
static $status = array(500 => 'Internal Server Error',
@ -43,7 +43,7 @@ function common_server_error($msg, $code=500) {
exit();
}
# Show a user error
// Show a user error
function common_user_error($msg, $code=400) {
static $status = array(400 => 'Bad Request',
401 => 'Unauthorized',
@ -79,8 +79,8 @@ function common_user_error($msg, $code=400) {
$xw = null;
# Start an HTML element
function common_element_start($tag, $attrs=NULL) {
// Start an HTML element
function common_element_start($tag, $attrs=null) {
global $xw;
$xw->startElement($tag);
if (is_array($attrs)) {
@ -97,7 +97,7 @@ function common_element_end($tag) {
'br', 'param', 'img', 'area',
'input', 'col');
global $xw;
# XXX: check namespace
// XXX: check namespace
if (in_array($tag, $empty_tag)) {
$xw->endElement();
} else {
@ -105,7 +105,7 @@ function common_element_end($tag) {
}
}
function common_element($tag, $attrs=NULL, $content=NULL) {
function common_element($tag, $attrs=null, $content=null) {
common_element_start($tag, $attrs);
global $xw;
if (!is_null($content)) {
@ -114,7 +114,7 @@ function common_element($tag, $attrs=NULL, $content=NULL) {
common_element_end($tag);
}
function common_start_xml($doc=NULL, $public=NULL, $system=NULL, $indent=true) {
function common_start_xml($doc=null, $public=null, $system=null, $indent=true) {
global $xw;
$xw = new XMLWriter();
$xw->openURI('php://output');
@ -147,7 +147,7 @@ function common_init_locale($language=null) {
function common_init_language() {
mb_internal_encoding('UTF-8');
$language = common_language();
# So we don't have to make people install the gettext locales
// So we don't have to make people install the gettext locales
$locale_set = common_init_locale($language);
bindtextdomain("laconica", common_config('site','locale_path'));
bind_textdomain_codeset("laconica", "UTF-8");
@ -160,7 +160,7 @@ function common_init_language() {
define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2');
function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) {
function common_show_header($pagetitle, $callable=null, $data=null, $headercall=null) {
global $config, $xw;
global $action; /* XXX: kind of cheating here. */
@ -168,7 +168,7 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
common_start_html();
common_element_start('head');
common_element('title', NULL,
common_element('title', null,
$pagetitle . " - " . $config['site']['name']);
common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
@ -176,7 +176,7 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
'media' => 'screen, projection, tv'));
foreach (array(6,7) as $ver) {
if (file_exists(theme_file('ie'.$ver.'.css'))) {
# Yes, IE people should be put in jail.
// Yes, IE people should be put in jail.
$xw->writeComment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
'href="'.theme_path('ie'.$ver.'.css').'?version='.LACONICA_VERSION.'" /><![endif]');
}
@ -243,12 +243,12 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=
common_element_start('div', array('id' => 'content'));
}
function common_start_html($type=NULL, $indent=true) {
function common_start_html($type=null, $indent=true) {
if (!$type) {
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL;
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
# XXX: allow content negotiation for RDF, RSS, or XRDS
// XXX: allow content negotiation for RDF, RSS, or XRDS
$type = common_negotiate_type(common_accept_to_prefs($httpaccept),
common_accept_to_prefs(PAGE_TYPE_PREFS));
@ -265,7 +265,7 @@ function common_start_html($type=NULL, $indent=true) {
'-//W3C//DTD XHTML 1.0 Strict//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd', $indent);
# FIXME: correct language for interface
// FIXME: correct language for interface
$language = common_language();
@ -276,7 +276,7 @@ function common_start_html($type=NULL, $indent=true) {
function common_show_footer() {
global $xw, $config;
common_element_end('div'); # content div
common_element_end('div'); // content div
common_foot_menu();
common_element_start('div', array('id' => 'footer'));
common_element_start('div', 'laconica');
@ -361,7 +361,7 @@ function common_foot_menu() {
common_element_end('ul');
}
function common_menu_item($url, $text, $title=NULL, $is_selected=false) {
function common_menu_item($url, $text, $title=null, $is_selected=false) {
$lattrs = array();
if ($is_selected) {
$lattrs['class'] = 'current';
@ -375,7 +375,7 @@ function common_menu_item($url, $text, $title=NULL, $is_selected=false) {
common_element_end('li');
}
function common_input($id, $label, $value=NULL,$instructions=NULL) {
function common_input($id, $label, $value=null,$instructions=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
$attrs = array('name' => $id,
@ -392,7 +392,7 @@ function common_input($id, $label, $value=NULL,$instructions=NULL) {
common_element_end('p');
}
function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value='true', $disabled=false)
function common_checkbox($id, $label, $checked=false, $instructions=null, $value='true', $disabled=false)
{
common_element_start('p');
$attrs = array('name' => $id,
@ -418,7 +418,7 @@ function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value
common_element_end('p');
}
function common_dropdown($id, $label, $content, $instructions=NULL, $blank_select=FALSE, $selected=NULL) {
function common_dropdown($id, $label, $content, $instructions=null, $blank_select=FALSE, $selected=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
common_element_start('select', array('id' => $id, 'name' => $id));
@ -445,7 +445,7 @@ function common_hidden($id, $value) {
'value' => $value));
}
function common_password($id, $label, $instructions=NULL) {
function common_password($id, $label, $instructions=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
$attrs = array('name' => $id,
@ -470,7 +470,7 @@ function common_submit($id, $label, $cls='submit') {
common_element_end('p');
}
function common_textarea($id, $label, $content=NULL, $instructions=NULL) {
function common_textarea($id, $label, $content=null, $instructions=null) {
common_element_start('p');
common_element('label', array('for' => $id), $label);
common_element('textarea', array('rows' => 3,
@ -509,7 +509,7 @@ function common_language() {
// Otherwise, find the best match for the languages requested by the
// user's browser...
$httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL;
$httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
if (!empty($httplang)) {
$language = client_prefered_language($httplang);
if ($language)
@ -519,15 +519,15 @@ function common_language() {
// Finally, if none of the above worked, use the site's default...
return common_config('site', 'language');
}
# salted, hashed passwords are stored in the DB
// salted, hashed passwords are stored in the DB
function common_munge_password($password, $id) {
return md5($password . $id);
}
# check if a username exists and has matching password
// check if a username exists and has matching password
function common_check_user($nickname, $password) {
# NEVER allow blank passwords, even if they match the DB
// NEVER allow blank passwords, even if they match the DB
if (mb_strlen($password) == 0) {
return false;
}
@ -544,7 +544,7 @@ function common_check_user($nickname, $password) {
}
}
# is the current user logged in?
// is the current user logged in?
function common_logged_in() {
return (!is_null(common_current_user()));
}
@ -559,12 +559,12 @@ function common_ensure_session() {
}
}
# Three kinds of arguments:
# 1) a user object
# 2) a nickname
# 3) NULL to clear
// Three kinds of arguments:
// 1) a user object
// 2) a nickname
// 3) null to clear
# Initialize to false; set to NULL if none found
// Initialize to false; set to null if none found
$_cur = false;
@ -573,7 +573,7 @@ function common_set_user($user) {
global $_cur;
if (is_null($user) && common_have_session()) {
$_cur = NULL;
$_cur = null;
unset($_SESSION['userid']);
return true;
} else if (is_string($user)) {
@ -609,9 +609,9 @@ function common_set_cookie($key, $value, $expiration=0) {
}
define('REMEMBERME', 'rememberme');
define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); # 30 days
define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); // 30 days
function common_rememberme($user=NULL) {
function common_rememberme($user=null) {
if (!$user) {
$user = common_current_user();
if (!$user) {
@ -625,7 +625,7 @@ function common_rememberme($user=NULL) {
$rm->code = common_good_rand(16);
$rm->user_id = $user->id;
# Wrap the insert in some good ol' fashioned transaction code
// Wrap the insert in some good ol' fashioned transaction code
$rm->query('BEGIN');
@ -652,12 +652,12 @@ function common_rememberme($user=NULL) {
function common_remembered_user() {
$user = NULL;
$user = null;
$packed = isset($_COOKIE[REMEMBERME]) ? $_COOKIE[REMEMBERME] : NULL;
$packed = isset($_COOKIE[REMEMBERME]) ? $_COOKIE[REMEMBERME] : null;
if (!$packed) {
return NULL;
return null;
}
list($id, $code) = explode(':', $packed);
@ -665,7 +665,7 @@ function common_remembered_user() {
if (!$id || !$code) {
common_log(LOG_WARNING, 'Malformed rememberme cookie: ' . $packed);
common_forgetme();
return NULL;
return null;
}
$rm = Remember_me::staticGet($code);
@ -673,13 +673,13 @@ function common_remembered_user() {
if (!$rm) {
common_log(LOG_WARNING, 'No such remember code: ' . $code);
common_forgetme();
return NULL;
return null;
}
if ($rm->user_id != $id) {
common_log(LOG_WARNING, 'Rememberme code for wrong user: ' . $rm->user_id . ' != ' . $id);
common_forgetme();
return NULL;
return null;
}
$user = User::staticGet($rm->user_id);
@ -687,17 +687,17 @@ function common_remembered_user() {
if (!$user) {
common_log(LOG_WARNING, 'No such user for rememberme: ' . $rm->user_id);
common_forgetme();
return NULL;
return null;
}
# successful!
// successful!
$result = $rm->delete();
if (!$result) {
common_log_db_error($rm, 'DELETE', __FILE__);
common_log(LOG_WARNING, 'Could not delete rememberme: ' . $code);
common_forgetme();
return NULL;
return null;
}
common_log(LOG_INFO, 'logging in ' . $user->nickname . ' using rememberme code ' . $rm->code);
@ -705,21 +705,21 @@ function common_remembered_user() {
common_set_user($user);
common_real_login(false);
# We issue a new cookie, so they can log in
# automatically again after this session
// We issue a new cookie, so they can log in
// automatically again after this session
common_rememberme($user);
return $user;
}
# must be called with a valid user!
// must be called with a valid user!
function common_forgetme() {
common_set_cookie(REMEMBERME, '', 0);
}
# who is the current user?
// who is the current user?
function common_current_user() {
global $_cur;
@ -734,13 +734,13 @@ function common_current_user() {
}
}
# that didn't work; try to remember; will init $_cur to NULL on failure
// that didn't work; try to remember; will init $_cur to null on failure
$_cur = common_remembered_user();
if ($_cur) {
common_debug("Got User " . $_cur->nickname);
common_debug("Faking session on remembered user");
# XXX: Is this necessary?
// XXX: Is this necessary?
$_SESSION['userid'] = $_cur->id;
}
}
@ -748,9 +748,9 @@ function common_current_user() {
return $_cur;
}
# Logins that are 'remembered' aren't 'real' -- they're subject to
# cookie-stealing. So, we don't let them do certain things. New reg,
# OpenID, and password logins _are_ real.
// Logins that are 'remembered' aren't 'real' -- they're subject to
// cookie-stealing. So, we don't let them do certain things. New reg,
// OpenID, and password logins _are_ real.
function common_real_login($real=true) {
common_ensure_session();
@ -761,16 +761,16 @@ function common_is_real_login() {
return common_logged_in() && $_SESSION['real_login'];
}
# get canonical version of nickname for comparison
// get canonical version of nickname for comparison
function common_canonical_nickname($nickname) {
# XXX: UTF-8 canonicalization (like combining chars)
// XXX: UTF-8 canonicalization (like combining chars)
return strtolower($nickname);
}
# get canonical version of email for comparison
// get canonical version of email for comparison
function common_canonical_email($email) {
# XXX: canonicalize UTF-8
# XXX: lcase the domain part
// XXX: canonicalize UTF-8
// XXX: lcase the domain part
return $email;
}
@ -791,7 +791,7 @@ function common_render_text($text) {
$r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
$r = preg_replace_callback('@https?://[^\]>\s]+@', 'common_render_uri_thingy', $r);
$r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
# XXX: machine tags
// XXX: machine tags
return $r;
}
@ -799,16 +799,16 @@ function common_render_uri_thingy($matches) {
$uri = $matches[0];
$trailer = '';
# Some heuristics for extracting URIs from surrounding punctuation
# Strip from trailing text...
// Some heuristics for extracting URIs from surrounding punctuation
// Strip from trailing text...
if (preg_match('/^(.*)([,.:"\']+)$/', $uri, $matches)) {
$uri = $matches[1];
$trailer = $matches[2];
}
$pairs = array(
']' => '[', # technically disallowed in URIs, but used in Java docs
')' => '(', # far too frequent in Wikipedia and MSDN
']' => '[', // technically disallowed in URIs, but used in Java docs
')' => '(', // far too frequent in Wikipedia and MSDN
);
$final = substr($uri, -1, 1);
if (isset($pairs[$final])) {
@ -958,28 +958,28 @@ function common_at_hash_link($sender_id, $tag) {
}
}
function common_relative_profile($sender, $nickname, $dt=NULL) {
# Try to find profiles this profile is subscribed to that have this nickname
function common_relative_profile($sender, $nickname, $dt=null) {
// Try to find profiles this profile is subscribed to that have this nickname
$recipient = new Profile();
# XXX: use a join instead of a subquery
// XXX: use a join instead of a subquery
$recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender->id.' and subscribed = id)', 'AND');
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
if ($recipient->find(TRUE)) {
# XXX: should probably differentiate between profiles with
# the same name by date of most recent update
// XXX: should probably differentiate between profiles with
// the same name by date of most recent update
return $recipient;
}
# Try to find profiles that listen to this profile and that have this nickname
// Try to find profiles that listen to this profile and that have this nickname
$recipient = new Profile();
# XXX: use a join instead of a subquery
// XXX: use a join instead of a subquery
$recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender->id.' and subscriber = id)', 'AND');
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
if ($recipient->find(TRUE)) {
# XXX: should probably differentiate between profiles with
# the same name by date of most recent update
// XXX: should probably differentiate between profiles with
// the same name by date of most recent update
return $recipient;
}
# If this is a local user, try to find a local user with that nickname.
// If this is a local user, try to find a local user with that nickname.
$sender = User::staticGet($sender->id);
if ($sender) {
$recipient_user = User::staticGet('nickname', $nickname);
@ -987,15 +987,15 @@ function common_relative_profile($sender, $nickname, $dt=NULL) {
return $recipient_user->getProfile();
}
}
# Otherwise, no links. @messages from local users to remote users,
# or from remote users to other remote users, are just
# outside our ability to make intelligent guesses about
return NULL;
// Otherwise, no links. @messages from local users to remote users,
// or from remote users to other remote users, are just
// outside our ability to make intelligent guesses about
return null;
}
// where should the avatar go for this user?
function common_avatar_filename($id, $extension, $size=NULL, $extra=NULL) {
function common_avatar_filename($id, $extension, $size=null, $extra=null) {
global $config;
if ($size) {
@ -1030,8 +1030,8 @@ function common_default_avatar($size) {
return theme_path('default-avatar-'.$sizenames[$size].'.png');
}
function common_local_url($action, $args=NULL, $fragment=NULL) {
$url = NULL;
function common_local_url($action, $args=null, $fragment=null) {
$url = null;
if (common_config('site','fancy')) {
$url = common_fancy_url($action, $args);
} else {
@ -1043,7 +1043,7 @@ function common_local_url($action, $args=NULL, $fragment=NULL) {
return $url;
}
function common_fancy_url($action, $args=NULL) {
function common_fancy_url($action, $args=null) {
switch (strtolower($action)) {
case 'public':
if ($args && isset($args['page'])) {
@ -1229,7 +1229,7 @@ function common_fancy_url($action, $args=NULL) {
case 'newmessage':
return common_path('message/new' . (($args) ? ('?' . http_build_query($args)) : ''));
case 'api':
# XXX: do fancy URLs for all the API methods
// XXX: do fancy URLs for all the API methods
switch (strtolower($args['apiaction'])) {
case 'statuses':
switch (strtolower($args['method'])) {
@ -1256,7 +1256,7 @@ function common_fancy_url($action, $args=NULL) {
}
}
function common_simple_url($action, $args=NULL) {
function common_simple_url($action, $args=null) {
global $config;
/* XXX: pretty URLs */
$extra = '';
@ -1281,7 +1281,7 @@ function common_date_string($dt) {
$now = time();
$diff = $now - $t;
if ($now < $t) { # that shouldn't happen!
if ($now < $t) { // that shouldn't happen!
return common_exact_date($dt);
} else if ($diff < 60) {
return _('a few seconds ago');
@ -1365,18 +1365,18 @@ function common_redirect($url, $code=307) {
}
function common_save_replies($notice) {
# Alternative reply format
// Alternative reply format
$tname = false;
if (preg_match('/^T ([A-Z0-9]{1,64}) /', $notice->content, $match)) {
$tname = $match[1];
}
# extract all @messages
// extract all @messages
$cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
$names = array();
if ($cnt || $tname) {
# XXX: is there another way to make an array copy?
// XXX: is there another way to make an array copy?
$names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]);
}
@ -1384,8 +1384,8 @@ function common_save_replies($notice) {
$replied = array();
# store replied only for first @ (what user/notice what the reply directed,
# we assume first @ is it)
// store replied only for first @ (what user/notice what the reply directed,
// we assume first @ is it)
for ($i=0; $i<count($names); $i++) {
$nickname = $names[$i];
@ -1393,7 +1393,7 @@ function common_save_replies($notice) {
if (!$recipient) {
continue;
}
if ($i == 0 && ($recipient->id != $sender->id) && !$notice->reply_to) { # Don't save reply to self
if ($i == 0 && ($recipient->id != $sender->id) && !$notice->reply_to) { // Don't save reply to self
$reply_for = $recipient;
$recipient_notice = $reply_for->getCurrentNotice();
if ($recipient_notice) {
@ -1402,7 +1402,7 @@ function common_save_replies($notice) {
$notice->update($orig);
}
}
# Don't save replies from blocked profile to local user
// Don't save replies from blocked profile to local user
$recipient_user = User::staticGet('id', $recipient->id);
if ($recipient_user && $recipient_user->hasBlocked($sender)) {
continue;
@ -1421,14 +1421,14 @@ function common_save_replies($notice) {
}
}
# Hash format replies, too
// Hash format replies, too
$cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $notice->content, $match);
if ($cnt) {
foreach ($match[1] as $tag) {
$tagged = Profile_tag::getTagged($sender->id, $tag);
foreach ($tagged as $t) {
if (!$replied[$t->id]) {
# Don't save replies from blocked profile to local user
// Don't save replies from blocked profile to local user
$t_user = User::staticGet('id', $t->id);
if ($t_user && $t_user->hasBlocked($sender)) {
continue;
@ -1467,7 +1467,7 @@ function common_broadcast_notice($notice, $remote=false) {
}
if (common_config('queue', 'enabled')) {
# Do it later!
// Do it later!
return common_enqueue_notice($notice);
} else {
return common_real_broadcast($notice, $remote);
@ -1532,7 +1532,7 @@ function common_twitter_broadcast($notice, $flink) {
return $success;
}
# Stick the notice on the queue
// Stick the notice on the queue
function common_enqueue_notice($notice) {
foreach (array('jabber', 'omb', 'sms', 'public') as $transport) {
@ -1570,7 +1570,7 @@ function common_dequeue_notice($notice) {
function common_real_broadcast($notice, $remote=false) {
$success = true;
if (!$remote) {
# Make sure we have the OMB stuff
// Make sure we have the OMB stuff
require_once(INSTALLDIR.'/lib/omb.php');
$success = omb_broadcast_remote_subscribers($notice);
if (!$success) {
@ -1613,9 +1613,9 @@ function common_profile_url($nickname) {
return common_local_url('showstream', array('nickname' => $nickname));
}
# Don't call if nobody's logged in
// Don't call if nobody's logged in
function common_notice_form($action=NULL, $content=NULL) {
function common_notice_form($action=null, $content=null) {
$user = common_current_user();
assert(!is_null($user));
common_element_start('form', array('id' => 'status_form',
@ -1635,7 +1635,7 @@ function common_notice_form($action=NULL, $content=NULL) {
if ($action) {
common_hidden('returnto', $action);
}
# set by JavaScript
// set by JavaScript
common_hidden('inreplyto', 'false');
common_element('input', array('id' => 'status_submit',
'name' => 'status_submit',
@ -1645,27 +1645,27 @@ function common_notice_form($action=NULL, $content=NULL) {
common_element_end('form');
}
# Should make up a reasonable root URL
// Should make up a reasonable root URL
function common_root_url() {
return common_path('');
}
# returns $bytes bytes of random data as a hexadecimal string
# "good" here is a goal and not a guarantee
// returns $bytes bytes of random data as a hexadecimal string
// "good" here is a goal and not a guarantee
function common_good_rand($bytes) {
# XXX: use random.org...?
// XXX: use random.org...?
if (file_exists('/dev/urandom')) {
return common_urandom($bytes);
} else { # FIXME: this is probably not good enough
} else { // FIXME: this is probably not good enough
return common_mtrand($bytes);
}
}
function common_urandom($bytes) {
$h = fopen('/dev/urandom', 'rb');
# should not block
// should not block
$src = fread($h, $bytes);
fclose($h);
$enc = '';
@ -1706,7 +1706,7 @@ function common_ensure_syslog() {
}
}
function common_log($priority, $msg, $filename=NULL) {
function common_log($priority, $msg, $filename=null) {
$logfile = common_config('site', 'logfile');
if ($logfile) {
$log = fopen($logfile, "a");
@ -1723,7 +1723,7 @@ function common_log($priority, $msg, $filename=NULL) {
}
}
function common_debug($msg, $filename=NULL) {
function common_debug($msg, $filename=null) {
if ($filename) {
common_log(LOG_DEBUG, basename($filename).' - '.$msg);
} else {
@ -1731,7 +1731,7 @@ function common_debug($msg, $filename=NULL) {
}
}
function common_log_db_error(&$object, $verb, $filename=NULL) {
function common_log_db_error(&$object, $verb, $filename=null) {
$objstr = common_log_objstring($object);
$last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
common_log(LOG_ERR, $last_error->message . '(' . $verb . ' on ' . $objstr . ')', $filename);
@ -1739,7 +1739,7 @@ function common_log_db_error(&$object, $verb, $filename=NULL) {
function common_log_objstring(&$object) {
if (is_null($object)) {
return "NULL";
return "null";
}
$arr = $object->toArray();
$fields = array();
@ -1762,9 +1762,9 @@ function common_valid_tag($tag) {
return false;
}
# Does a little before-after block for next/prev page
// Does a little before-after block for next/prev page
function common_pagination($have_before, $have_after, $page, $action, $args=NULL) {
function common_pagination($have_before, $have_after, $page, $action, $args=null) {
if ($have_before || $have_after) {
common_element_start('div', array('id' => 'pagination'));
@ -1800,7 +1800,7 @@ function common_pagination($have_before, $have_after, $page, $action, $args=NULL
* and written by Evan Prodromou. */
function common_accept_to_prefs($accept, $def = '*/*') {
# No arg means accept anything (per HTTP spec)
// No arg means accept anything (per HTTP spec)
if(!$accept) {
return array($def => 1);
}
@ -1810,7 +1810,7 @@ function common_accept_to_prefs($accept, $def = '*/*') {
$parts = explode(',', $accept);
foreach($parts as $part) {
# FIXME: doesn't deal with params like 'text/html; level=1'
// FIXME: doesn't deal with params like 'text/html; level=1'
@list($value, $qpart) = explode(';', $part);
$match = array();
if(!isset($qpart)) {
@ -1833,7 +1833,7 @@ function common_mime_type_match($type, $avail) {
} elseif(array_key_exists('*/*', $avail)) {
return '*/*';
} else {
return NULL;
return null;
}
}
}
@ -1906,24 +1906,24 @@ function common_notice_uri(&$notice) {
array('notice' => $notice->id));
}
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
// 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
function common_confirmation_code($bits) {
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
// 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
static $codechars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$chars = ceil($bits/5);
$code = '';
for ($i = 0; $i < $chars; $i++) {
# XXX: convert to string and back
// XXX: convert to string and back
$num = hexdec(common_good_rand(1));
# XXX: randomness is too precious to throw away almost
# 40% of the bits we get!
// XXX: randomness is too precious to throw away almost
// 40% of the bits we get!
$code .= $codechars[$num%32];
}
return $code;
}
# convert markup to HTML
// convert markup to HTML
function common_markup_to_html($c) {
$c = preg_replace('/%%action.(\w+)%%/e', "common_local_url('\\1')", $c);
@ -1943,7 +1943,7 @@ function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) {
function common_profile_uri($profile) {
if (!$profile) {
return NULL;
return null;
}
$user = User::staticGet($profile->id);
if ($user) {
@ -1954,12 +1954,12 @@ function common_profile_uri($profile) {
if ($remote) {
return $remote->uri;
}
# XXX: this is a very bad profile!
return NULL;
// XXX: this is a very bad profile!
return null;
}
function common_canonical_sms($sms) {
# strip non-digits
// strip non-digits
preg_replace('/\D/', '', $sms);
return $sms;
}
@ -1980,7 +1980,7 @@ function common_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
break;
}
# FIXME: show error page if we're on the Web
// FIXME: show error page if we're on the Web
/* Don't execute PHP internal error handler */
return true;
}
@ -2139,7 +2139,7 @@ function common_message_form($content, $user, $to) {
$mutual_users->free();
unset($mutual_users);
common_dropdown('to', _('To'), $mutual, NULL, FALSE, $to->id);
common_dropdown('to', _('To'), $mutual, null, FALSE, $to->id);
common_element_start('p');
@ -2161,9 +2161,9 @@ function common_message_form($content, $user, $to) {
}
function common_memcache() {
static $cache = NULL;
static $cache = null;
if (!common_config('memcached', 'enabled')) {
return NULL;
return null;
} else {
if (!$cache) {
$cache = new Memcache();
@ -2181,21 +2181,21 @@ function common_memcache() {
}
function common_compatible_license($from, $to) {
# XXX: better compatibility check needed here!
// XXX: better compatibility check needed here!
return ($from == $to);
}
/* These are almost identical, so we use a helper function */
function common_block_form($profile, $args=NULL) {
function common_block_form($profile, $args=null) {
common_blocking_form('block', _('Block'), $profile, $args);
}
function common_unblock_form($profile, $args=NULL) {
function common_unblock_form($profile, $args=null) {
common_blocking_form('unblock', _('Unblock'), $profile, $args);
}
function common_blocking_form($type, $label, $profile, $args=NULL) {
function common_blocking_form($type, $label, $profile, $args=null) {
common_element_start('form', array('id' => $type . '-' . $profile->id,
'method' => 'post',
'class' => $type,
@ -2217,4 +2217,3 @@ function common_blocking_form($type, $label, $profile, $args=NULL) {
common_element_end('form');
return;
}