aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/OpenGraph.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:07:19 +0200
committerJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:19:12 +0200
commita3da1483a9e689846179159355badfec8073dbec (patch)
tree770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /lib/classes/OpenGraph.php
current code from svn, revision 62608
Diffstat (limited to 'lib/classes/OpenGraph.php')
-rw-r--r--lib/classes/OpenGraph.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/classes/OpenGraph.php b/lib/classes/OpenGraph.php
new file mode 100644
index 0000000..75326aa
--- /dev/null
+++ b/lib/classes/OpenGraph.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Open Graph class that extracts open graph urls from a given string.
+ *
+ * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
+ * @license GPL2 or any later version
+ * @since Stud.IP 3.4
+ */
+class OpenGraph
+{
+ /**
+ * 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 = StudipCoreFormat::getStudipMarkup('links')['start'];
+ $matched = preg_match_all('/' . $regexp . '/ums', $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;
+ }
+}