Skip to content

Commit

Permalink
in_array could not compare strings with mixed upper and lower case. N…
Browse files Browse the repository at this point in the history
…ow all the array indices are converted to lowercase first before comparison is done.
  • Loading branch information
rmdstudio committed Oct 25, 2014
1 parent 5a2862b commit 1a287bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ public function updateHashtagsFromBody(KCommandContext $context)
{
$entity = $this->getItem();
$terms = $this->extractHashtagTerms($entity->body);

foreach($entity->hashtags as $hashtag)
if(!in_array($hashtag->name, $terms))
$entity->removeHashtag($hashtag->name);

if(is_array($terms))
{
$terms_search = array_map('strtolower', $terms);

foreach($entity->hashtags as $hashtag)
if(!in_array($hashtag->name, $terms_search))
$entity->removeHashtag($hashtag->name);
}

foreach($terms as $term)
$entity->addHashtag(trim($term));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,34 @@ public function addMentionsFromBody()
*/
public function updateMentionsFromBody(KCommandContext $context)
{
$entity = $this->getItem();
$usernames = $this->extractMentions($entity->body);
$existing_mentions = $entity->mentions;

foreach($existing_mentions as $mention)
if(!in_array($mention->username, $usernames))
$entity->removeMention($mention->username);

$existing_mentions = KConfig::unbox($existing_mentions->username);

foreach($usernames as $index=>$username)
if(in_array($username, $existing_mentions))
unset($usernames[$index]);
$entity = $this->getItem();

$body_mentions = $this->extractMentions($entity->body);
$body_mentions = array_map('strtolower', $body_mentions);

$entity_mentions = KConfig::unbox($entity->mentions->username);

if(is_array($entity_mentions))
$entity_mentions = array_map('strtolower', $entity_mentions);

//update removed mentions
if(is_array($body_mentions))
foreach($entity_mentions as $mention)
if(!in_array($mention, $body_mentions))
$entity->removeMention($mention);

foreach($usernames as $username)
$entity->addMention(trim($username));
//remove the body mentions that already exists in the entity mentions
if(is_array($entity_mentions))
foreach($body_mentions as $index=>$mention)
if(in_array($mention, $entity_mentions))
unset($body_mentions[$index]);

//what's left are new mentions. Add them to the entity.
foreach($body_mentions as $mention)
$entity->addMention(trim($mention));

$this->_newly_mentioned = $usernames;
//keep the list of new mentions so you can notify them later.
$this->_newly_mentioned = $body_mentions;
}

/**
Expand Down

0 comments on commit 1a287bb

Please sign in to comment.