aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-11-05 09:55:23 +0100
committerMario Vavti <mario@mariovavti.com>2018-11-05 09:55:23 +0100
commit4830a1559d5ad9f59d809bf3d693592d3f7c8ab2 (patch)
treedb87b400af1f3de1ca01bccef58b0bf4e55b1241 /include
parentc8dd516d6c743d0371dc2ccb476eb70bcc17fa0a (diff)
parent92ea3ef72036c39601b69565f3e03fa44ad9aef7 (diff)
downloadvolse-hubzilla-4830a1559d5ad9f59d809bf3d693592d3f7c8ab2.tar.gz
volse-hubzilla-4830a1559d5ad9f59d809bf3d693592d3f7c8ab2.tar.bz2
volse-hubzilla-4830a1559d5ad9f59d809bf3d693592d3f7c8ab2.zip
Merge branch 'dev'
Diffstat (limited to 'include')
-rw-r--r--include/hubloc.php33
-rw-r--r--include/import.php3
-rw-r--r--include/markdown.php26
-rw-r--r--include/network.php4
-rwxr-xr-xinclude/oembed.php7
5 files changed, 39 insertions, 34 deletions
diff --git a/include/hubloc.php b/include/hubloc.php
index d1170a62c..b2903b0ee 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -186,31 +186,30 @@ function hubloc_change_primary($hubloc) {
logger('no hubloc');
return false;
}
- if(! (intval($hubloc['hubloc_primary']))) {
- logger('not primary: ' . $hubloc['hubloc_url']);
- return false;
- }
- logger('setting primary: ' . $hubloc['hubloc_url']);
+ logger('setting primary: ' . $hubloc['hubloc_url'] . ((intval($hubloc['hubloc_primary'])) ? ' true' : ' false'));
- // See if there's a local channel
+ // See if this is a local hubloc and if so update the primary for the corresponding channel record.
- $r = q("select channel_id, channel_primary from channel where channel_hash = '%s' limit 1",
- dbesc($hubloc['hubloc_hash'])
- );
- if($r) {
- if(! $r[0]['channel_primary']) {
- q("update channel set channel_primary = 1 where channel_id = %d",
- intval($r[0]['channel_id'])
- );
- }
- else {
- q("update channel set channel_primary = 0 where channel_id = %d",
+ if($hubloc['hubloc_url'] === z_root()) {
+ $r = q("select channel_id from channel where channel_hash = '%s' limit 1",
+ dbesc($hubloc['hubloc_hash'])
+ );
+ if($r) {
+ q("update channel set channel_primary = %d where channel_id = %d",
+ intval($hubloc['hubloc_primary']),
intval($r[0]['channel_id'])
);
}
}
+ // we only need to proceed further if this particular hubloc is now primary
+
+ if(! (intval($hubloc['hubloc_primary']))) {
+ logger('not primary: ' . $hubloc['hubloc_url']);
+ return false;
+ }
+
// do we even have an xchan for this hubloc and if so is it already set as primary?
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
diff --git a/include/import.php b/include/import.php
index 714161c57..6476aa688 100644
--- a/include/import.php
+++ b/include/import.php
@@ -93,8 +93,7 @@ function import_channel($channel, $account_id, $seize, $newname = '') {
'channel_w_comment', 'channel_w_mail', 'channel_w_like', 'channel_w_tagwall',
'channel_w_chat', 'channel_w_storage', 'channel_w_pages', 'channel_a_republish',
'channel_a_delegate', 'perm_limits', 'channel_password', 'channel_salt',
- 'channel_moved', 'channel_primary', 'channel_removed', 'channel_deleted',
- 'channel_system'
+ 'channel_moved', 'channel_removed', 'channel_deleted', 'channel_system'
];
$clean = array();
diff --git a/include/markdown.php b/include/markdown.php
index d2148811c..64f0a0854 100644
--- a/include/markdown.php
+++ b/include/markdown.php
@@ -248,20 +248,12 @@ function bb_to_markdown($Text, $options = []) {
// Convert it to HTML - don't try oembed
$Text = bbcode($Text, [ 'tryoembed' => false ]);
- // Markdownify does not preserve previously escaped html entities such as <> and &.
- //$Text = str_replace(array('&lt;','&gt;','&amp;'),array('&_lt_;','&_gt_;','&_amp_;'),$Text);
-
// Now convert HTML to Markdown
-
$Text = html2markdown($Text);
//html2markdown adds backslashes infront of hashes after a new line. remove them
$Text = str_replace("\n\#", "\n#", $Text);
- // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason.
-
- //$Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('&lt;','&gt;','&amp;'),$Text);
-
// If the text going into bbcode() has a plain URL in it, i.e.
// with no [url] tags around it, it will come out of parseString()
// looking like: <http://url.com>, which gets removed by strip_tags().
@@ -291,12 +283,24 @@ function bb_to_markdown($Text, $options = []) {
* If the HTML text can not get parsed it will return an empty string.
*
* @param string $html The HTML code to convert
+ * @param array $options an array of options to pass to the environment
* @return string Markdown representation of the given HTML text, empty on error
*/
-function html2markdown($html,$options = []) {
+function html2markdown($html, $options = []) {
$markdown = '';
- $internal_errors = libxml_use_internal_errors(true);
+ if(! $options) {
+ $options = [
+ 'header_style' => 'setext', // Set to 'atx' to output H1 and H2 headers as # Header1 and ## Header2
+ 'suppress_errors' => true, // Set to false to show warnings when loading malformed HTML
+ 'strip_tags' => false, // Set to true to strip tags that don't have markdown equivalents. N.B. Strips tags, not their content. Useful to clean MS Word HTML output.
+ 'bold_style' => '**', // DEPRECATED: Set to '__' if you prefer the underlined style
+ 'italic_style' => '*', // DEPRECATED: Set to '_' if you prefer the underlined style
+ 'remove_nodes' => '', // space-separated list of dom nodes that should be removed. example: 'meta style script'
+ 'hard_break' => false, // Set to true to turn <br> into `\n` instead of ` \n`
+ 'list_item_style' => '-', // Set the default character for each <li> in a <ul>. Can be '-', '*', or '+'
+ ];
+ }
$environment = Environment::createDefaultEnvironment($options);
$environment->addConverter(new TableConverter());
@@ -308,8 +312,6 @@ function html2markdown($html,$options = []) {
logger("Invalid HTML. HTMLToMarkdown library threw an exception.");
}
- libxml_use_internal_errors($internal_errors);
-
return $markdown;
}
diff --git a/include/network.php b/include/network.php
index 4c9813768..f976dcc35 100644
--- a/include/network.php
+++ b/include/network.php
@@ -711,9 +711,9 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
foreach($matches as $mtch) {
logger('data: ' . $mtch[2] . ' ' . $mtch[3]);
- if(substr($mtch[1],0,1) == '=') {
+ if(substr($mtch[2],0,1) == '=') {
$owidth = intval(substr($mtch[2],1));
- if(intval($owidth) > 0 && intval($owidth) < 1024)
+ if($owidth > 0 && $owidth < 1024)
continue;
}
diff --git a/include/oembed.php b/include/oembed.php
index 41ab001d3..e5557dc11 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -272,6 +272,7 @@ function oembed_fetch_url($embedurl){
}
$j['embedurl'] = $embedurl;
+ $j['zrl'] = $is_matrix;
// logger('fetch return: ' . print_r($j,true));
@@ -335,7 +336,11 @@ function oembed_format_object($j){
case "rich": {
// not so safe..
- $ret.= $jhtml;
+ if($j['zrl']) {
+ $ret = ((preg_match('/^<div[^>]+>(.*?)<\/div>$/is',$j['html'],$o)) ? $o[1] : $j['html']);
+ } else {
+ $ret.= $jhtml;
+ };
}; break;
}