remove some code duplication

This commit is contained in:
friendica 2014-07-14 01:38:16 -07:00
parent 17bd39fcd4
commit 233e4e1363
6 changed files with 26 additions and 59 deletions

View File

@ -3,7 +3,7 @@
require_once("include/oembed.php"); require_once("include/oembed.php");
require_once('include/event.php'); require_once('include/event.php');
require_once('include/zot.php'); require_once('include/zot.php');
require_once('include/hubloc.php');
function tryoembed($match) { function tryoembed($match) {
$url = ((count($match)==2)?$match[1]:$match[2]); $url = ((count($match)==2)?$match[1]:$match[2]);
@ -19,15 +19,7 @@ function tryoembed($match) {
function tryzrlaudio($match) { function tryzrlaudio($match) {
$link = $match[1]; $link = $match[1];
$m = @parse_url($link); $zrl = is_matrix_url($link);
$zrl = false;
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
if($zrl) if($zrl)
$link = zid($link); $link = zid($link);
return '<audio src="' . $link . '" controls="controls" ><a href="' . $link . '">' . $link . '</a></audio>'; return '<audio src="' . $link . '" controls="controls" ><a href="' . $link . '">' . $link . '</a></audio>';
@ -35,15 +27,7 @@ function tryzrlaudio($match) {
function tryzrlvideo($match) { function tryzrlvideo($match) {
$link = $match[1]; $link = $match[1];
$m = @parse_url($link); $zrl = is_matrix_url($link);
$zrl = false;
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
if($zrl) if($zrl)
$link = zid($link); $link = zid($link);
return '<video controls="controls" src="' . $link . '" style="width:100%; max-width:' . get_app()->videowidth . 'px"><a href="' . $link . '">' . $link . '</a></video>'; return '<video controls="controls" src="' . $link . '" style="width:100%; max-width:' . get_app()->videowidth . 'px"><a href="' . $link . '">' . $link . '</a></video>';

View File

@ -23,15 +23,8 @@ function bookmark_add($channel,$sender,$taxonomy,$private,$opts = null) {
$iarr['mitem_desc'] = $taxonomy['term']; $iarr['mitem_desc'] = $taxonomy['term'];
$iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0); $iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0);
$m = @parse_url($taxonomy['url']); require_once('include/hubloc.php');
$zrl = false; $zrl = is_matrix_url($taxonomy['url']);
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
if($zrl) if($zrl)
$iarr['mitem_flags'] |= MENU_ITEM_ZID; $iarr['mitem_flags'] |= MENU_ITEM_ZID;

View File

@ -1,5 +1,17 @@
<?php /** @file */ <?php /** @file */
function is_matrix_url($url) {
$m = @parse_url($url);
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
return true;
}
return false;
}
function prune_hub_reinstalls() { function prune_hub_reinstalls() {

View File

@ -189,15 +189,8 @@ function add_source_route($iid,$hash) {
function red_zrl_callback($matches) { function red_zrl_callback($matches) {
$m = @parse_url($matches[2]); require_once('include/hubloc.php');
$zrl = false; $zrl = is_matrix_url($matches[2]);
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
$t = strip_zids($matches[2]); $t = strip_zids($matches[2]);
if($t !== $matches[2]) { if($t !== $matches[2]) {
@ -236,15 +229,8 @@ function red_unescape_codeblock($m) {
function red_zrlify_img_callback($matches) { function red_zrlify_img_callback($matches) {
$m = @parse_url($matches[2]); require_once('include/hubloc.php');
$zrl = false; $zrl = is_matrix_url($matches[2]);
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
$t = strip_zids($matches[2]); $t = strip_zids($matches[2]);
if($t !== $matches[2]) { if($t !== $matches[2]) {

View File

@ -29,18 +29,10 @@ function oembed_fetch_url($embedurl){
$txt = ""; $txt = "";
if (in_array($ext, $noexts)) { if (in_array($ext, $noexts)) {
$m = @parse_url($embedurl); require_once('include/hubloc.php');
$zrl = false; $zrl = is_matrix_url($embedurl);
if($m['host']) { if($zrl)
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1", $embedurl = zid($embedurl);
dbesc($m['host'])
);
if($r)
$zrl = true;
}
if($zrl) {
$embedurl = zid($embedurl);
}
} }
else { else {
// try oembed autodiscovery // try oembed autodiscovery

View File

@ -1 +1 @@
2014-07-13.735 2014-07-14.736