Make replies to @#
darcs-hash:20081124034952-84dde-e059f0800780de879ffa922e5ce379682a4f275a.gz
This commit is contained in:
parent
f80cd3273e
commit
f8fa9a942f
|
@ -83,4 +83,19 @@ class Profile_tag extends Memcached_DataObject
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Return profiles with a given tag
|
||||||
|
static function getTagged($tagger, $tag) {
|
||||||
|
$profile = new Profile();
|
||||||
|
$profile->query('SELECT profile.* ' .
|
||||||
|
'FROM profile JOIN profile_tag ' .
|
||||||
|
'ON profile.id = profile_tag.tagged ' .
|
||||||
|
'WHERE profile_tag.tagger = ' . $tagger . ' ' .
|
||||||
|
'AND profile_tag.tag = "' . $tag . '" ');
|
||||||
|
$tagged = array();
|
||||||
|
while ($profile->fetch()) {
|
||||||
|
$tagged[] = clone($profile);
|
||||||
|
}
|
||||||
|
return $tagged;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
38
lib/util.php
38
lib/util.php
|
@ -710,6 +710,7 @@ function common_render_content($text, $notice) {
|
||||||
$id = $notice->profile_id;
|
$id = $notice->profile_id;
|
||||||
$r = preg_replace('/(^|\s+)@([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r);
|
$r = preg_replace('/(^|\s+)@([A-Za-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);
|
$r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r);
|
||||||
|
$r = preg_replace('/(^|\s+)@#([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_hash_link($id, '\\2')", $r);
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,6 +861,22 @@ function common_at_link($sender_id, $nickname) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function common_at_hash_link($sender_id, $tag) {
|
||||||
|
$user = User::staticGet($sender_id);
|
||||||
|
if (!$user) {
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
$tagged = Profile_tag::getTagged($user->id, common_canonical_tag($tag));
|
||||||
|
if ($tagged) {
|
||||||
|
$url = common_local_url('subscriptions',
|
||||||
|
array('nickname' => $user->nickname,
|
||||||
|
'tag' => $tag));
|
||||||
|
return '<a href="'.htmlspecialchars($url).'" class="atlink">'.$tag.'</a>';
|
||||||
|
} else {
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function common_relative_profile($sender, $nickname, $dt=NULL) {
|
function common_relative_profile($sender, $nickname, $dt=NULL) {
|
||||||
# Try to find profiles this profile is subscribed to that have this nickname
|
# Try to find profiles this profile is subscribed to that have this nickname
|
||||||
$recipient = new Profile();
|
$recipient = new Profile();
|
||||||
|
@ -1274,6 +1291,8 @@ function common_save_replies($notice) {
|
||||||
$sender = Profile::staticGet($notice->profile_id);
|
$sender = Profile::staticGet($notice->profile_id);
|
||||||
# store replied only for first @ (what user/notice what the reply directed,
|
# store replied only for first @ (what user/notice what the reply directed,
|
||||||
# we assume first @ is it)
|
# we assume first @ is it)
|
||||||
|
$replied = array();
|
||||||
|
|
||||||
for ($i=0; $i<count($names); $i++) {
|
for ($i=0; $i<count($names); $i++) {
|
||||||
$nickname = $names[$i];
|
$nickname = $names[$i];
|
||||||
$recipient = common_relative_profile($sender, $nickname, $notice->created);
|
$recipient = common_relative_profile($sender, $nickname, $notice->created);
|
||||||
|
@ -1298,6 +1317,25 @@ function common_save_replies($notice) {
|
||||||
common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message);
|
common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message);
|
||||||
common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message));
|
common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message));
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
$replied[$recipient->id] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Hash format replies, too
|
||||||
|
$cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $notice->content, $match);
|
||||||
|
foreach ($match as $tag) {
|
||||||
|
$tagged = Profile_tag::getTagged($sender->id, $tag);
|
||||||
|
foreach ($tagged as $t) {
|
||||||
|
if (!$replied[$t->id]) {
|
||||||
|
$reply = new Reply();
|
||||||
|
$reply->notice_id = $notice->id;
|
||||||
|
$reply->profile_id = $t->id;
|
||||||
|
$id = $reply->insert();
|
||||||
|
if (!$id) {
|
||||||
|
common_log_db_error($reply, 'INSERT', __FILE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user