<commit_before><?
defined('C5_EXECUTE') or die("Access Denied.");

class SearchBlockController extends BlockController {
	
	protected $btTable = 'btSearch';
	protected $btInterfaceWidth = "400";
	protected $btInterfaceHeight = "240";
	
	public $title = "";
	public $buttonText = ">"; 
	public $baseSearchPath = "";
	public $resultsURL = "";
		
	protected $hColor = '#EFE795';

	public function highlightedMarkup($fulltext, $highlight) {
		if (!$highlight) {
			return $fulltext;
		}

		$this->hText = $fulltext;
		$this->hHighlight  = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex
		$this->hText = @preg_replace( "#$this->hHighlight#ui", '<span style="background-color:'. $this->hColor .';">$0</span>', $this->hText );	
		return $this->hText; 
	}
	
	public function highlightedExtendedMarkup($fulltext, $highlight) {
		$text = @preg_replace("#\n|\r#", ' ', $fulltext);
		
		$matches = array();
		$highlight = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex
		
		if (!$highlight) {
			$text = Loader::helper('text')->shorten($fulltext, 180);
			if (strlen($fulltext) > 180) {
				$text . '&hellip;';
			}
			return $text;
		}
		
		$regex = '([[:alnum:]|\'|\.|_|\s]{0,45})'. $highlight .'([[:alnum:]|\.|_|\s]{0,45})';
		preg_match_all("#$regex#ui", $text, $matches);
		
		if(!empty($matches[0])) {
			$body_length = 0;
			$body_string = array();
			foreach($matches[0] as $line) {
				$body_length += strlen($line);
				
				$r = $this->highlightedMarkup($line, $highlight);
				if ($r) {
					$body_string[] = $r;
				}
				if($body_length > 150)
					break;
			}
			if(!empty($body_string))
				return @implode("&hellip;", $body_string);<commit_msg>Add a optional line break after the ellipsis character to prevent cases where very long lines break layout. http://developers.whatwg.org/text-level-semantics.html#the-wbr-element Former-commit-id: c1c48b701ee359a45c8c85374c5b95d71f9f599d<commit_after><?
defined('C5_EXECUTE') or die("Access Denied.");

class SearchBlockController extends BlockController {
	
	protected $btTable = 'btSearch';
	protected $btInterfaceWidth = "400";
	protected $btInterfaceHeight = "240";
	
	public $title = "";
	public $buttonText = ">"; 
	public $baseSearchPath = "";
	public $resultsURL = "";
		
	protected $hColor = '#EFE795';

	public function highlightedMarkup($fulltext, $highlight) {
		if (!$highlight) {
			return $fulltext;
		}

		$this->hText = $fulltext;
		$this->hHighlight  = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex
		$this->hText = @preg_replace( "#$this->hHighlight#ui", '<span style="background-color:'. $this->hColor .';">$0</span>', $this->hText );	
		return $this->hText; 
	}
	
	public function highlightedExtendedMarkup($fulltext, $highlight) {
		$text = @preg_replace("#\n|\r#", ' ', $fulltext);
		
		$matches = array();
		$highlight = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex
		
		if (!$highlight) {
			$text = Loader::helper('text')->shorten($fulltext, 180);
			if (strlen($fulltext) > 180) {
				$text . '&hellip;<wbr>';
			}
			return $text;
		}
		
		$regex = '([[:alnum:]|\'|\.|_|\s]{0,45})'. $highlight .'([[:alnum:]|\.|_|\s]{0,45})';
		preg_match_all("#$regex#ui", $text, $matches);
		
		if(!empty($matches[0])) {
			$body_length = 0;
			$body_string = array();
			foreach($matches[0] as $line) {
				$body_length += strlen($line);
				
				$r = $this->highlightedMarkup($line, $highlight);
				if ($r) {
					$body_string[] = $r;
				}
				if($body_length > 150)
					break;
			}
			if(!empty($body_string))
				return @implode("&hellip;<wbr>", $body_string);
{'fraction_non_alphanumeric': 0.20891514500537056, 'fraction_numerical': 0.022556390977443608, 'mean_word_length': 4.246478873239437, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6975064', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1295, 'n_words': 261}