/** * Extracts urls and their according open graph infos from a given string * * @param String $string Text to extract urls and open graph infos from * @return OpenGraphURLCollection containing the extracted urls */ public static function extract($string) { $collection = new OpenGraphURLCollection(); if (Config::get()->OPENGRAPH_ENABLE) { $regexp = StudipFormat::getStudipMarkups()['links']['start']; $matched = preg_match_all('/' . $regexp . '/ms', $string, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $url = $match[2]; if (!$url) { continue; } if (!isLinkIntern($url)) { $og_url = OpenGraphURL::fromURL($url); if ($og_url && !$collection->find($og_url->id)) { $og_url->store(); $collection[] = $og_url; } } } } return $collection; }
public function handleElement(&$token) { if ($token->name === 'a' && isset($token->attr['href'])) { $token->attr['class'] = isLinkIntern($token->attr['href']) ? 'link-intern' : 'link-extern'; } }
/** * Stud.IP markup for hyperlinks (intern, extern). * Has lower priority than [code], [img], etc */ protected static function markupLinks($markup, $matches) { if ($markup->isInsideOf('htmlAnchor') || $markup->isInsideOf('htmlImg')) { return $matches[0]; } $url = $matches[2]; $title = $matches[1] ?: $url; $intern = isLinkIntern($url); $url = TransformInternalLinks($url); $linkmarkup = clone $markup; $linkmarkup->removeMarkup('links'); $linkmarkup->removeMarkup('wiki-links'); return sprintf('<a class="%s" href="%s"%s>%s</a>', $intern ? 'link-intern' : 'link-extern', $url, $intern ? '' : ' target="_blank"', $linkmarkup->format($title)); }