improved link bot and bbcode2html

main
fuzzykitten 2025-05-24 15:52:11 -04:00
parent ce0e2cac2f
commit a9919af3cf
5 changed files with 21 additions and 20 deletions

View File

@ -24,8 +24,7 @@ $settings = array(
// the description of the overbpoard that is displayed when the users hovers on the link for the overboard
"hover_title_main" => 'This is the main sub. Use to post important stuff and to create other subs.',
// the description of the sub main that is displayed when the users hovers on the link.
"enable_reddit_bot" => TRUE, // use a bot to detect links to clearnet reddit, and post corresponding ones to an i2p frontend
"enable_wikipedia_bot" => TRUE, // the same, but for wikipedia links
"enable_link_bot" => TRUE, // use a bot to detect links to clearnet, and post corresponding ones to an i2p frontend
"enable_sub_creation" => TRUE, // enable users to create subs by posting in main
"enable_logging" => TRUE, // set to FALSE to disable all logs of endboard. This will provide stricter privacy, however, it will also
// disable the features: max_post_*, bot_block, portal, max_requests_* and fail2ban.
@ -90,8 +89,6 @@ $settings = array(
"min_space" => 200, // the minimum free space on the file system in Mb, if not available, no new posts will be taken
"pagination" => 10, // number of messages per page to show for main, other subs and overboard. Threads and individual feeds show all messages.
"max_name_sub" => 20, // the maximum number of characters allowed for the name of a sub, exceeding input will be cut
"line_break" => 300, // number of characters after which the line is broken when posts are displayed.
// 300 is to display certain ascii-art. 80...120 is fine for texts.
"lifetime_token" => 5, // the lifetime of an access token for an admin or mod in minutes. After that a new login is needed.
"original_content_thread" => FALSE, // do not allow the same text to be posted twice in the same thread
"original_content_sub" => TRUE, // do not allow the same text to be posted twice in the same sub, including all threads on the sub (overrides previous if TRUE)

View File

@ -92,8 +92,10 @@ function bbcode_to_html($text, $settings, $sub)
// and if so, give back an array with corresponding links in i2p
function link_bot($text, $settings)
{
if ( ($settings['enable_reddit_bot'] == FALSE) ) {
return $text;
$links = array();
if ( ($settings['enable_link_bot'] == FALSE) ) {
return $links;
}
$text = preg_replace('/\s*\R\s*/', ' ', $text);
@ -110,7 +112,9 @@ function link_bot($text, $settings)
'/(http\:\/\/reddit\.com\/)(.*)/',
'/(http\:\/\/redd\.it\/)(.*)/',
'/(https\:\/\/en\.wikipedia\.org\/)(.*)/',
'/(http\:\/\/en\.wikipedia\.org\/)(.*)/'
'/(http\:\/\/en\.wikipedia\.org\/)(.*)/',
'/(https\:\/\/en\.m\.wikipedia\.org\/)(.*)/',
'/(http\:\/\/en\.m\.wikipedia\.org\/)(.*)/'
);
$replace = array (
@ -123,11 +127,11 @@ function link_bot($text, $settings)
'[url http://libreddit.qwik.i2p/$2]',
'[url http://libreddit.qwik.i2p/$2]',
'[url http://wikiless.i2p/$2]',
'[url http://wikiless.i2p/$2]',
'[url http://wikiless.i2p/$2]',
'[url http://wikiless.i2p/$2]'
);
$links = array();
foreach($words as $word){
$new_link = preg_replace($search, $replace, $word);
if ( $new_link != $word ) {

View File

@ -408,8 +408,6 @@ function show_settings($settings){
. $settings['pagination'] . "</td></tr>";
echo "<tr><td>Maximum length of a subs name</td><td>"
. $settings['max_name_sub'] . "</td></tr>";
echo "<tr><td>Line break after x charcters</td><td>"
. $settings['line_break'] . "</td></tr>";
echo "<tr><td>Require original content in a thread</td><td>";
var_export($settings['original_content_thread']);
echo "</td></tr>";

View File

@ -627,6 +627,10 @@ switch($mode) {
$post_id = make_post($db, $sub, $settings, $text, $org_id);
$links = array_unique(link_bot($text, $settings));
if ( $org_id == '' ) {
$org_id = $post_id;
}
if ( !empty($links) ) {
foreach($links as $link) {
$text = "This is the link detection bot.\n\r"

View File

@ -248,11 +248,10 @@ function bump_message($db, $org_id, $sub)
}
// Break text according to config.php, also transform \r\n to <br>
function break_text($text, $settings)
function break_text($text)
{
$post_text = wordwrap($text, $settings['line_break'], "\n", TRUE);
$post_text = nl2br($post_text, FALSE);
$post_text = nl2br($text, FALSE);
return $post_text;
}
@ -1172,7 +1171,7 @@ function print_thread($db, $sub, $settings, $org_id)
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$post_text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($post_text, $settings),
$post_text = break_text(bbcode_to_html($post_text),
$settings);
$id_text = make_id_text($post_id);
@ -1246,7 +1245,7 @@ function print_overboard($db, $settings, $page)
$org_id = "{$row[1]}";
$sub = "{$row[2]}";
$text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($text, $settings), $settings);
$post_text = break_text(bbcode_to_html($text, $settings));
$link_string_1 = "/mob/r/$sub/$org_id/op";
$link_string_2 = "/mob/r/$sub/$org_id";
@ -1322,7 +1321,7 @@ function print_individual_feed($db, $settings, $ex_subs, $in_subs)
$sub = "{$row[2]}";
$text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($text, $settings), $settings);
$post_text = break_text(bbcode_to_html($text, $settings));
$link_string_1 = "/mob/r/$sub/$org_id/op";
$link_string_2 = "/mob/r/$sub/$org_id";
@ -1467,8 +1466,7 @@ function print_replies($db, $sub, $post_id, $org_id, $settings)
$counter++;
$post = array();
$sub_post_text = break_text(bbcode_to_html
($sub_text, $settings, $sub),
$settings);
($sub_text, $settings, $sub));
array_push($post, $sub_post_id);
array_push($post, $sub_org_id);
array_push($post, $sub_post_text);
@ -1613,7 +1611,7 @@ function print_sub($db, $sub, $settings, $page)
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($text, $settings), $settings);
$post_text = break_text(bbcode_to_html($text, $settings));
$id_text = make_id_text($post_id);
$link_string_1 = "/mob/r/$sub/$org_id/op";