Skip to content

Commit

Permalink
兼容 php 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
forecho committed Jul 21, 2016
1 parent 4ef961b commit a104d98
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions common/services/PostService.php
Expand Up @@ -84,21 +84,21 @@ public static function contentReplaceFloor($content)
*/
public static function contentReplaceAtUser($content, $model)
{
$model->atUsers = $usernames = static::parseUsernames($content);
$model->atUsers = $usernames = static::parseUsername($content);
foreach ($usernames as $username) {
$content = str_replace("@$username", sprintf('[@%s](%s)', $username, Url::to(['/user/default/show', 'username' => $username])), $content);
}

return $content;
}

public static function parseUsernames($content)
public static function parseUsername($content)
{
preg_match_all('/@(\S{4,255}) /', $content, $matches);
if (empty($users = $matches[1])) {
if (empty($matches[1])) {
return [];
}
$existUserRows = User::find()->where(['username' => $users])->select('id,username')->asArray()->all();
$existUserRows = User::find()->where(['username' => $matches[1]])->select('id,username')->asArray()->all();
return ArrayHelper::map($existUserRows, 'id', 'username') ?: [];
}

Expand Down

0 comments on commit a104d98

Please sign in to comment.