aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/bbcode.php65
-rw-r--r--include/conversation.php10
-rw-r--r--include/feedutils.php48
-rw-r--r--include/markdown.php67
-rwxr-xr-xinclude/oembed.php2
-rw-r--r--include/photo/photo_driver.php13
-rw-r--r--include/photos.php14
-rw-r--r--include/socgraph.php71
-rw-r--r--include/taxonomy.php30
-rw-r--r--include/text.php47
10 files changed, 170 insertions, 197 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 135368db9..0d2fb8c74 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -9,6 +9,66 @@ require_once('include/event.php');
require_once('include/zot.php');
+function get_bb_tag_pos($s, $name, $occurance = 1) {
+
+ if($occurance < 1)
+ $occurance = 1;
+
+ $start_open = -1;
+ for($i = 1; $i <= $occurance; $i++) {
+ if( $start_open !== false)
+ $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags
+ }
+
+ if( $start_open === false)
+ return false;
+
+ $start_equal = strpos($s, '=', $start_open);
+ $start_close = strpos($s, ']', $start_open);
+
+ if( $start_close === false)
+ return false;
+
+ $start_close++;
+
+ $end_open = strpos($s, '[/' . $name . ']', $start_close);
+
+ if( $end_open === false)
+ return false;
+
+ $res = array( 'start' => array('open' => $start_open, 'close' => $start_close),
+ 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) );
+ if( $start_equal !== false)
+ $res['start']['equal'] = $start_equal + 1;
+
+ return $res;
+}
+
+function bb_tag_preg_replace($pattern, $replace, $name, $s) {
+
+ $string = $s;
+
+ $occurance = 1;
+ $pos = get_bb_tag_pos($string, $name, $occurance);
+ while($pos !== false && $occurance < 1000) {
+
+ $start = substr($string, 0, $pos['start']['open']);
+ $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
+ $end = substr($string, $pos['end']['close']);
+ if($end === false)
+ $end = '';
+
+ $subject = preg_replace($pattern, $replace, $subject);
+ $string = $start . $subject . $end;
+
+ $occurance++;
+ $pos = get_bb_tag_pos($string, $name, $occurance);
+ }
+
+ return $string;
+}
+
+
function tryoembed($match) {
$url = ((count($match) == 2) ? $match[1] : $match[2]);
@@ -555,10 +615,7 @@ function bb_code_options($match) {
}
function bb_highlight($match) {
- $lang = ((in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby',
- 'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','json','sh']))
- ? strtolower($match[1]) : 'php' );
- return text_highlight($match[2],$lang);
+ return text_highlight($match[2],strtolower($match[1]));
}
function bb_fixtable_lf($match) {
diff --git a/include/conversation.php b/include/conversation.php
index 0f940b1a3..c325a516f 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -917,9 +917,9 @@ function thread_action_menu($item,$mode = '') {
}
-function author_is_pmable($xchan) {
+function author_is_pmable($xchan, $abook) {
- $x = [ 'xchan' => $xchan, 'result' => 'unset' ];
+ $x = [ 'xchan' => $xchan, 'abook' => $abook, 'result' => 'unset' ];
call_hooks('author_is_pmable',$x);
if($x['result'] !== 'unset')
return $x['result'];
@@ -949,7 +949,7 @@ function thread_author_menu($item, $mode = '') {
}
$profile_link = chanlink_hash($item['author_xchan']);
-
+ $contact = false;
if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts))
$contact = App::$contacts[$item['author_xchan']];
@@ -958,9 +958,9 @@ function thread_author_menu($item, $mode = '') {
$follow_url = z_root() . '/follow/?f=&url=' . urlencode($item['author']['xchan_addr']);
- if($item['uid'] > 0 && author_is_pmable($item['author']))
+ if($item['uid'] > 0 && author_is_pmable($item['author'],$contact)) {
$pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']);
-
+ }
if($contact) {
diff --git a/include/feedutils.php b/include/feedutils.php
index 6c411723a..708532013 100644
--- a/include/feedutils.php
+++ b/include/feedutils.php
@@ -136,7 +136,7 @@ function get_feed_for($channel, $observer_hash, $params) {
continue;
/** @BUG $owner is undefined in this call */
- $atom .= atom_entry($item, $type, null, $owner, true);
+ $atom .= atom_entry($item, $type, null, $owner, true, '', $params['compat']);
}
}
@@ -397,6 +397,9 @@ function get_atom_elements($feed, $item, &$author) {
}
$ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false);
+ $mastodon = (($item->get_item_tags('http://mastodon.social/schema/1.0','scope')) ? true : false);
+ if($mastodon)
+ $ostatus_protocol = true;
$apps = $item->get_item_tags(NAMESPACE_STATUSNET, 'notice_info');
if($apps && $apps[0]['attribs']['']['source']) {
@@ -1306,6 +1309,28 @@ function atom_render_author($tag,$xchan) {
}
+function compat_photos_list($s) {
+
+ $ret = [];
+
+ $found = preg_match_all('/\[[zi]mg(.*?)\](.*?)\[/ism',$s,$matches,PREG_SET_ORDER);
+
+ if($found) {
+ foreach($matches as $match) {
+ $ret[] = [
+ 'href' => $match[2],
+ 'length' => 0,
+ 'type' => guess_image_type($match[2])
+ ];
+
+ }
+ }
+
+ return $ret;
+}
+
+
+
/**
* @brief Create an item for the Atom feed.
*
@@ -1319,7 +1344,8 @@ function atom_render_author($tag,$xchan) {
* @param number $cid default 0
* @return void|string
*/
-function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) {
+function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $compat = false) {
+
if(! $item['parent'])
return;
@@ -1334,6 +1360,13 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) {
else
$body = $item['body'];
+ if($compat) {
+ $compat_photos = compat_photos_list($body);
+ }
+ else {
+ $compat_photos = null;
+ }
+
$o = "\r\n\r\n<entry>\r\n";
if(is_array($author)) {
@@ -1403,10 +1436,19 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) {
. (($enc['href']) ? 'href="' . $enc['href'] . '" ' : '')
. (($enc['length']) ? 'length="' . $enc['length'] . '" ' : '')
. (($enc['type']) ? 'type="' . $enc['type'] . '" ' : '')
- . ' />';
+ . ' />' . "\r\n";
}
}
}
+ if($compat_photos) {
+ foreach($compat_photos as $enc) {
+ $o .= '<link rel="enclosure" '
+ . (($enc['href']) ? 'href="' . $enc['href'] . '" ' : '')
+ . ((array_key_exists('length',$enc)) ? 'length="' . $enc['length'] . '" ' : '')
+ . (($enc['type']) ? 'type="' . $enc['type'] . '" ' : '')
+ . ' />' . "\r\n";
+ }
+ }
if($item['term']) {
foreach($item['term'] as $term) {
diff --git a/include/markdown.php b/include/markdown.php
index f7e9d53fc..3ade03971 100644
--- a/include/markdown.php
+++ b/include/markdown.php
@@ -13,73 +13,6 @@ require_once("include/html2bbcode.php");
require_once("include/bbcode.php");
-function get_bb_tag_pos($s, $name, $occurance = 1) {
-
- if($occurance < 1)
- $occurance = 1;
-
- $start_open = -1;
- for($i = 1; $i <= $occurance; $i++) {
- if( $start_open !== false)
- $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags
- }
-
- if( $start_open === false)
- return false;
-
- $start_equal = strpos($s, '=', $start_open);
- $start_close = strpos($s, ']', $start_open);
-
- if( $start_close === false)
- return false;
-
- $start_close++;
-
- $end_open = strpos($s, '[/' . $name . ']', $start_close);
-
- if( $end_open === false)
- return false;
-
- $res = array( 'start' => array('open' => $start_open, 'close' => $start_close),
- 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) );
- if( $start_equal !== false)
- $res['start']['equal'] = $start_equal + 1;
-
- return $res;
-}
-
-function bb_tag_preg_replace($pattern, $replace, $name, $s) {
-
- $string = $s;
-
- $occurance = 1;
- $pos = get_bb_tag_pos($string, $name, $occurance);
- while($pos !== false && $occurance < 1000) {
-
- $start = substr($string, 0, $pos['start']['open']);
- $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
- $end = substr($string, $pos['end']['close']);
- if($end === false)
- $end = '';
-
- $subject = preg_replace($pattern, $replace, $subject);
- $string = $start . $subject . $end;
-
- $occurance++;
- $pos = get_bb_tag_pos($string, $name, $occurance);
- }
-
- return $string;
-}
-
-function share_shield($m) {
- return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]);
-}
-
-function share_unshield($m) {
- $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]);
- return str_replace($m[1], base64url_decode($x), $m[0]);
-}
function diaspora_mention_callback($matches) {
diff --git a/include/oembed.php b/include/oembed.php
index 5865c95d5..e35a77fa3 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -134,7 +134,7 @@ function oembed_fetch_url($embedurl){
$txt = null;
// we should try to cache this and avoid a lookup on each render
- $zrl = is_matrix_url($embedurl);
+ $zrl = ((get_config('system','oembed_zrl')) ? is_matrix_url($embedurl) : false);
$furl = ((local_channel() && $zrl) ? zid($embedurl) : $embedurl);
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php
index cc1f3b5d0..eb61578e1 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -252,11 +252,10 @@ abstract class photo_driver {
*/
if(! $this->is_valid())
- return FALSE;
-
+ return false;
if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg'))
- return;
+ return false;
$exif = @exif_read_data($filename,null,true);
@@ -489,8 +488,10 @@ function guess_image_type($filename, $headers = '') {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$ph = photo_factory('');
$types = $ph->supportedTypes();
- foreach ($types as $m=>$e){
- if ($ext==$e) $type = $m;
+ foreach($types as $m => $e) {
+ if($ext === $e) {
+ $type = $m;
+ }
}
}
@@ -502,7 +503,7 @@ function guess_image_type($filename, $headers = '') {
}
}
- logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
+ logger('Photo: guess_image_type: type = ' . $type, LOGGER_DEBUG);
return $type;
}
diff --git a/include/photos.php b/include/photos.php
index 8a7e49df6..de5e08646 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -495,15 +495,15 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di
$ret['success'] = true;
$ret['albums'] = array();
foreach($albums as $k => $album) {
- $entry = array(
- 'text' => (($album['album']) ? $album['album'] : '/'),
+ $entry = [
+ 'text' => (($album['album']) ? $album['album'] : '/'),
'shorttext' => (($album['album']) ? ellipsify($album['album'],28) : '/'),
- 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'),
- 'total' => $album['total'],
- 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'],
+ 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'),
+ 'total' => $album['total'],
+ 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'],
'urlencode' => urlencode($album['album']),
- 'bin2hex' => $album['folder']
- );
+ 'bin2hex' => $album['folder']
+ ];
$ret['albums'][] = $entry;
}
}
diff --git a/include/socgraph.php b/include/socgraph.php
index 69365f80f..9a6245d01 100644
--- a/include/socgraph.php
+++ b/include/socgraph.php
@@ -243,77 +243,6 @@ function common_friends($uid,$xchan,$start = 0,$limit=100000000,$shuffle = false
}
-function count_common_friends_zcid($uid,$zcid) {
-
- $r = q("SELECT count(*) as total
- FROM glink left join gcontact on glink.gcid = gcontact.id
- where glink.zcid = %d
- and gcontact.nurl in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) ",
- intval($zcid),
- intval($uid)
- );
-
- if(count($r))
- return $r[0]['total'];
-
- return 0;
-}
-
-function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = false) {
-
- if($shuffle)
- $sql_extra = " order by rand() ";
- else
- $sql_extra = " order by gcontact.name asc ";
-
- $r = q("SELECT gcontact.*
- FROM glink left join gcontact on glink.gcid = gcontact.id
- where glink.zcid = %d
- and gcontact.nurl in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 )
- $sql_extra limit %d offset %d",
- intval($zcid),
- intval($uid),
- intval($limit),
- intval($start)
- );
-
- return $r;
-}
-
-
-function count_all_friends($uid,$cid) {
-
- $r = q("SELECT count(*) as total
- FROM glink left join gcontact on glink.gcid = gcontact.id
- where glink.cid = %d and glink.uid = %d ",
- intval($cid),
- intval($uid)
- );
-
- if(count($r))
- return $r[0]['total'];
-
- return 0;
-}
-
-
-function all_friends($uid,$cid,$start = 0, $limit = 80) {
-
- $r = q("SELECT gcontact.*
- FROM glink left join gcontact on glink.gcid = gcontact.id
- where glink.cid = %d and glink.uid = %d
- order by gcontact.name asc LIMIT %d OFFSET %d ",
- intval($cid),
- intval($uid),
- intval($limit),
- intval($start)
- );
-
- return $r;
-}
-
-
-
function suggestion_query($uid, $myxchan, $start = 0, $limit = 80) {
if((! $uid) || (! $myxchan))
diff --git a/include/taxonomy.php b/include/taxonomy.php
index 0b4b2aa9a..dc0e439e2 100644
--- a/include/taxonomy.php
+++ b/include/taxonomy.php
@@ -44,6 +44,36 @@ function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') {
}
+function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = '') {
+
+ if($type2) {
+ $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term = '%s' and term.uid = %d and term.otype = 1",
+ intval($type),
+ intval($type2),
+ dbesc($s),
+ intval($uid)
+ );
+ }
+ else {
+ $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term = '%s' and term.uid = %d and term.otype = 1",
+ intval($type),
+ dbesc($s),
+ intval($uid)
+ );
+ }
+ if($r) {
+ $str = '';
+ foreach($r as $rv) {
+ if($str)
+ $str .= ',';
+ $str .= intval($rv['parent']);
+ }
+ return " AND " . (($table) ? dbesc($table) . '.' : '') . "id in ( $str ) ";
+ }
+ return " AND false ";
+}
+
+
function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') {
if(! $term)
return false;
diff --git a/include/text.php b/include/text.php
index d352a61bf..6f5c48679 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2969,40 +2969,13 @@ function text_highlight($s, $lang) {
$s = jindent($s);
}
- if(! strpos('Text_Highlighter', get_include_path())) {
- set_include_path(get_include_path() . PATH_SEPARATOR . 'library/Text_Highlighter');
- }
- require_once('library/Text_Highlighter/Text/Highlighter.php');
- require_once('library/Text_Highlighter/Text/Highlighter/Renderer/Html.php');
- $options = array(
- 'numbers' => HL_NUMBERS_LI,
- 'tabsize' => 4,
- );
- $tag_added = false;
- $s = trim(html_entity_decode($s, ENT_COMPAT));
- $s = str_replace(" ", "\t", $s);
-
- // The highlighter library insists on an opening php tag for php code blocks. If
- // it isn't present, nothing is highlighted. So we're going to see if it's present.
- // If not, we'll add it, and then quietly remove it after we get the processed output back.
-
- if($lang === 'php') {
- if(strpos('<?php', $s) !== 0) {
- $s = '<?php' . "\n" . $s;
- $tag_added = true;
- }
- }
- $renderer = new Text_Highlighter_Renderer_HTML($options);
- $hl = Text_Highlighter::factory($lang);
- $hl->setRenderer($renderer);
- $o = $hl->highlight($s);
- $o = str_replace([" ", "\n"], ["&nbsp;&nbsp;&nbsp;&nbsp;", ''], $o);
+ $arr = [ 'text' => $s, 'language' => $lang, 'success' => false ];
+ call_hooks('text_highlight',$arr);
- if($tag_added) {
- $b = substr($o, 0, strpos($o, '<li>'));
- $e = substr($o, strpos($o, '</li>'));
- $o = $b . $e;
- }
+ if($arr['success'])
+ $o = $arr['text'];
+ else
+ $o = $s;
return('<code>' . $o . '</code>');
}
@@ -3065,6 +3038,14 @@ function create_table_from_array($table, $arr) {
return $r;
}
+function share_shield($m) {
+ return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]);
+}
+
+function share_unshield($m) {
+ $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]);
+ return str_replace($m[1], base64url_decode($x), $m[0]);
+}
function cleanup_bbcode($body) {