AvocadoAmber/AvocadoEdition_Light/extend/mmb.lib.php

107 lines
2.8 KiB
PHP
Raw Normal View History

2022-09-17 20:50:50 +09:00
<?php
2024-09-19 20:57:39 +09:00
if (!defined('_GNUBOARD_'))
2024-09-23 11:07:19 +09:00
exit;
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
function autolink($str, $bo_table, $stx = '')
2022-09-17 20:50:50 +09:00
{
2024-09-19 20:57:39 +09:00
$str = ' ' . $str;
2024-09-30 01:58:32 +09:00
$str = strtr($str, ["&#039;" => "'", "&#034;" => "&quot;"]);
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$str = preg_replace(
2024-09-30 01:58:32 +09:00
'`<a href="([^"]*)"[^>]*>\S*</a>`i',
2024-09-19 20:57:39 +09:00
'<a href="$1" target="_blank" class="other-site-link">Link URL</a>',
$str
);
2022-09-17 20:50:50 +09:00
2024-09-30 01:58:32 +09:00
$str = substr($str, 1);
2022-09-17 20:50:50 +09:00
2024-09-30 01:58:32 +09:00
$str = preg_replace(
"/\\#([0-9a-zA-Z가-힣_])([0-9a-zA-Z가-힣_]*)/",
'<a href="?bo_table=' . $bo_table . '&amp;sfl=hash&amp;stx=%23$1$2" class="link_hash_tag">&#35;$1$2</a>',
$str
);
2022-09-17 20:50:50 +09:00
2024-09-30 01:58:32 +09:00
$str = preg_replace(
"/\\@([0-9])([0-9]*)/",
'<a href="?bo_table=' . $bo_table . '&amp;sfl=log&amp;stx=$1$2&amp;single=Y" target="_blank" class="log_link_tag">$1$2</a>',
$str
);
2024-09-19 20:57:39 +09:00
2024-09-30 01:58:32 +09:00
return strtr($str, ["[[" => "<span class='member_call'>", "]]" => "</span>"]);
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
function get_sql_search_mmb($search_ca_name, $search_field, $search_text, $search_operator = 'and', $single_use = '')
2022-09-17 20:50:50 +09:00
{
2024-09-19 20:57:39 +09:00
global $g5;
2024-09-30 01:58:32 +09:00
$str = $search_ca_name ? "ca_name = '$search_ca_name'" : "";
2024-09-19 20:57:39 +09:00
2024-09-30 01:58:32 +09:00
$search_text = trim(strip_tags($search_text));
2024-09-19 20:57:39 +09:00
if (!$search_text) {
2024-09-30 01:58:32 +09:00
return $search_ca_name ? $str : '0';
2024-09-19 20:57:39 +09:00
}
2024-09-30 01:58:32 +09:00
$str = $str ? "$str and " : "";
2024-09-19 20:57:39 +09:00
$tmp = explode(",", trim($search_field));
$field = explode("||", $tmp[0]);
2024-09-30 01:58:32 +09:00
$not_comment = !empty($tmp[1]) ? $tmp[1] : "";
$search_parts = [];
foreach (explode(" ", $search_text) as $search_str) {
if ($search_str === "")
2024-09-19 20:57:39 +09:00
continue;
insert_popular($field, $search_str);
2024-09-30 01:58:32 +09:00
$field_parts = [];
foreach ($field as $f) {
$f = preg_match("/^[\w,|]+$/", $f) ? $f : "wr_subject";
2024-09-19 20:57:39 +09:00
2024-09-30 01:58:32 +09:00
switch ($f) {
2024-09-19 20:57:39 +09:00
case "mb_id":
case "wr_name":
2024-09-30 01:58:32 +09:00
$field_parts[] = "$f = '$search_str'";
2024-09-19 20:57:39 +09:00
break;
case "wr_hit":
case "wr_good":
case "wr_nogood":
2024-09-30 01:58:32 +09:00
$field_parts[] = "$f >= '$search_str'";
2024-09-19 20:57:39 +09:00
break;
case "wr_num":
2024-09-30 01:58:32 +09:00
$field_parts[] = "$f = " . ((-1) * $search_str);
2024-09-19 20:57:39 +09:00
break;
case "wr_ip":
case "wr_password":
2024-09-30 01:58:32 +09:00
$field_parts[] = "1=0";
2024-09-19 20:57:39 +09:00
break;
case "hash":
2024-09-30 01:58:32 +09:00
$field_parts[] = "wr_content like '%$search_str%'";
2024-09-19 20:57:39 +09:00
break;
case "log":
2024-09-30 01:58:32 +09:00
$log_condition = "wr_num >= " . ($search_str * -1);
2024-09-19 20:57:39 +09:00
if ($single_use) {
2024-09-30 01:58:32 +09:00
$log_condition .= " and wr_num < " . (($search_str * -1) + 1);
2024-09-19 20:57:39 +09:00
}
2024-09-30 01:58:32 +09:00
$field_parts[] = $log_condition;
2024-09-19 20:57:39 +09:00
break;
default:
2024-09-30 01:58:32 +09:00
$field_parts[] = preg_match("/[a-zA-Z]/", $search_str)
? "INSTR(LOWER($f), LOWER('$search_str'))"
: "INSTR($f, '$search_str')";
2024-09-19 20:57:39 +09:00
break;
}
}
2024-09-30 01:58:32 +09:00
$search_parts[] = "(" . implode(" or ", $field_parts) . ")";
}
$str .= "(" . implode(" $search_operator ", $search_parts) . ")";
2024-09-19 20:57:39 +09:00
2024-09-30 01:58:32 +09:00
if ($not_comment) {
$str .= " and wr_is_comment = '0'";
2024-09-19 20:57:39 +09:00
}
return $str;
2022-09-17 20:50:50 +09:00
}