function common_element_end($tag) {
static $empty_tag = array('base', 'meta', 'link', 'hr',
'br', 'param', 'img', 'area',
- 'input', 'col');
+ 'input', 'col');
global $xw;
# XXX: check namespace
if (in_array($tag, $empty_tag)) {
common_accept_to_prefs(PAGE_TYPE_PREFS));
if (!$type) {
- common_user_error(_t('This page is not available in a media type you accept'), 406);
+ common_user_error(_('This page is not available in a media type you accept'), 406);
exit(0);
}
common_element_start('div', array('id' => 'content'));
}
+# XXX: Refactor w/common_user_error() ?
+function common_show_basic_auth_error() {
+ header('HTTP/1.1 401 Unauthorized');
+ header('Content-type: text/plain');
+ print("Could not authenticate you.\n"); # exactly what Twitter says
+ exit();
+}
+
function common_show_footer() {
global $xw, $config;
common_element_end('div'); # content div
common_element_start('div', array('id' => 'footer'));
common_element_start('div', 'laconica');
if (common_config('site', 'broughtby')) {
- $instr = _t('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
+ $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
} else {
- $instr = _t('**%%site.name%%** is a microblogging service. ');
+ $instr = _('**%%site.name%%** is a microblogging service. ');
}
- $instr .= _t('It runs the [Laconica](http://laconi.ca/) ' .
- 'microblogging software, version ' . LACONICA_VERSION . ', ' .
- 'available under the ' .
- '[GNU Affero General Public License]' .
- '(http://www.fsf.org/licensing/licenses/agpl-3.0.html).');
+ $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION);
$output = common_markup_to_html($instr);
common_raw($output);
common_element_end('div');
'src' => $config['license']['image'],
'alt' => $config['license']['title']));
common_element_start('p');
- common_text(_t('Unless otherwise specified, contents of this site are copyright by the contributors and available under the '));
+ common_text(_('Unless otherwise specified, contents of this site are copyright by the contributors and available under the '));
common_element('a', array('class' => 'license',
'rel' => 'license',
href => $config['license']['url']),
$config['license']['title']);
- common_text(_t('. Contributors should be attributed by full name or nickname.'));
+ common_text(_('. Contributors should be attributed by full name or nickname.'));
common_element_end('p');
common_element_end('div');
common_element_end('div');
common_element_start('ul', array('id' => 'nav'));
if ($user) {
common_menu_item(common_local_url('all', array('nickname' => $user->nickname)),
- _t('Home'));
+ _('Home'));
}
- common_menu_item(common_local_url('public'), _t('Public'));
- common_menu_item(common_local_url('peoplesearch'), _t('Search'));
+ common_menu_item(common_local_url('public'), _('Public'));
+ common_menu_item(common_local_url('peoplesearch'), _('Search'));
common_menu_item(common_local_url('doc', array('title' => 'help')),
- _t('Help'));
+ _('Help'));
if ($user) {
common_menu_item(common_local_url('profilesettings'),
- _t('Settings'));
+ _('Settings'));
common_menu_item(common_local_url('logout'),
- _t('Logout'));
+ _('Logout'));
} else {
- common_menu_item(common_local_url('login'), _t('Login'));
- common_menu_item(common_local_url('register'), _t('Register'));
- common_menu_item(common_local_url('openidlogin'), _t('OpenID'));
+ common_menu_item(common_local_url('login'), _('Login'));
+ common_menu_item(common_local_url('register'), _('Register'));
+ common_menu_item(common_local_url('openidlogin'), _('OpenID'));
}
common_element_end('ul');
}
function common_foot_menu() {
common_element_start('ul', array('id' => 'nav_sub'));
common_menu_item(common_local_url('doc', array('title' => 'about')),
- _t('About'));
+ _('About'));
common_menu_item(common_local_url('doc', array('title' => 'faq')),
- _t('FAQ'));
+ _('FAQ'));
common_menu_item(common_local_url('doc', array('title' => 'privacy')),
- _t('Privacy'));
+ _('Privacy'));
common_menu_item(common_local_url('doc', array('title' => 'source')),
- _t('Source'));
+ _('Source'));
common_menu_item(common_local_url('doc', array('title' => 'contact')),
- _t('Contact'));
+ _('Contact'));
common_element_end('ul');
}
} else if (!($user instanceof User)) {
return false;
}
-
+
if ($user) {
common_ensure_session();
$_SESSION['userid'] = $user->id;
# who is the current user?
function common_current_user() {
- if ($_REQUEST[session_name()]) {
+ if ($_REQUEST[session_name()] || $_SESSION && $_SESSION['userid']) {
common_ensure_session();
$id = $_SESSION['userid'];
if ($id) {
}
# that didn't work; try to remember
$user = common_remembered_user();
+ common_debug("Got User " . $user->nickname);
+ if ($user) {
+ common_debug("Faking session on remembered user");
+ $_SESSION['userid'] = $user->id;
+ }
return $user;
}
function common_render_content($text, $notice) {
$r = htmlspecialchars($text);
$id = $notice->profile_id;
- $r = preg_replace('@https?://\S+@', '<a href="\0" class="extlink">\0</a>', $r);
+ $r = preg_replace('@https?://[^)\]>\s]+@', '<a href="\0" class="extlink">\0</a>', $r);
$r = preg_replace('/(^|\s+)@([a-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r);
+ $r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r);
# XXX: # tags
# XXX: machine tags
return $r;
return common_path('settings/'.$action);
case 'profilesettings':
return common_path('settings/profile');
+ case 'emailsettings':
+ return common_path('settings/email');
case 'openidsettings':
return common_path('settings/openid');
case 'newnotice':
if ($now < $t) { # that shouldn't happen!
return common_exact_date($dt);
} else if ($diff < 60) {
- return _t('a few seconds ago');
+ return _('a few seconds ago');
} else if ($diff < 92) {
- return _t('about a minute ago');
+ return _('about a minute ago');
} else if ($diff < 3300) {
- return _t('about ') . round($diff/60) . _t(' minutes ago');
+ return sprintf(_('about %d minutes ago'), round($diff/60));
} else if ($diff < 5400) {
- return _t('about an hour ago');
+ return _('about an hour ago');
} else if ($diff < 22 * 3600) {
- return _t('about ') . round($diff/3600) . _t(' hours ago');
+ return sprintf(_('about %d hours ago'), round($diff/3600));
} else if ($diff < 37 * 3600) {
- return _t('about a day ago');
+ return _('about a day ago');
} else if ($diff < 24 * 24 * 3600) {
- return _t('about ') . round($diff/(24*3600)) . _t(' days ago');
+ return sprintf(_('about %d days ago'), round($diff/(24*3600)));
} else if ($diff < 46 * 24 * 3600) {
- return _t('about a month ago');
+ return _('about a month ago');
} else if ($diff < 330 * 24 * 3600) {
- return _t('about ') . round($diff/(30*24*3600)) . _t(' months ago');
+ return sprintf(_('about %d months ago'), round($diff/(30*24*3600)));
} else if ($diff < 480 * 24 * 3600) {
- return _t('about a year ago');
+ return _('about a year ago');
} else {
return common_exact_date($dt);
}
return date(DATE_W3C, $t);
}
+function common_date_rfc2822($dt) {
+ $t = strtotime($dt);
+ return date("r", $t);
+}
+
+function common_date_iso8601($dt) {
+ $t = strtotime($dt);
+ return date("c", $t);
+}
+
function common_redirect($url, $code=307) {
static $status = array(301 => "Moved Permanently",
302 => "Found",
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
common_element('a', array('href' => $url), $url);
common_end_xml();
+ exit;
}
function common_save_replies($notice) {
+ # Alternative reply format
+ if (preg_match('/^T ([A-Z0-9]{1,64}) /', $notice->content, $match)) {
+ $tname = $match[1];
+ }
# extract all @messages
$cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
- if (!$cnt) {
+ if (!$cnt && !$tname) {
return true;
}
+ # 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]);
$sender = Profile::staticGet($notice->profile_id);
# store replied only for first @ (what user/notice what the reply directed,
# we assume first @ is it)
- for ($i=0; $i<count($match[1]); $i++) {
- $nickname = $match[1][$i];
+ for ($i=0; $i<count($names); $i++) {
+ $nickname = $names[$i];
$recipient = common_relative_profile($sender, $nickname, $notice->created);
if (!$recipient) {
continue;
if (!$id) {
$last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
common_log(LOG_ERROR, 'DB error inserting reply: ' . $last_error->message);
- common_server_error('DB error inserting reply: ' . $last_error->message);
+ common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message));
return;
}
}
common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id);
return $result;
}
-
+
function common_real_broadcast($notice, $remote=false) {
$success = true;
if (!$remote) {
common_element_start('p');
common_element('label', array('for' => 'status_textarea',
'id' => 'status_label'),
- _t('What\'s up, ').$user->nickname.'?');
+ sprintf(_('What\'s up, %s?'), $user->nickname));
common_element('span', array('id' => 'counter', 'class' => 'counter'), '140');
common_element('textarea', array('id' => 'status_textarea',
'cols' => 60,
common_element('input', array('id' => 'status_submit',
'name' => 'status_submit',
'type' => 'submit',
- 'value' => _t('Send')));
+ 'value' => _('Send')));
common_element_end('p');
common_element_end('form');
}
-function common_mint_tag($extra) {
- global $config;
- return
- 'tag:'.$config['tag']['authority'].','.
- $config['tag']['date'].':'.$config['tag']['prefix'].$extra;
-}
-
# Should make up a reasonable root URL
function common_root_url() {
return date('YmdHis');
}
-// XXX: set up gettext
-
-function _t($str) {
- return $str;
-}
-
function common_ensure_syslog() {
static $initialized = false;
if (!$initialized) {
global $config;
- define_syslog_variables();
openlog($config['syslog']['appname'], 0, LOG_USER);
$initialized = true;
}
if ($logfile) {
$log = fopen($logfile, "a");
if ($log) {
- static $syslog_priorities = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR',
+ static $syslog_priorities = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR',
'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG');
$output = date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n";
fwrite($log, $output);
common_element_start('li', 'before');
common_element('a', array('href' => common_local_url($action, $newargs)),
- _t('« After'));
+ _('« After'));
common_element_end('li');
}
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
common_element_start('li', 'after');
common_element('a', array('href' => common_local_url($action, $newargs)),
- _t('Before »'));
+ _('Before »'));
common_element_end('li');
}
$c = preg_replace('/%%(\w+).(\w+)%%/e', 'common_config(\'\\1\', \'\\2\')', $c);
return Markdown($c);
}
+
+function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) {
+ $avatar = $profile->getAvatar($size);
+ if ($avatar) {
+ return common_avatar_display_url($avatar);
+ } else {
+ return common_default_avatar($size);
+ }
+}
+
+function common_profile_uri($profile) {
+ if (!$profile) {
+ return NULL;
+ }
+ $user = User::staticGet($profile->id);
+ if ($user) {
+ return $user->uri;
+ }
+
+ $remote = Remote_profile::staticGet($profile->id);
+ if ($remote) {
+ return $remote->uri;
+ }
+ # XXX: this is a very bad profile!
+ return NULL;
+}
\ No newline at end of file