<commit_before><?php
	function module_pref_filters($link) {
		$subop = $_REQUEST["subop"];
		$quiet = $_REQUEST["quiet"];

		if ($subop == "getfiltertree") {
			$root = array();
			$root['id'] = 'root';
			$root['name'] = __('Filters');
			$root['items'] = array();

			$result = db_query($link, "SELECT 
					ttrss_filters.id AS id,reg_exp,
					ttrss_filter_types.name AS filter_type_name,
					ttrss_filter_types.description AS filter_type_descr,
					enabled,
					inverse,
					feed_id,
					action_id,
					filter_param,
					filter_type,
					ttrss_filter_actions.description AS action_description,
					ttrss_feeds.title AS feed_title,
					ttrss_filter_actions.name AS action_name,
					ttrss_filters.action_param AS action_param
				FROM 
					ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
						ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
				WHERE
					filter_type = ttrss_filter_types.id AND
					ttrss_filter_actions.id = action_id AND
					ttrss_filters.owner_uid = ".$_SESSION["uid"]."
				ORDER by action_description, reg_exp");

			$cat = false;
			$cur_action_description = "";

			while ($line = db_fetch_assoc($result)) {
				if ($cur_action_description != $line['action_description']) {

					if ($cat)
						array_push($root['items'], $cat);

					$cat = array();
					$cat['id'] = 'ACTION:' . $line['action_id'];
					$cat['name'] = $line['action_description'];
					$cat['items'] = array();

					$cur_action_description = $line['action_description'];
				}

				if (array_search($line["action_name"], 
					array("score", "tag", "label")) === false) {

						$line["action_param"] = '';
				} else {
					if ($line['action_name'] == 'label') {

						$tmp_result = db_query($link, "SELECT fg_color, bg_color
							FROM ttrss_labels2 WHERE caption = '".
								db_escape_string($line["action_param"])."' AND
								owner_uid = " . $_SESSION["uid"]);

						if (db_num_rows($tmp_result) != 0) {
							$fg_color = db_fetch_result($tmp_result, 0, "fg_color");
							$bg_color = db_fetch_result($tmp_result, 0, "bg_color");

							$tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>&alpha;</span> " . $line['action_param'];

							$line['action_param'] = $tmp;
						}
					}
				}

				$filter = array();
				$filter['id'] = 'FILTER:' . $line['id'];
				$filter['bare_id'] = $line['id'];
				$filter['name'] = $line['reg_exp'];
				$filter['type'] = $line['filter_type'];
				$filter['enabled'] = sql_bool_to_bool($line['enabled']);
				$filter['param'] = $line['action_param'];
				$filter['inverse'] = sql_bool_to_bool($line['inverse']);
				$filter['checkbox'] = false;

				if ($line['feed_id'])
					$filter['feed'] = $line['feed_title']; 

				array_push($cat['items'], $filter);
			}

			array_push($root['items'], $cat);

			$fl = array();
			$fl['identifier'] = 'id';
			$fl['label'] = 'name';
			$fl['items'] = array($root);

			print json_encode($fl);
			return;
		}

		if ($subop == "edit") {

			$filter_id = db_escape_string($_REQUEST["id"]);

			$result = db_query($link, 
				"SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);

			$reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
			$filter_type = db_fetch_result($result, 0, "filter_type");
			$feed_id = db_fetch_result($result, 0, "feed_id");
			$action_id = db_fetch_result($result, 0, "action_id");
			$action_param = db_fetch_result($result, 0, "action_param");
			$filter_param = db_fetch_result($result, 0, "filter_param");

			$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
			$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));

			print "<form id=\"filter_edit_form\" onsubmit='return false'>";<commit_msg>pref-filters: fix malformed JSON when there are no filters defined<commit_after><?php
	function module_pref_filters($link) {
		$subop = $_REQUEST["subop"];
		$quiet = $_REQUEST["quiet"];

		if ($subop == "getfiltertree") {
			$root = array();
			$root['id'] = 'root';
			$root['name'] = __('Filters');
			$root['items'] = array();

			$result = db_query($link, "SELECT 
					ttrss_filters.id AS id,reg_exp,
					ttrss_filter_types.name AS filter_type_name,
					ttrss_filter_types.description AS filter_type_descr,
					enabled,
					inverse,
					feed_id,
					action_id,
					filter_param,
					filter_type,
					ttrss_filter_actions.description AS action_description,
					ttrss_feeds.title AS feed_title,
					ttrss_filter_actions.name AS action_name,
					ttrss_filters.action_param AS action_param
				FROM 
					ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
						ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
				WHERE
					filter_type = ttrss_filter_types.id AND
					ttrss_filter_actions.id = action_id AND
					ttrss_filters.owner_uid = ".$_SESSION["uid"]."
				ORDER by action_description, reg_exp");

			$cat = false;
			$cur_action_description = "";

			if (db_num_rows($result) > 0) {

				while ($line = db_fetch_assoc($result)) {
					if ($cur_action_description != $line['action_description']) {
	
						if ($cat)
							array_push($root['items'], $cat);
	
						$cat = array();
						$cat['id'] = 'ACTION:' . $line['action_id'];
						$cat['name'] = $line['action_description'];
						$cat['items'] = array();
	
						$cur_action_description = $line['action_description'];
					}
	
					if (array_search($line["action_name"], 
						array("score", "tag", "label")) === false) {
	
							$line["action_param"] = '';
					} else {
						if ($line['action_name'] == 'label') {
	
							$tmp_result = db_query($link, "SELECT fg_color, bg_color
								FROM ttrss_labels2 WHERE caption = '".
									db_escape_string($line["action_param"])."' AND
									owner_uid = " . $_SESSION["uid"]);
	
							if (db_num_rows($tmp_result) != 0) {
								$fg_color = db_fetch_result($tmp_result, 0, "fg_color");
								$bg_color = db_fetch_result($tmp_result, 0, "bg_color");
	
								$tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>&alpha;</span> " . $line['action_param'];
	
								$line['action_param'] = $tmp;
							}
						}
					}
	
					$filter = array();
					$filter['id'] = 'FILTER:' . $line['id'];
					$filter['bare_id'] = $line['id'];
					$filter['name'] = $line['reg_exp'];
					$filter['type'] = $line['filter_type'];
					$filter['enabled'] = sql_bool_to_bool($line['enabled']);
					$filter['param'] = $line['action_param'];
					$filter['inverse'] = sql_bool_to_bool($line['inverse']);
					$filter['checkbox'] = false;
	
					if ($line['feed_id'])
						$filter['feed'] = $line['feed_title']; 
	
					array_push($cat['items'], $filter);
				}
	
				array_push($root['items'], $cat);
			}

			$fl = array();
			$fl['identifier'] = 'id';
			$fl['label'] = 'name';
			$fl['items'] = array($root);

			print json_encode($fl);
			return;
		}

		if ($subop == "edit") {

			$filter_id = db_escape_string($_REQUEST["id"]);

			$result = db_query($link, 
				"SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);

			$reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
			$filter_type = db_fetch_result($result, 0, "filter_type");
			$feed_id = db_fetch_result($result, 0, "feed_id");
			$action_id = db_fetch_result($result, 0, "action_id");
			$action_param = db_fetch_result($result, 0, "action_param");
			$filter_param = db_fetch_result($result, 0, "filter_param");

			$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
			$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));

			print "<form id=\"filter_edit_form\" onsubmit='return false'>";
{'fraction_non_alphanumeric': 0.17723156532988357, 'fraction_numerical': 0.003234152652005175, 'mean_word_length': 3.7899628252788102, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': '4478229', 'n_tokens_mistral': 3417, 'n_tokens_neox': 2677, 'n_words': 469}