X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=d461a0a0300473d99bcf3f3adc22b91015d1bdfe;hb=fba25b0d9810dac55a27feed173437a2a2f61364;hp=f7b66c07df40532659afd55258c4f6de07c62074;hpb=834c21b2aaf78da1081416d05098286e9bf17c2a;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index f7b66c07df..d461a0a030 100644 --- a/lib/util.php +++ b/lib/util.php @@ -223,6 +223,14 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall= 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 @@ -234,7 +242,7 @@ function common_show_footer() { } else { $instr = _('**%%site.name%%** is a microblogging service. '); } - $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); + $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'); @@ -548,7 +556,7 @@ function common_forgetme() { # 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) { @@ -559,6 +567,11 @@ function common_current_user() { } # 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; } @@ -593,8 +606,9 @@ define('URL_REGEX', '^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet function common_render_content($text, $notice) { $r = htmlspecialchars($text); $id = $notice->profile_id; - $r = preg_replace('@https?://\S+@', '\0', $r); + $r = preg_replace('@https?://[^)\]>\s]+@', '\0', $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; @@ -724,6 +738,8 @@ function common_fancy_url($action, $args=NULL) { 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': @@ -862,16 +878,22 @@ function common_redirect($url, $code=307) { } 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; $icreated); if (!$recipient) { continue; @@ -984,13 +1006,6 @@ function common_notice_form($action=NULL, $content=NULL) { 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() { @@ -1047,7 +1062,6 @@ function common_ensure_syslog() { static $initialized = false; if (!$initialized) { global $config; - define_syslog_variables(); openlog($config['syslog']['appname'], 0, LOG_USER); $initialized = true; } @@ -1269,3 +1283,29 @@ function common_markup_to_html($c) { $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