From a341c889b751055e90eba9b7a14da5b7cd0e8032 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 31 Jan 2016 15:55:27 -0800 Subject: add oembed provider for photos --- boot.php | 2 +- include/oembed.php | 7 ++-- include/security.php | 2 +- index.php | 11 ++++--- mod/oep.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mod/photos.php | 2 ++ version.inc | 2 +- 7 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 mod/oep.php diff --git a/boot.php b/boot.php index 4b49cacb5..8b5e75326 100755 --- a/boot.php +++ b/boot.php @@ -48,7 +48,7 @@ require_once('include/AccessList.php'); define ( 'PLATFORM_NAME', 'hubzilla' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc'))); -define ( 'STD_VERSION', '1.1.3' ); +define ( 'STD_VERSION', '1.1.4' ); define ( 'ZOT_REVISION', 1 ); define ( 'DB_UPDATE_VERSION', 1161 ); diff --git a/include/oembed.php b/include/oembed.php index e50d34c7d..b95f93f91 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -78,7 +78,6 @@ function oembed_fetch_url($embedurl){ else { // try oembed autodiscovery $redirects = 0; - $result = z_fetch_url($embedurl, false, $redirects, array('timeout' => 15, 'accept_content' => "text/*", 'novalidate' => true )); if($result['success']) $html_text = $result['body']; @@ -88,8 +87,8 @@ function oembed_fetch_url($embedurl){ if ($dom){ $xpath = new DOMXPath($dom); $attr = "oembed"; - $xattr = oe_build_xpath("class","oembed"); + $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach($entries as $e){ $href = $e->getAttributeNode("href")->nodeValue; @@ -173,6 +172,10 @@ function oembed_format_object($j){ $ret.="
"; }; break; case "link": { + if($j->thumbnail_url) { + $ret = 'thumbnail

'; + } + //$ret = "".$j->title.""; }; break; case "rich": { diff --git a/include/security.php b/include/security.php index 2a9a6e39e..ee94dba82 100644 --- a/include/security.php +++ b/include/security.php @@ -181,7 +181,7 @@ function permissions_sql($owner_id, $remote_observer = null) { */ else { - $observer = (($remote_observer) ? $remote_observer : get_observer_hash()); + $observer = ((! is_null($remote_observer)) ? $remote_observer : get_observer_hash()); if($observer) { $groups = init_groups_visitor($observer); diff --git a/index.php b/index.php index 7e9cde9bb..2d8116f96 100755 --- a/index.php +++ b/index.php @@ -289,9 +289,12 @@ if($a->module_loaded) { */ if(function_exists($a->module . '_init')) { - call_hooks($a->module . '_mod_init', $placeholder); - $func = $a->module . '_init'; - $func($a); + $arr = array('init' => true, 'replace' => false); + call_hooks($a->module . '_mod_init', $arr); + if(! $arr['replace']) { + $func = $a->module . '_init'; + $func($a); + } } /** @@ -333,7 +336,7 @@ if($a->module_loaded) { if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) && (function_exists($a->module . '_post')) - && (! x($_POST, 'auth-params'))) { + && (! x($_POST, 'auth-params'))) { call_hooks($a->module . '_mod_post', $_POST); $func = $a->module . '_post'; $func($a); diff --git a/mod/oep.php b/mod/oep.php new file mode 100644 index 000000000..d0f4bd193 --- /dev/null +++ b/mod/oep.php @@ -0,0 +1,93 @@ + $maxheight) + continue; + if($maxwidth && $rr['width'] > $maxwidth) + continue; + $foundres = true; + break; + } + + if($foundres) { + $ret['type'] = 'link'; + $ret['thumbnail_url'] = z_root() . '/photo/' . '/' . $rr['resource_id'] . '-' . $rr['scale']; + $ret['thumbnail_width'] = $rr['width']; + $ret['thumbnail_height'] = $rr['height']; + } + + + } + return $ret; + +} \ No newline at end of file diff --git a/mod/photos.php b/mod/photos.php index f1b7aceed..d187e1d45 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -804,6 +804,8 @@ function photos_content(&$a) { if($datatype === 'image') { + $a->page['htmlhead'] .= "\r\n" . '' . "\r\n"; + // fetch image, item containing image, then comments $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' diff --git a/version.inc b/version.inc index 1c457edcc..0ee245598 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2016-01-29.1293H +2016-01-31.1295H -- cgit v1.2.3