X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=1a83f0fffa9a140d058ab2643115c8be442088e9;hb=c8162f7d978c56c29a504302419b5569c0aa37f3;hp=d518bd317f9af91531bb81a8fd224ed5b7f45b42;hpb=208b82a299cedae62f0ee649e35e03b24c53f0e3;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index d518bd317f..1a83f0fffa 100644 --- a/lib/util.php +++ b/lib/util.php @@ -93,16 +93,25 @@ function common_element_start($tag, $attrs=NULL) { } function common_element_end($tag) { + static $empty_tag = array('base', 'meta', 'link', 'hr', + 'br', 'param', 'img', 'area', + 'input', 'col'); global $xw; - # TODO: switch based on $tag - $xw->fullEndElement(); + # XXX: check namespace + if (in_array($tag, $empty_tag)) { + $xw->endElement(); + } else { + $xw->fullEndElement(); + } } function common_element($tag, $attrs=NULL, $content=NULL) { - common_element_start($tag, $attrs); - global $xw; - $xw->text($content); - common_element_end($tag); + common_element_start($tag, $attrs); + global $xw; + if ($content) { + $xw->text($content); + } + common_element_end($tag); } function common_start_xml($doc=NULL, $public=NULL, $system=NULL) { @@ -412,8 +421,12 @@ function common_check_user($nickname, $password) { if (is_null($user)) { return false; } else { - return (0 == strcmp(common_munge_password($password, $user->id), - $user->password)); + if (0 == strcmp(common_munge_password($password, $user->id), + $user->password)) { + return $user; + } else { + return false; + } } } @@ -432,19 +445,26 @@ function common_ensure_session() { } } -function common_set_user($nickname) { - if (is_null($nickname) && common_have_session()) { +# Three kinds of arguments: +# 1) a user object +# 2) a nickname +# 3) NULL to clear + +function common_set_user($user) { + if (is_null($user) && common_have_session()) { unset($_SESSION['userid']); return true; - } else { + } else if (is_string($user)) { + $nickname = $user; $user = User::staticGet('nickname', $nickname); - if ($user) { - common_ensure_session(); - $_SESSION['userid'] = $user->id; - return true; - } else { - return false; - } + } else if (!($user instanceof User)) { + return false; + } + + if ($user) { + common_ensure_session(); + $_SESSION['userid'] = $user->id; + return $user; } return false; } @@ -468,10 +488,13 @@ function common_set_cookie($key, $value, $expiration=0) { define('REMEMBERME', 'rememberme'); define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); -function common_rememberme() { - $user = common_current_user(); +function common_rememberme($user=NULL) { if (!$user) { - return false; + $user = common_current_user(); + if (!$user) { + common_debug('No current user to remember', __FILE__); + return false; + } } $rm = new Remember_me(); $rm->code = common_good_rand(16); @@ -479,8 +502,10 @@ function common_rememberme() { $result = $rm->insert(); if (!$result) { common_log_db_error($rm, 'INSERT', __FILE__); + common_debug('Error adding rememberme record for ' . $user->nickname, __FILE__); return false; } + common_log(LOG_INFO, 'adding rememberme cookie for ' . $user->nickname); common_set_cookie(REMEMBERME, implode(':', array($rm->user_id, $rm->code)), time() + REMEMBERME_EXPIRY); @@ -504,11 +529,12 @@ function common_remembered_user() { common_log_db_error($rm, 'DELETE', __FILE__); $user = NULL; } else { + common_log(LOG_INFO, 'logging in ' . $user->nickname . ' using rememberme code ' . $rm->code); common_set_user($user->nickname); common_real_login(false); # We issue a new cookie, so they can log in # automatically again after this session - common_rememberme(); + common_rememberme($user); } } } @@ -704,7 +730,11 @@ function common_fancy_url($action, $args=NULL) { case 'openidsettings': return common_path('settings/openid'); case 'newnotice': - return common_path('notice/new'); + if ($args && $args['replyto']) { + return common_path('notice/new?replyto='.$args['replyto']); + } else { + return common_path('notice/new'); + } case 'shownotice': return common_path('notice/'.$args['notice']); case 'xrds': @@ -721,6 +751,8 @@ function common_fancy_url($action, $args=NULL) { } case 'allrss': return common_path($args['nickname'].'/all/rss'); + case 'repliesrss': + return common_path($args['nickname'].'/replies/rss'); case 'userrss': return common_path($args['nickname'].'/rss'); case 'showstream': @@ -844,12 +876,16 @@ function common_save_replies($notice) { $reply = new Reply(); $reply->notice_id = $notice->id; $reply->profile_id = $recipient->id; - $reply->created = DB_DataObject_Cast::dateTime(); - $recipient_notice = $reply_for->getCurrentNotice($notice->created); - $reply->replied_id = $recipient_notice->id; + if ($reply_for) { +# $recipient_notice = $reply_for->getCurrentNotice($notice->created); + $recipient_notice = $reply_for->getCurrentNotice(); + $reply->replied_id = $recipient_notice->id; + } $id = $reply->insert(); if (!$id) { - common_log_db_error($reply, 'INSERT', __FILE__); + $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); return; } } @@ -867,17 +903,16 @@ function common_broadcast_notice($notice, $remote=false) { # Stick the notice on the queue function common_enqueue_notice($notice) { - common_log(LOG_INFO, 'start queueing notice ID = ' . $notice->id); $qi = new Queue_item(); $qi->notice_id = $notice->id; - $qi->created = DB_DataObject_Cast::dateTime(); - $result = $qi->insert(); - if ($result === FALSE) { + $qi->created = $notice->created; + $result = $qi->insert(); + if (!$result) { $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); common_log(LOG_ERROR, 'DB error inserting queue item: ' . $last_error->message); return false; } - common_log(LOG_INFO, 'complete queueing notice ID = ' . $notice->id); + common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id); return $result; } @@ -1035,7 +1070,7 @@ function common_debug($msg, $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_ERROR, $last_error->message . '(' . $verb . ' on ' . $objstr . ')', $filename); + common_log(LOG_ERR, $last_error->message . '(' . $verb . ' on ' . $objstr . ')', $filename); } function common_log_objstring(&$object) {