Commit a3dd3c4071e3d169f29757e803cddf11e14778a4

  • avatar
  • blaise.ca <balleyne @d…b.privatedns.com>
  • Sun Nov 01 06:55:03 CET 2009
feature: Linked URLs, usernames, hash tags and groups in microblog updates

feature: added smarter matching for microblog/status updates, checking for lack of hash (which ping.fm strips for Facebook) or periods appended to the end (does a check ignoring the last character)
  
1212 $this->$key = htmlspecialchars($value, ENT_NOQUOTES, 'utf-8', FALSE);
1313 }
1414 }
15
15
16 /**
17 * Turn URLs into links.
18 */
19 function linkify($text){
20 return preg_replace('/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?)/i', '<a href="$1">$1</a>', $text);
21 }
22
1623 function timeSince(){
1724 $timeSince = time() - ($this->rec_updated);
1825
102102}
103103
104104class MicroBlog extends Entry{
105 #TODO: add link to post
106 #TODO: create hyperlinks within post
105
106 #TODO: add link to post ?
107107 function getSingleTitle(){
108 return $this->getNeutralTitle();
108 $title = $this->getNeutralTitle();
109
110 // Replace URLs with links
111 $title = $this->linkify($title);
112
113 // Default to Twitter if multiple...
114 $domain = count($this->icons) > 1 ? Twitter::$static_domain : $this->domain;
115 $search_path = count($this->icons) > 1 ? Twitter::$static_search_path : $this->search_path;
116
117 // Link usernames
118 $title = preg_replace('/( |\.|^)@([\w_-]+)/i', '$1@<a href="http://'.$domain.'/$2">$2</a>', $title);
119
120 // Link hash tags
121 $title = preg_replace('/( |^)#([\w_-]+)/i', '$1#<a href="http://'.$search_path.'?q=%23$2">$2</a>', $title);
122
123 return $title;
109124 }
110125
111126 function getSingleDescription(){
128128 }
129129
130130 function equals($other){
131 return $other->getNeutralTitle() == $this->getNeutralTitle();
131 $x = trim($this->getNeutralTitle());
132 $y = trim($other->getNeutralTitle());
133
134 $basic_match = $x == $y;
135 $ignore_last_char = ($x == substr_replace($y, '', -1) || $y == substr_replace($x, '', -1));
136 $without_hash_tags = ($x == str_replace('#', '', $y) || $y == str_replace('#', '', $x)); // ping.fm sometimes strips them
137
138 return $basic_match || $ignore_last_char || $without_hash_tags;
132139 }
133140
134141 /**
143143 */
144144 function getNeutralTitle(){
145145 #TODO: un-hardcode
146 // Strip out username from update
146147 $usernames['twitter'] = 'balleyne: ';
147148 $usernames['facebook'] = 'Blaise ';
148149 $ustring = '';
341341#TODO: make this more interesting
342342class StatusUpdates extends MicroBlog{
343343 function getSingleTitle(){
344 return $this->title;
344 return $this->linkify($this->title);
345345 }
346346}
347347
459459
460460class Identica extends MicroBlog{
461461 var $img = 'http://identi.ca/favicon.ico';
462 var $domain = 'identi.ca';
463 var $search_path = 'identi.ca/search/notice';
464 public static $static_domain = 'identi.ca';
465 public static $static_search_path = 'identi.ca/search/notice';
466
467 function getSingleTitle(){
468 $title = parent::getSingleTitle();
469
470 // Link groups
471 $title = preg_replace('/( |^)!([\w_-]+)/i', '$1!<a href="http://'.$this->domain.'/group/$2">$2</a>', $title);
472
473 return $title;
474 }
462475}
463476
464477class IdenticaFavorites extends Favorites{
465478 var $img = 'http://identi.ca/favicon.ico';
466
479
467480 function getSingleDescription(){
468481 return '';
469482 }
499499
500500class Twitter extends MicroBlog{
501501 var $img = 'http://www.twitter.com/favicon.ico';
502 var $domain = 'twitter.com';
503 var $search_path = 'search.twitter.com/search';
504 public static $static_domain = 'twitter.com';
505 public static $static_search_path = 'search.twitter.com/search';
502506}
503507
504508class TwitterFavorites extends Favorites{