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 const PLUGIN_VERSION = '2.0.0';
15 function onEndFindMentions(Profile $sender, $text, &$mentions)
19 preg_match_all('/(?:^|\s+)@([A-Za-z0-9_:\-\.\/%]+)\b/',
24 foreach ($atmatches[1] as $match) {
26 if(!common_valid_http_url($url)) { $url = 'http://' . $url; }
27 if(common_valid_http_url($url)) {
28 $mentioned = Mention_url_profile::fromUrl($url);
29 $text = mb_strlen($mentioned->nickname) <= mb_strlen($match[0]) ? $mentioned->nickname : $match[0];
32 if($mentioned instanceof Profile) {
33 $matches[$match[1]] = array('mentioned' => array($mentioned),
36 'position' => $match[1],
37 'length' => mb_strlen($match[0]),
38 'url' => $mentioned->profileurl);
42 foreach ($mentions as $i => $other) {
43 // If we share a common prefix with a local user, override it!
44 $pos = $other['position'];
45 if (isset($matches[$pos])) {
46 $mentions[$i] = $matches[$pos];
47 unset($matches[$pos]);
50 foreach ($matches as $mention) {
51 $mentions[] = $mention;
57 public function onStartGetProfileFromURI($uri, &$profile)
59 $mention_profile = Mention_url_profile::getKV('profileurl', $uri);
60 if($mention_profile instanceof Mention_url_profile) {
61 $profile = $mention_profile->getProfile();
62 return !($profile instanceof Profile);
68 public function onCheckSchema()
70 $schema = Schema::get();
71 $schema->ensureTable('mention_url_profile', Mention_url_profile::schemaDef());
75 public function onPluginVersion(array &$versions)
77 $versions[] = array('name' => 'MentionURL',
78 'version' => self::PLUGIN_VERSION,
79 'author' => 'Stephen Paul Weber',
80 'homepage' => 'http://gnu.io/',
82 // TRANS: Plugin description.
83 _m('Plugin to allow mentioning arbitrary URLs.'));