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 public function onStartFindMentions($sender, $text, &$mentions)
15 preg_match_all('/(?:^|\s+)@([A-Za-z0-9_:\-\.\/%]+)\b/',
20 foreach ($atmatches[1] as $match) {
22 if(!common_valid_http_url($url)) { $url = 'http://' . $url; }
23 if(common_valid_http_url($url)) {
24 $mentioned = Mention_url_profile::fromUrl($url);
25 $text = mb_strlen($mentioned->nickname) <= mb_strlen($match[0]) ? $mentioned->nickname : $match[0];
28 if($mentioned instanceof Profile) {
29 $mentions[] = array('mentioned' => array($mentioned),
32 'position' => $match[1],
33 'length' => mb_strlen($match[0]),
34 'url' => $mentioned->profileurl);
41 public function onStartGetProfileFromURI($uri, &$profile)
43 $mention_profile = Mention_url_profile::getKV('profileurl', $uri);
44 if($mention_profile instanceof Mention_url_profile) {
45 $profile = $mention_profile->getProfile();
46 return !($profile instanceof Profile);
52 public function onCheckSchema()
54 $schema = Schema::get();
55 $schema->ensureTable('mention_url_profile', Mention_url_profile::schemaDef());
59 public function onPluginVersion(array &$versions)
61 $versions[] = array('name' => 'MentionURL',
62 'version' => GNUSOCIAL_VERSION,
63 'author' => 'Stephen Paul Weber',
64 'homepage' => 'http://gnu.io/',
66 // TRANS: Plugin description.
67 _m('Plugin to allow mentioning arbitrary URLs.'));