diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/api.php | 2 | ||||
-rw-r--r-- | include/bbcode.php | 52 | ||||
-rw-r--r-- | include/conversation.php | 14 | ||||
-rw-r--r-- | include/identity.php | 64 | ||||
-rwxr-xr-x | include/items.php | 34 | ||||
-rwxr-xr-x | include/oembed.php | 169 | ||||
-rw-r--r-- | include/text.php | 35 | ||||
-rw-r--r-- | include/zot.php | 2 |
8 files changed, 307 insertions, 65 deletions
diff --git a/include/api.php b/include/api.php index e64c86695..3b2c71923 100644 --- a/include/api.php +++ b/include/api.php @@ -2108,7 +2108,7 @@ require_once('include/api_auth.php'); 'shorturllength' => '30', 'hubzilla' => array( 'PLATFORM_NAME' => Zotlabs\Project\System::get_platform_name(), - 'RED_VERSION' => Zotlabs\Project\System::get_project_version(), + 'STD_VERSION' => Zotlabs\Project\System::get_project_version(), 'ZOT_REVISION' => ZOT_REVISION, 'DB_UPDATE_VERSION' => Zotlabs\Project\System::get_update_version() ) diff --git a/include/bbcode.php b/include/bbcode.php index b8cd23f59..7a7ea8ce6 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -345,6 +345,48 @@ function bb_spoilertag($match) { return '<div onclick="openClose(\'opendiv-' . $rnd . '\'); return false;" class="fakelink">' . $openclose . '</div><blockquote id="opendiv-' . $rnd . '" style="display: none;">' . $text . '</blockquote>'; } +function bb_definitionList($match) { + // $match[1] is the markup styles for the "terms" in the definition list. + // $match[2] is the content between the [dl]...[/dl] tags + + $classes = ''; + if (stripos($match[1], "b") !== false) $classes .= 'dl-terms-bold '; + if (stripos($match[1], "i") !== false) $classes .= 'dl-terms-italic '; + if (stripos($match[1], "u") !== false) $classes .= 'dl-terms-underline '; + if (stripos($match[1], "l") !== false) $classes .= 'dl-terms-large '; + if (stripos($match[1], "m") !== false) $classes .= 'dl-terms-monospace '; + if (stripos($match[1], "h") !== false) $classes .= 'dl-horizontal '; // dl-horizontal is already provided by bootstrap + if (strlen($classes) === 0) $classes = "dl-terms-plain"; + + // The bbcode transformation will be: + // [*=term-text] description-text => </dd> <dt>term-text<dt><dd> description-text + // then after all replacements have been made, the extra </dd> at the start of the + // first line can be removed. HTML5 allows the tag to be missing from the end of the last line. + // Using '(?<!\\\)' to allow backslash-escaped closing braces to appear in the term-text. + $closeDescriptionTag = "</dd>\n"; + $eatLeadingSpaces = '(?: |[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element + $listElements = preg_replace('/^(\n|<br \/>)/', '', $match[2]); // ltrim the first newline + $listElements = preg_replace( + '/' . $eatLeadingSpaces . '\[\*=([[:print:]]*?)(?<!\\\)\]/ism', + $closeDescriptionTag . '<dt>$1</dt><dd>', + $listElements + ); + // Unescape any \] inside the <dt> tags + $listElements = preg_replace_callback('/<dt>(.*?)<\/dt>/ism', 'bb_definitionList_unescapeBraces', $listElements); + + // Remove the extra </dd> at the start of the string, if there is one. + $firstOpenTag = strpos($listElements, '<dd>'); + $firstCloseTag = strpos($listElements, $closeDescriptionTag); + if ($firstCloseTag !== false && ($firstOpenTag === false || ($firstCloseTag < $firstOpenTag))) { + $listElements = preg_replace( '/<\/dd>/ism', '', $listElements, 1); + } + + return '<dl class="bb-dl ' . rtrim($classes) . '">' . $listElements . '</dl>';; +} +function bb_definitionList_unescapeBraces($match) { + return '<dt>' . str_replace('\]', ']', $match[1]) . '</dt>'; +} + /** * @brief Sanitize style properties from BBCode to HTML. * @@ -587,7 +629,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) } if($tryoembed) { if (strpos($Text,'[/url]') !== false) { - $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'tryoembed', $Text); + $Text = preg_replace_callback("/[^\^]\[url\]([$URLSearchString]*)\[\/url\]/ism", 'tryoembed', $Text); } } if (strpos($Text,'[/url]') !== false) { @@ -713,6 +755,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) || ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) || + ((strpos($Text, "[/dl]") !== false) && (strpos($Text, "[dl") !== false)) || ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) { $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text); $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text); @@ -724,6 +767,13 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text); $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text); $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>', $Text); + + // [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large + // etc. style may be specified for the "terms" in the definition list. The quotation marks + // are also optional. The regex looks intimidating, but breaks down as: + // "[dl" <optional-whitespace> <optional-termStyles> "]" <matchGroup2> "[/dl]" + // where optional-termStyles are: "terms=" <optional-quote> <matchGroup1> <optional-quote> + $Text = preg_replace_callback('/\[dl[[:space:]]*(?:terms=(?:"|")?([a-zA-Z]+)(?:"|")?)?\](.*?)\[\/dl\]/ism', 'bb_definitionList', $Text); } if (strpos($Text,'[th]') !== false) { $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>', $Text); diff --git a/include/conversation.php b/include/conversation.php index 94f1e7da7..ea5be221f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1138,6 +1138,14 @@ function status_editor($a, $x, $popup = false) { if(x($x, 'hide_location')) $geotag = $setloc = $clearloc = ''; + $weblink = t('Insert web link'); + if(x($x, 'hide_weblink')) + $weblink = ''; + + $writefiles = perm_is_allowed($x['profile_uid'], get_observer_hash(), 'write_storage'); + if(x($x, 'hide_attach')) + $writefiles = false; + $mimeselect = ''; if(array_key_exists('mimetype', $x) && $x['mimetype']) { if($x['mimetype'] != 'text/bbcode') @@ -1187,7 +1195,7 @@ function status_editor($a, $x, $popup = false) { $jotplugins = ''; $preview = t('Preview'); - if(x($x, 'nopreview')) + if(x($x, 'hide_preview')) $preview = ''; $defexpire = ((($z = get_pconfig($x['profile_uid'], 'system', 'default_post_expire')) && (! $webpage)) ? $z : ''); @@ -1213,14 +1221,14 @@ function status_editor($a, $x, $popup = false) { '$pagetitle' => (x($x,'pagetitle') ? $x['pagetitle'] : ''), '$id_select' => $id_select, '$id_seltext' => t('Post as'), - '$writefiles' => perm_is_allowed($x['profile_uid'], get_observer_hash(), 'write_storage'), + '$writefiles' => $writefiles, '$bold' => t('Bold'), '$italic' => t('Italic'), '$underline' => t('Underline'), '$quote' => t('Quote'), '$code' => t('Code'), '$attach' => t('Attach file'), - '$weblink' => t('Insert web link'), + '$weblink' => $weblink, '$setloc' => $setloc, '$voting' => t('Toggle voting'), '$feature_voting' => $feature_voting, diff --git a/include/identity.php b/include/identity.php index 1c899048a..c60c846c0 100644 --- a/include/identity.php +++ b/include/identity.php @@ -491,7 +491,7 @@ function identity_basic_export($channel_id, $items = false) { // use constants here as otherwise we will have no idea if we can import from a site // with a non-standard platform and version. - $ret['compatibility'] = array('project' => PLATFORM_NAME, 'version' => RED_VERSION, 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Project\System::get_server_role()); + $ret['compatibility'] = array('project' => PLATFORM_NAME, 'version' => STD_VERSION, 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Project\System::get_server_role()); $r = q("select * from channel where channel_id = %d limit 1", intval($channel_id) @@ -1878,3 +1878,65 @@ function get_zcard($channel,$observer_hash = '',$args = array()) { return $o; } + + +function get_zcard_embed($channel,$observer_hash = '',$args = array()) { + + logger('get_zcard_embed'); + + $maxwidth = (($args['width']) ? intval($args['width']) : 0); + $maxheight = (($args['height']) ? intval($args['height']) : 0); + + + if(($maxwidth > 1200) || ($maxwidth < 1)) + $maxwidth = 1200; + + if($maxwidth <= 425) { + $width = 425; + $size = 'hz_small'; + $cover_size = PHOTO_RES_COVER_425; + $pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']); + } + elseif($maxwidth <= 900) { + $width = 900; + $size = 'hz_medium'; + $cover_size = PHOTO_RES_COVER_850; + $pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']); + } + elseif($maxwidth <= 1200) { + $width = 1200; + $size = 'hz_large'; + $cover_size = PHOTO_RES_COVER_1200; + $pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']); + } + + $channel['channel_addr'] = $channel['channel_address'] . '@' . App::get_hostname(); + $zcard = array('chan' => $channel); + + $r = q("select height, width, resource_id, scale, type from photo where uid = %d and scale = %d and photo_usage = %d", + intval($channel['channel_id']), + intval($cover_size), + intval(PHOTO_COVER) + ); + + if($r) { + $cover = $r[0]; + $cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['scale']; + } + else { + $cover = $pphoto; + } + + $o .= replace_macros(get_markup_template('zcard_embed.tpl'),array( + '$maxwidth' => $maxwidth, + '$scale' => $scale, + '$translate' => $translate, + '$size' => $size, + '$cover' => $cover, + '$pphoto' => $pphoto, + '$zcard' => $zcard + )); + + return $o; + +} diff --git a/include/items.php b/include/items.php index 2720dd841..b3c9403e0 100755 --- a/include/items.php +++ b/include/items.php @@ -3400,6 +3400,37 @@ function tgroup_check($uid,$item) { */ function start_delivery_chain($channel, $item, $item_id, $parent) { + $sourced = check_item_source($channel['channel_id'],$item); + + if($sourced) { + $r = q("select * from source where src_channel_id = %d and ( src_xchan = '%s' or src_xchan = '*' ) limit 1", + intval($channel['channel_id']), + dbesc(($item['source_xchan']) ? $item['source_xchan'] : $item['owner_xchan']) + ); + if($r) { + $t = trim($r[0]['src_tag']); + if($t) { + $tags = explode(',',$t); + if($tags) { + foreach($tags as $tt) { + $tt = trim($tt); + if($tt) { + q("insert into term (uid,oid,otype,type,term,url) + values(%d,%d,%d,%d,'%s','%s') ", + intval($channel['channel_id']), + intval($item_id), + intval(TERM_OBJ_POST), + intval(TERM_CATEGORY), + dbesc($tt), + dbesc(z_root() . '/channel/' . $channel['channel_address'] . '?f=&cat=' . urlencode($tt)) + ); + } + } + } + } + } + } + // Change this copy of the post to a forum head message and deliver to all the tgroup members // also reset all the privacy bits to the forum default permissions @@ -3459,6 +3490,9 @@ function start_delivery_chain($channel, $item, $item_id, $parent) { intval($item_id) ); + + + if($r) proc_run('php','include/notifier.php','tgroup',$item_id); else { diff --git a/include/oembed.php b/include/oembed.php index 3994af0fb..1e5c51172 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -1,69 +1,106 @@ <?php /** @file */ + + function oembed_replacecb($matches){ $embedurl=$matches[1]; + $result = oembed_action($embedurl); + if($result['action'] === 'block') { + return '<a href="' . $result['url'] . '">' . $result['url'] . '</a>'; + } + + $j = oembed_fetch_url($result['url']); + $s = oembed_format_object($j); + return $s; +} + + +function oembed_action($embedurl) { + + $host = ''; + $action = 'filter'; + + $embedurl = trim(str_replace('&','&', $embedurl)); + + logger('oembed_action: ' . $embedurl, LOGGER_DEBUG, LOG_INFO); + + // These media files should now be caught in bbcode.php + // left here as a fallback in case this is called from another source + + $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm","opus"); + $ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION); + + if(strpos($embedurl,'http://') === 0) { + if(intval(get_config('system','embed_sslonly'))) { + $action = 'block'; + } + } // site white/black list if(($x = get_config('system','embed_deny'))) { - $l = explode("\n",$x); - if($l) { - foreach($l as $ll) { - if(trim($ll) && strpos($embedurl,trim($ll)) !== false) - return '<a href="' . $embedurl . '">' . $embedurl . '</a>'; + if(($x) && (! is_array($x))) + $x = explode("\n",$x); + if($x) { + foreach($x as $ll) { + $t = trim($ll); + if(($t) && (strpos($embedurl,$t) !== false)) { + $action = 'block'; + break; + } } } } + + $found = false; + if(($x = get_config('system','embed_allow'))) { - $found = false; - $l = explode("\n",$x); - if($l) { - foreach($l as $ll) { - if(trim($ll) && strpos($embedurl,trim($ll)) !== false) { + if(($x) && (! is_array($x))) + $x = explode("\n",$x); + if($x) { + foreach($x as $ll) { + $t = trim($ll); + if(($t) && (strpos($embedurl,$t) !== false) && ($action !== 'block')) { $found = true; + $action = 'allow'; break; } } } - if(! $found) { - return '<a href="' . $embedurl . '">' . $embedurl . '</a>'; + if((! $found) && ($action !== 'block')) { + $action = 'filter'; } } - // implements a personal embed white/black list for logged in members + // allow individual members to block something that wasn't blocked already. + // They cannot over-ride the site to allow or change the filtering on an + // embed that is not allowed by the site admin. + if(local_channel()) { if(($x = get_pconfig(local_channel(),'system','embed_deny'))) { - $l = explode("\n",$x); - if($l) { - foreach($l as $ll) { - if(trim($ll) && strpos($embedurl,trim($ll)) !== false) - return '<a href="' . $embedurl . '">' . $embedurl . '</a>'; - } - } - } - if(($x = get_pconfig(local_channel(),'system','embed_allow'))) { - $found = false; - $l = explode("\n",$x); - if($l) { - foreach($l as $ll) { - if(trim($ll) && strpos($embedurl,trim($ll)) !== false) { - $found = true; + if(($x) && (! is_array($x))) + $x = explode("\n",$x); + if($x) { + foreach($x as $ll) { + $t = trim($ll); + if(($t) && (strpos($embedurl,$t) !== false)) { + $action = 'block'; break; } } } - if(! $found) { - return '<a href="' . $embedurl . '">' . $embedurl . '</a>'; - } } } - $j = oembed_fetch_url($embedurl); - $s = oembed_format_object($j); - return $s; -} + $arr = array('url' => $embedurl, 'action' => $action); + call_hooks('oembed_action',$arr); + + logger('action: ' . $arr['action'] . ' url: ' . $arr['url'], LOGGER_DEBUG,LOG_DEBUG); + + return $arr; +} // if the url is embeddable with oembed, return the bbcode link. @@ -79,42 +116,49 @@ function oembed_process($url) { function oembed_fetch_url($embedurl){ - $a = get_app(); + // These media files should now be caught in bbcode.php + // left here as a fallback in case this is called from another source - $embedurl = str_replace('&','&', $embedurl); + $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm","opus"); + $ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION); -// logger('fetch: ' . $embedurl); + $result = oembed_action($embedurl); - $txt = Cache::get(App::$videowidth . $embedurl); + $embedurl = $result['url']; + $action = $result['action']; - if(strstr($txt,'youtu') && strstr(z_root(),'https:')) { - $txt = str_replace('http:','https:',$txt); - } + $txt = null; - // These media files should now be caught in bbcode.php - // left here as a fallback in case this is called from another source + if($action !== 'block') { + $txt = Cache::get(App::$videowidth . $embedurl); - $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm","opus"); - $ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION); - - - if(is_null($txt)){ - $txt = ""; + if(strstr($txt,'youtu') && strstr(z_root(),'https:')) { + $txt = str_replace('http:','https:',$txt); + } + } - if (in_array($ext, $noexts)) { + if(is_null($txt)) { + + $txt = ""; + $furl = $embedurl; + $zrl = false; + + if(local_channel()) { require_once('include/hubloc.php'); - $zrl = is_matrix_url($embedurl); + $zrl = is_matrix_url($furl); if($zrl) - $embedurl = zid($embedurl); + $furl = zid($furl); } - else { + + + if (! in_array($ext, $noexts) && $action !== 'block') { // try oembed autodiscovery $redirects = 0; - $result = z_fetch_url($embedurl, false, $redirects, array('timeout' => 15, 'accept_content' => "text/*", 'novalidate' => true )); + $result = z_fetch_url($furl, false, $redirects, array('timeout' => 15, 'accept_content' => "text/*", 'novalidate' => true )); if($result['success']) $html_text = $result['body']; - if($html_text){ + if($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom){ $xpath = new DOMXPath($dom); @@ -149,6 +193,7 @@ function oembed_fetch_url($embedurl){ } $txt=trim($txt); + if ($txt[0]!="{") $txt='{"type":"error"}'; //save in cache @@ -160,6 +205,18 @@ function oembed_fetch_url($embedurl){ $j = json_decode($txt); + + if($action === 'filter') { + if($j->html) { + $orig = $j->html; + $allow_position = (($zrl) ? true : false); + $j->html = purify_html($j->html,$allow_position); + if($j->html != $orig) { + logger('oembed html was purified. original: ' . $orig . ' purified: ' . $j->html, LOGGER_DEBUG, LOG_INFO); + } + } + } + $j->embedurl = $embedurl; // logger('fetch return: ' . print_r($j,true)); diff --git a/include/text.php b/include/text.php index d7c91e430..66a49d4b5 100644 --- a/include/text.php +++ b/include/text.php @@ -122,7 +122,7 @@ function z_input_filter($channel_id,$s,$type = 'text/bbcode') { -function purify_html($s) { +function purify_html($s, $allow_position = false) { require_once('library/HTMLPurifier.auto.php'); require_once('include/html2bbcode.php'); @@ -202,6 +202,35 @@ function purify_html($s) { $def->addElement('header', 'Block', 'Flow', 'Common'); $def->addElement('footer', 'Block', 'Flow', 'Common'); + + if($allow_position) { + $cssDefinition = $config->getCSSDefinition(); + + $cssDefinition->info['position'] = new HTMLPurifier_AttrDef_Enum(array('absolute', 'fixed', 'relative', 'static', 'inherit'), false); + + $cssDefinition->info['left'] = new HTMLPurifier_AttrDef_CSS_Composite(array( + new HTMLPurifier_AttrDef_CSS_Length(), + new HTMLPurifier_AttrDef_CSS_Percentage() + )); + + $cssDefinition->info['right'] = new HTMLPurifier_AttrDef_CSS_Composite(array( + new HTMLPurifier_AttrDef_CSS_Length(), + new HTMLPurifier_AttrDef_CSS_Percentage() + )); + + $cssDefinition->info['top'] = new HTMLPurifier_AttrDef_CSS_Composite(array( + new HTMLPurifier_AttrDef_CSS_Length(), + new HTMLPurifier_AttrDef_CSS_Percentage() + )); + + $cssDefinition->info['bottom'] = new HTMLPurifier_AttrDef_CSS_Composite(array( + new HTMLPurifier_AttrDef_CSS_Length(), + new HTMLPurifier_AttrDef_CSS_Percentage() + )); + + } + + $purifier = new HTMLPurifier($config); return $purifier->purify($s); @@ -1826,7 +1855,9 @@ function lang_selector() { function engr_units_to_bytes ($size_str) { - switch (substr ($size_str, -1)) { + if(! $size_str) + return $size_str; + switch (substr(trim($size_str), -1)) { case 'M': case 'm': return (int)$size_str * 1048576; case 'K': case 'k': return (int)$size_str * 1024; case 'G': case 'g': return (int)$size_str * 1073741824; diff --git a/include/zot.php b/include/zot.php index 1ca1b862b..157354afa 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3914,7 +3914,7 @@ function zotinfo($arr) { $ret['site']['channels'] = channel_total(); - $ret['site']['version'] = Zotlabs\Project\System::get_platform_name() . ' ' . RED_VERSION . '[' . DB_UPDATE_VERSION . ']'; + $ret['site']['version'] = Zotlabs\Project\System::get_platform_name() . ' ' . STD_VERSION . '[' . DB_UPDATE_VERSION . ']'; $ret['site']['admin'] = get_config('system','admin_email'); |