コード例 #1
0
 function testLinkify()
 {
     $value = '@username';
     $result = '<a href="http://twitter.com/username">@username</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $this->assertEqual($this->Twitter->linkify($value, array('username' => false)), $value);
     $value = '#hashtag';
     $result = '<a href="http://search.twitter.com/search?q=%23hashtag">#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $this->assertEqual($this->Twitter->linkify($value, array('hashtag' => false)), $value);
     $value = 'http://example.com';
     $result = '<a href="http://example.com">http://example.com</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $this->assertEqual($this->Twitter->linkify($value, array('url' => false)), $value);
     $value = '@username #hashtag';
     $result = '<a href="http://twitter.com/username">@username</a> <a href="http://search.twitter.com/search?q=%23hashtag">#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '@username#hashtag';
     $result = '<a href="http://twitter.com/username">@username</a><a href="http://search.twitter.com/search?q=%23hashtag">#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '@username http://example.com';
     $result = '<a href="http://twitter.com/username">@username</a> <a href="http://example.com">http://example.com</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = 'http://example.com #hashtag';
     $result = '<a href="http://example.com">http://example.com</a> <a href="http://search.twitter.com/search?q=%23hashtag">#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = 'http://example.com/#hashtag';
     $result = '<a href="http://example.com/#hashtag">http://example.com/#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '@user_name';
     $result = '<a href="http://twitter.com/user_name">@user_name</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '#hash_tag';
     $result = '<a href="http://search.twitter.com/search?q=%23hash_tag">#hash_tag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '@user%name';
     $result = '<a href="http://twitter.com/user">@user</a>%name';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = 'http://example.com:8080/path?query=search&order=asc#hashtag';
     $result = '<a href="http://example.com:8080/path?query=search&order=asc#hashtag">http://example.com:8080/path?query=search&order=asc#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = 'http://subdomain.example.com:8080/?query=search&order=asc#hashtag';
     $result = '<a href="http://subdomain.example.com:8080/?query=search&order=asc#hashtag">http://subdomain.example.com:8080/?query=search&order=asc#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = 'http://subdomain.example.com:8080/?#hashtag';
     $result = '<a href="http://subdomain.example.com:8080/?#hashtag">http://subdomain.example.com:8080/?#hashtag</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '@username @nameuser';
     $result = '<a href="http://twitter.com/username">@username</a> <a href="http://twitter.com/nameuser">@nameuser</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
     $value = '#hashtag #taghash';
     $result = '<a href="http://search.twitter.com/search?q=%23hashtag">#hashtag</a> <a href="http://search.twitter.com/search?q=%23taghash">#taghash</a>';
     $this->assertEqual($this->Twitter->linkify($value), $result);
 }
コード例 #2
0
ファイル: twitter_form.php プロジェクト: elstc/twitter_kit
 /**
  * linkify text
  *
  * @param string $value
  * @param array  $options
  *    username: linkify username. eg. @username
  *    hashtag : linkify hashtag. eg. #hashtag
  *    url     : linkify url. eg. http://example.com/
  * @return string
  */
 public function linkify($value, $options = array())
 {
     return $this->Twitter->linkify($value, $options);
 }