aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-01-31 15:55:27 -0800
committerredmatrix <git@macgirvin.com>2016-01-31 15:55:27 -0800
commita341c889b751055e90eba9b7a14da5b7cd0e8032 (patch)
treec42867ffbcac204c664522cb1559b7169c797cc1
parent1f87fef9684a29da91fcb41a5d1d3bd4fb9a4619 (diff)
downloadvolse-hubzilla-a341c889b751055e90eba9b7a14da5b7cd0e8032.tar.gz
volse-hubzilla-a341c889b751055e90eba9b7a14da5b7cd0e8032.tar.bz2
volse-hubzilla-a341c889b751055e90eba9b7a14da5b7cd0e8032.zip
add oembed provider for photos
-rwxr-xr-xboot.php2
-rwxr-xr-xinclude/oembed.php7
-rw-r--r--include/security.php2
-rwxr-xr-xindex.php11
-rw-r--r--mod/oep.php93
-rw-r--r--mod/photos.php2
-rw-r--r--version.inc2
7 files changed, 110 insertions, 9 deletions
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.="<br>";
}; break;
case "link": {
+ if($j->thumbnail_url) {
+ $ret = '<a href="' . $embedurl . '" ><img src="' . $j->thumbnail_url . '" alt="thumbnail" /></a><br /><br />';
+ }
+
//$ret = "<a href='".$embedurl."'>".$j->title."</a>";
}; 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 @@
+<?php
+
+// oembed provider
+
+
+
+function oep_init(&$a) {
+
+
+
+ $url = $_REQUEST['url'];
+ if(! $url)
+ http_status_exit(404, 'Not found');
+
+ $maxwidth = $_REQUEST['maxwidth'];
+ $maxheight = $_REQUEST['maxheight'];
+ $format = $_REQUEST['format'];
+ if($format && $format !== 'json')
+ http_status_exit(501, 'Not implemented');
+
+ if(fnmatch('*/photos/*/album/*',$url))
+ $arr = oep_album_reply($_REQUEST);
+ elseif(fnmatch('*/photos/*',$url))
+ $arr = oep_photo_reply($_REQUEST);
+
+
+ if($arr) {
+ header('Content-Type: application/json+oembed');
+ echo json_encode($arr);
+ killme();
+ }
+
+ http_status_exit(404,'Not found');
+
+}
+
+
+function oep_album_reply() {
+
+}
+
+function oep_photo_reply($args) {
+
+ $ret = array();
+ $url = $args['url'];
+ $maxwidth = intval($args['maxwidth']);
+ $maxheight = intval($args['maxheight']);
+
+ if(preg_match('|//(.*?)/(.*?)/(.*?)/image/|',$url,$matches)) {
+ $chn = $matches[3];
+ $res = basename($url);
+ }
+
+ if(! ($chn && $res))
+ return;
+ $c = q("select * from channel where channel_address = '%s' limit 1",
+ dbesc($chn)
+ );
+
+ if(! $c)
+ return;
+
+ $sql_extra = permissions_sql($c[0]['channel_id']);
+
+
+ $r = q("select height, width, scale, resource_id from photo where uid = %d and resource_id = '%s' $sql_extra order by scale asc",
+ intval($c[0]['channel_id']),
+ dbesc($res)
+ );
+
+ if($r) {
+ foreach($r as $rr) {
+ $foundres = false;
+ if($maxheight && $rr['height'] > $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" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . $a->cmd) . '" title="oembed" />' . "\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