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
# 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;
}
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",
}
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;
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() {
static $initialized = false;
if (!$initialized) {
global $config;
- define_syslog_variables();
openlog($config['syslog']['appname'], 0, LOG_USER);
$initialized = true;
}
return common_default_avatar($size);
}
}
-
\ No newline at end of file
+
+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