-function common_munge_password($id, $password) {
- return md5($id . $password);
-}
-
-# check if a username exists and has matching password
-function common_check_user($nickname, $password) {
- $user = User::staticGet('nickname', $nickname);
- if (is_null($user)) {
- return false;
- } else {
- return (0 == strcmp(common_munge_password($password, $user->id),
- $user->password));
- }
-}
-
-# is the current user logged in?
-function common_logged_in() {
- return (!is_null(common_current_user()));
-}
-
-function common_have_session() {
- return (0 != strcmp(session_id(), ''));
-}
-
-function common_ensure_session() {
- if (!common_have_session()) {
- @session_start();
- }
-}
-
-function common_set_user($nickname) {
- if (is_null($nickname) && common_have_session()) {
- unset($_SESSION['userid']);
- return true;
- } else {
- $user = User::staticGet('nickname', $nickname);
- if ($user) {
- common_ensure_session();
- $_SESSION['userid'] = $user->id;
- return true;
- } else {
- return false;
- }
- }
- return false;
-}
-
-# who is the current user?
-function common_current_user() {
- static $user = NULL; # FIXME: global memcached
- if (is_null($user)) {
- if (common_have_session()) {
- $id = $_SESSION['userid'];
- if ($id) {
- $user = User::staticGet($id);
- }
- }
- }
- return $user;
-}
-
-# get canonical version of nickname for comparison
-function common_canonical_nickname($nickname) {
- # XXX: UTF-8 canonicalization (like combining chars)
- return strtolower($nickname);
-}
-
-function common_render_content($text) {
- # XXX: @ messages
- # XXX: # tags
- # XXX: machine tags
- return htmlspecialchars($text);
-}
-
-// where should the avatar go for this user?
-
-function common_avatar_filename($user, $extension, $size=NULL) {
- global $config;
-
- if ($size) {
- return $user->id . '-' . $size . $extension;
- } else {
- return $user->id . '-original' . $extension;
- }
-}
-
-function common_avatar_path($filename) {
- global $config;
- return $config['avatar']['directory'] . '/' . $filename;
-}
-
-function common_avatar_url($filename) {
- global $config;
- return $config['avatar']['path'] . '/' . $filename;
-}
-
-function common_local_url($action, $args=NULL) {
- global $config;
- /* XXX: pretty URLs */
- $extra = '';
- if ($args) {
- foreach ($args as $key => $value) {
- $extra .= "&${key}=${value}";
- }
- }
- return "http://".$config['site']['server'].'/'.$config['site']['path']."/index.php?action=${action}${extra}";
-}
-
-function commmon_date_string($dt) {
- // XXX: do some sexy date formatting
- return date(DATE_RFC822);
-}
-
-function common_redirect($url, $code=307) {
- static $status = array(301 => "Moved Permanently",
- 302 => "Found",
- 303 => "See Other",
- 307 => "Temporary Redirect");
- header("Status: ${code} $status[$code]");
- header("Location: $url");
- common_element('a', array('href' => $url), $url);
-}
-
-function common_broadcast_notices($id) {
- // XXX: broadcast notices to remote subscribers
- // XXX: broadcast notices to SMS
- // XXX: broadcast notices to Jabber
- // XXX: broadcast notices to other IM
- // XXX: use a queue system like http://code.google.com/p/microapps/wiki/NQDQ
- return true;
-}