3 if (!defined('GNUSOCIAL')) { exit(1); }
5 require_once __DIR__ . '/lib/util.php';
8 * This plugin lets you type @twitter.com/singpolyma
9 * so that you can be specific instead of relying on heuristics.
11 class MentionURLPlugin extends Plugin
13 function onEndFindMentions(Profile $sender, $text, &$mentions)
17 preg_match_all('/(?:^|\s+)@([A-Za-z0-9_:\-\.\/%]+)\b/',
22 foreach ($atmatches[1] as $match) {
24 if(!common_valid_http_url($url)) { $url = 'http://' . $url; }
25 if(common_valid_http_url($url)) {
26 $mentioned = Mention_url_profile::fromUrl($url);
27 $text = mb_strlen($mentioned->nickname) <= mb_strlen($match[0]) ? $mentioned->nickname : $match[0];
30 if($mentioned instanceof Profile) {
31 $matches[$match[1]] = array('mentioned' => array($mentioned),
34 'position' => $match[1],
35 'length' => mb_strlen($match[0]),
36 'url' => $mentioned->profileurl);
40 foreach ($mentions as $i => $other) {
41 // If we share a common prefix with a local user, override it!
42 $pos = $other['position'];
43 if (isset($matches[$pos])) {
44 $mentions[$i] = $matches[$pos];
45 unset($matches[$pos]);
48 foreach ($matches as $mention) {
49 $mentions[] = $mention;
55 public function onStartGetProfileFromURI($uri, &$profile)
57 $mention_profile = Mention_url_profile::getKV('profileurl', $uri);
58 if($mention_profile instanceof Mention_url_profile) {
59 $profile = $mention_profile->getProfile();
60 return !($profile instanceof Profile);
66 public function onCheckSchema()
68 $schema = Schema::get();
69 $schema->ensureTable('mention_url_profile', Mention_url_profile::schemaDef());
73 public function onPluginVersion(array &$versions)
75 $versions[] = array('name' => 'MentionURL',
76 'version' => GNUSOCIAL_VERSION,
77 'author' => 'Stephen Paul Weber',
78 'homepage' => 'http://gnu.io/',
80 // TRANS: Plugin description.
81 _m('Plugin to allow mentioning arbitrary URLs.'));