aboutsummaryrefslogtreecommitdiffstats
path: root/include/opengraph.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2019-11-25 08:41:34 +0000
committerMario <mario@mariovavti.com>2019-11-25 08:41:34 +0000
commit004861fbb726353ff804921332af7cf371db14e3 (patch)
tree593ad3d8059137b72e88f0929a84ea1acfe7fd59 /include/opengraph.php
parent8727f12b18788a7a1dc450130ceb0ea7524b649a (diff)
downloadvolse-hubzilla-004861fbb726353ff804921332af7cf371db14e3.tar.gz
volse-hubzilla-004861fbb726353ff804921332af7cf371db14e3.tar.bz2
volse-hubzilla-004861fbb726353ff804921332af7cf371db14e3.zip
merge opengraph fixes from dev
Diffstat (limited to 'include/opengraph.php')
-rw-r--r--include/opengraph.php123
1 files changed, 60 insertions, 63 deletions
diff --git a/include/opengraph.php b/include/opengraph.php
index 9de021d54..4c88570d3 100644
--- a/include/opengraph.php
+++ b/include/opengraph.php
@@ -3,73 +3,70 @@
* @file include/opengraph.php
* @brief Add Opengraph metadata and related functions.
*/
-
-
+
+
/**
* @brief Adds Opengraph meta tags into HTML head
*
* @param array $item
- * @param array $profile
+ * @param array $channel
*
*/
-
- function opengraph_add_meta($item, $profile) {
-
- if(! empty($item)) {
-
- if(! empty($item['title']))
- $ogtitle = $item['title'];
-
- // find first image if exist
- if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $item['body'], $matches)) {
- $ogimage = $matches[2];
- $ogimagetype = guess_image_type($ogimage);
- }
-
- // use summary as description if exist
- $ogdesc = (empty($item['summary']) ? $item['body'] : $item['summary'] );
-
- $ogdesc = str_replace("#^[", "[", $ogdesc);
-
- $ogdesc = bbcode($ogdesc, [ 'tryoembed' => false ]);
- $ogdesc = trim(html2plain($ogdesc, 0, true));
- $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8');
-
- // remove all URLs
- $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc);
-
- // shorten description
- $ogdesc = substr($ogdesc, 0, 300);
- $ogdesc = str_replace("\n", " ", $ogdesc);
- while (strpos($ogdesc, " ") !== false)
- $ogdesc = str_replace(" ", " ", $ogdesc);
- $ogdesc = (strlen($ogdesc) < 298 ? $ogdesc : rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "...");
-
- $ogtype = "article";
- }
-
- $channel = channelx_by_n($profile['profile_uid']);
-
- if(! isset($ogdesc)) {
- if($profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) {
- $ogdesc = $profile['about'];
- }
- else {
- $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']);
- }
- }
-
- if(! isset($ogimage)) {
- $ogimage = $channel['xchan_photo_l'];
- $ogimagetype = $channel['xchan_photo_mimetype'];
- }
-
- App::$page['htmlhead'] .= '<meta property="og:title" content="' . htmlspecialchars((isset($ogtitle) ? $ogtitle : $channel['channel_name'])) . '">' . "\r\n";
- App::$page['htmlhead'] .= '<meta property="og:image" content="' . $ogimage . '">' . "\r\n";
- App::$page['htmlhead'] .= '<meta property="og:image:type" content="' . $ogimagetype . '">' . "\r\n";
- App::$page['htmlhead'] .= '<meta property="og:description" content="' . htmlspecialchars($ogdesc) . '">' . "\r\n";
- App::$page['htmlhead'] .= '<meta property="og:type" content="' . (isset($ogtype) ? $ogtype : "profile") . '">' . "\r\n";
-
- return true;
+
+ function opengraph_add_meta($item, $channel) {
+
+ if(! empty($item)) {
+
+ if(! empty($item['title']))
+ $ogtitle = $item['title'];
+
+ // find first image if exist
+ if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $item['body'], $matches)) {
+ $ogimage = $matches[2];
+ $ogimagetype = guess_image_type($ogimage);
+ }
+
+ // use summary as description if exist
+ $ogdesc = (empty($item['summary']) ? $item['body'] : $item['summary'] );
+
+ $ogdesc = str_replace("#^[", "[", $ogdesc);
+
+ $ogdesc = bbcode($ogdesc, [ 'tryoembed' => false ]);
+ $ogdesc = trim(html2plain($ogdesc, 0, true));
+ $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8');
+
+ // remove all URLs
+ $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc);
+
+ // shorten description
+ $ogdesc = substr($ogdesc, 0, 300);
+ $ogdesc = str_replace("\n", " ", $ogdesc);
+ while (strpos($ogdesc, " ") !== false)
+ $ogdesc = str_replace(" ", " ", $ogdesc);
+ $ogdesc = (strlen($ogdesc) < 298 ? $ogdesc : rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "...");
+
+ $ogtype = "article";
+ }
+
+ if(! isset($ogdesc)) {
+ if(App::$profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) {
+ $ogdesc = App::$profile['about'];
+ }
+ else {
+ $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']);
+ }
+ }
+
+ if(! isset($ogimage)) {
+ $ogimage = $channel['xchan_photo_l'];
+ $ogimagetype = $channel['xchan_photo_mimetype'];
+ }
+
+ App::$page['htmlhead'] .= '<meta property="og:title" content="' . htmlspecialchars((isset($ogtitle) ? $ogtitle : $channel['channel_name'])) . '">' . "\r\n";
+ App::$page['htmlhead'] .= '<meta property="og:image" content="' . $ogimage . '">' . "\r\n";
+ App::$page['htmlhead'] .= '<meta property="og:image:type" content="' . $ogimagetype . '">' . "\r\n";
+ App::$page['htmlhead'] .= '<meta property="og:description" content="' . htmlspecialchars($ogdesc) . '">' . "\r\n";
+ App::$page['htmlhead'] .= '<meta property="og:type" content="' . (isset($ogtype) ? $ogtype : "profile") . '">' . "\r\n";
+
+ return true;
}
- \ No newline at end of file