| 1 |
<?php |
|---|
| 2 |
function module_pref_filters($link) { |
|---|
| 3 |
$subop = $_GET["subop"]; |
|---|
| 4 |
$quiet = $_GET["quiet"]; |
|---|
| 5 |
|
|---|
| 6 |
if ($subop == "edit") { |
|---|
| 7 |
|
|---|
| 8 |
$filter_id = db_escape_string($_GET["id"]); |
|---|
| 9 |
|
|---|
| 10 |
$result = db_query($link, |
|---|
| 11 |
"SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
|---|
| 12 |
|
|---|
| 13 |
$reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp")); |
|---|
| 14 |
$filter_type = db_fetch_result($result, 0, "filter_type"); |
|---|
| 15 |
$feed_id = db_fetch_result($result, 0, "feed_id"); |
|---|
| 16 |
$action_id = db_fetch_result($result, 0, "action_id"); |
|---|
| 17 |
$action_param = db_fetch_result($result, 0, "action_param"); |
|---|
| 18 |
|
|---|
| 19 |
$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled")); |
|---|
| 20 |
$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse")); |
|---|
| 21 |
|
|---|
| 22 |
print "<div id=\"infoBoxTitle\">".__('Filter Editor')."</div>"; |
|---|
| 23 |
print "<div class=\"infoBoxContents\">"; |
|---|
| 24 |
|
|---|
| 25 |
print "<form id=\"filter_edit_form\" onsubmit='return false'>"; |
|---|
| 26 |
|
|---|
| 27 |
print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">"; |
|---|
| 28 |
print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">"; |
|---|
| 29 |
print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">"; |
|---|
| 30 |
|
|---|
| 31 |
$result = db_query($link, "SELECT id,description |
|---|
| 32 |
FROM ttrss_filter_types ORDER BY description"); |
|---|
| 33 |
|
|---|
| 34 |
$filter_types = array(); |
|---|
| 35 |
|
|---|
| 36 |
while ($line = db_fetch_assoc($result)) { |
|---|
| 37 |
|
|---|
| 38 |
$filter_types[$line["id"]] = __($line["description"]); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
print "<div class=\"dlgSec\">".__("Match")."</div>"; |
|---|
| 42 |
|
|---|
| 43 |
print "<div class=\"dlgSecCont\">"; |
|---|
| 44 |
|
|---|
| 45 |
print "<input onkeypress=\"return filterCR(event, filterEditSave)\" |
|---|
| 46 |
onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" |
|---|
| 47 |
onchange=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" |
|---|
| 48 |
name=\"reg_exp\" size=\"30\" value=\"$reg_exp\">"; |
|---|
| 49 |
|
|---|
| 50 |
print " " . __("on field") . " "; |
|---|
| 51 |
print_select_hash("filter_type", $filter_type, $filter_types); |
|---|
| 52 |
|
|---|
| 53 |
print "<br/>"; |
|---|
| 54 |
|
|---|
| 55 |
print __("in") . " "; |
|---|
| 56 |
print_feed_select($link, "feed_id", $feed_id); |
|---|
| 57 |
|
|---|
| 58 |
print "</div>"; |
|---|
| 59 |
|
|---|
| 60 |
print "<div class=\"dlgSec\">".__("Perform Action")."</div>"; |
|---|
| 61 |
|
|---|
| 62 |
print "<div class=\"dlgSecCont\">"; |
|---|
| 63 |
|
|---|
| 64 |
print "<select name=\"action_id\" |
|---|
| 65 |
onchange=\"filterDlgCheckAction(this)\">"; |
|---|
| 66 |
|
|---|
| 67 |
$result = db_query($link, "SELECT id,description FROM ttrss_filter_actions |
|---|
| 68 |
ORDER BY name"); |
|---|
| 69 |
|
|---|
| 70 |
while ($line = db_fetch_assoc($result)) { |
|---|
| 71 |
$is_sel = ($line["id"] == $action_id) ? "selected" : ""; |
|---|
| 72 |
printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"])); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
print "</select>"; |
|---|
| 76 |
|
|---|
| 77 |
$param_hidden = ($action_id == 4 || $action_id == 6) ? "" : "display : none"; |
|---|
| 78 |
|
|---|
| 79 |
print "<span id=\"filter_dlg_param_box\" style=\"$param_hidden\">"; |
|---|
| 80 |
print " " . __("with parameters:") . " "; |
|---|
| 81 |
print "<input size=\"20\" |
|---|
| 82 |
onkeypress=\"return filterCR(event, filterEditSave)\" |
|---|
| 83 |
name=\"action_param\" value=\"$action_param\">"; |
|---|
| 84 |
print "</span>"; |
|---|
| 85 |
|
|---|
| 86 |
print " "; |
|---|
| 87 |
|
|---|
| 88 |
print "</div>"; |
|---|
| 89 |
|
|---|
| 90 |
print "<div class=\"dlgSec\">".__("Options")."</div>"; |
|---|
| 91 |
print "<div class=\"dlgSecCont\">"; |
|---|
| 92 |
|
|---|
| 93 |
print "<div style=\"line-height : 100%\">"; |
|---|
| 94 |
|
|---|
| 95 |
if ($enabled) { |
|---|
| 96 |
$checked = "checked"; |
|---|
| 97 |
} else { |
|---|
| 98 |
$checked = ""; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
print "<input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> |
|---|
| 102 |
<label for=\"enabled\">".__('Enabled')."</label><br/>"; |
|---|
| 103 |
|
|---|
| 104 |
if ($inverse) { |
|---|
| 105 |
$checked = "checked"; |
|---|
| 106 |
} else { |
|---|
| 107 |
$checked = ""; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> |
|---|
| 111 |
<label for=\"inverse\">".__('Inverse match')."</label>"; |
|---|
| 112 |
|
|---|
| 113 |
print "</div>"; |
|---|
| 114 |
print "</div>"; |
|---|
| 115 |
|
|---|
| 116 |
print "<div class=\"dlgButtons\">"; |
|---|
| 117 |
|
|---|
| 118 |
$reg_exp = htmlspecialchars($reg_exp, ENT_QUOTES); |
|---|
| 119 |
|
|---|
| 120 |
print "<div style=\"float : left\">"; |
|---|
| 121 |
print "<input type=\"submit\" |
|---|
| 122 |
class=\"button\" onclick='return removeFilter($filter_id, \"$reg_exp\")' |
|---|
| 123 |
value=\"".__('Remove')."\"> "; |
|---|
| 124 |
print "</div>"; |
|---|
| 125 |
|
|---|
| 126 |
print "<input type=\"submit\" |
|---|
| 127 |
id=\"infobox_submit\" |
|---|
| 128 |
class=\"button\" onclick=\"return filterEditSave()\" |
|---|
| 129 |
value=\"".__('Save')."\"> "; |
|---|
| 130 |
|
|---|
| 131 |
print "<input class=\"button\" |
|---|
| 132 |
type=\"submit\" onclick=\"return filterEditCancel()\" |
|---|
| 133 |
value=\"".__('Cancel')."\">"; |
|---|
| 134 |
|
|---|
| 135 |
print "</div>"; |
|---|
| 136 |
|
|---|
| 137 |
return; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
if ($subop == "editSave") { |
|---|
| 142 |
|
|---|
| 143 |
$reg_exp = db_escape_string(trim($_GET["reg_exp"])); |
|---|
| 144 |
$filter_type = db_escape_string(trim($_GET["filter_type"])); |
|---|
| 145 |
$filter_id = db_escape_string($_GET["id"]); |
|---|
| 146 |
$feed_id = db_escape_string($_GET["feed_id"]); |
|---|
| 147 |
$action_id = db_escape_string($_GET["action_id"]); |
|---|
| 148 |
$action_param = db_escape_string($_GET["action_param"]); |
|---|
| 149 |
$enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"])); |
|---|
| 150 |
$inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); |
|---|
| 151 |
|
|---|
| 152 |
if (!$feed_id) { |
|---|
| 153 |
$feed_id = 'NULL'; |
|---|
| 154 |
} else { |
|---|
| 155 |
$feed_id = sprintf("'%s'", db_escape_string($feed_id)); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
$result = db_query($link, "UPDATE ttrss_filters SET |
|---|
| 159 |
reg_exp = '$reg_exp', |
|---|
| 160 |
feed_id = $feed_id, |
|---|
| 161 |
action_id = '$action_id', |
|---|
| 162 |
filter_type = '$filter_type', |
|---|
| 163 |
enabled = $enabled, |
|---|
| 164 |
inverse = $inverse, |
|---|
| 165 |
action_param = '$action_param' |
|---|
| 166 |
WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
|---|
| 167 |
|
|---|
| 168 |
if (db_affected_rows($link, $result) != 0) { |
|---|
| 169 |
print_notice(T_sprintf("Saved filter <b>%s</b>", htmlspecialchars($reg_exp))); |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
if ($subop == "remove") { |
|---|
| 175 |
|
|---|
| 176 |
$ids = split(",", db_escape_string($_GET["ids"])); |
|---|
| 177 |
|
|---|
| 178 |
foreach ($ids as $id) { |
|---|
| 179 |
db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); |
|---|
| 180 |
} |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
if ($subop == "add") { |
|---|
| 184 |
|
|---|
| 185 |
$regexp = db_escape_string(trim($_GET["reg_exp"])); |
|---|
| 186 |
$filter_type = db_escape_string(trim($_GET["filter_type"])); |
|---|
| 187 |
$feed_id = db_escape_string($_GET["feed_id"]); |
|---|
| 188 |
$action_id = db_escape_string($_GET["action_id"]); |
|---|
| 189 |
$action_param = db_escape_string($_GET["action_param"]); |
|---|
| 190 |
|
|---|
| 191 |
$inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); |
|---|
| 192 |
|
|---|
| 193 |
if (!$regexp) return; |
|---|
| 194 |
|
|---|
| 195 |
if (!$feed_id) { |
|---|
| 196 |
$feed_id = 'NULL'; |
|---|
| 197 |
} else { |
|---|
| 198 |
$feed_id = sprintf("'%s'", db_escape_string($feed_id)); |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
$result = db_query($link, |
|---|
| 202 |
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, |
|---|
| 203 |
action_id, action_param, inverse) |
|---|
| 204 |
VALUES |
|---|
| 205 |
('$regexp', '$filter_type','".$_SESSION["uid"]."', |
|---|
| 206 |
$feed_id, '$action_id', '$action_param', $inverse)"); |
|---|
| 207 |
|
|---|
| 208 |
if (db_affected_rows($link, $result) != 0) { |
|---|
| 209 |
print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp)); |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
return; |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
if ($quiet) return; |
|---|
| 216 |
|
|---|
| 217 |
set_pref($link, "_PREFS_ACTIVE_TAB", "filterConfig"); |
|---|
| 218 |
|
|---|
| 219 |
$sort = db_escape_string($_GET["sort"]); |
|---|
| 220 |
|
|---|
| 221 |
if (!$sort || $sort == "undefined") { |
|---|
| 222 |
$sort = "reg_exp"; |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
$result = db_query($link, "SELECT id,description |
|---|
| 228 |
); |
|---|
| 229 |
|
|---|
| 230 |
$filter_types = array(); |
|---|
| 231 |
|
|---|
| 232 |
$line = db_fetch_assoc($result)) { |
|---|
| 233 |
|
|---|
| 234 |
$filter_types[$line["id"]] = $line["description"]; |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
$filter_search = db_escape_string($_GET["search"]); |
|---|
| 239 |
|
|---|
| 240 |
array_key_exists("search", $_GET)) { |
|---|
| 241 |
$_SESSION["prefs_filter_search"] = $filter_search; |
|---|
| 242 |
|
|---|
| 243 |
$filter_search = $_SESSION["prefs_filter_search"]; |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
"<div class=\"feedEditSearch\"> |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
.__('Search')."\"> |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
; |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
"<input type=\"submit\" |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
.__('Create filter')."\">"; |
|---|
| 263 |
|
|---|
| 264 |
" "; |
|---|
| 265 |
|
|---|
| 266 |
"<input type=\"submit\" |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
.__('Rescore articles')."\">"; |
|---|
| 270 |
|
|---|
| 271 |
$filter_search) { |
|---|
| 272 |
$filter_search = db_escape_string($filter_search); |
|---|
| 273 |
$filter_search_query = "( |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
; |
|---|
| 278 |
|
|---|
| 279 |
$filter_search_query = ""; |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
$result = db_query($link, "SELECT |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
.$_SESSION["uid"]." |
|---|
| 301 |
); |
|---|
| 302 |
|
|---|
| 303 |
db_num_rows($result) != 0) { |
|---|
| 304 |
|
|---|
| 305 |
"<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" |
|---|
| 306 |
; |
|---|
| 307 |
|
|---|
| 308 |
"<tr><td class=\"selectPrompt\" colspan=\"8\"> |
|---|
| 309 |
.__('Select:')." |
|---|
| 310 |
.__('All')."</a>, |
|---|
| 311 |
.__('None')."</a> |
|---|
| 312 |
; |
|---|
| 313 |
|
|---|
| 314 |
$lnum = 0; |
|---|
| 315 |
|
|---|
| 316 |
$cur_action_description = ""; |
|---|
| 317 |
|
|---|
| 318 |
$line = db_fetch_assoc($result)) { |
|---|
| 319 |
|
|---|
| 320 |
$class = ($lnum % 2) ? "even" : "odd"; |
|---|
| 321 |
|
|---|
| 322 |
$filter_id = $line["id"]; |
|---|
| 323 |
$edit_filter_id = $_GET["id"]; |
|---|
| 324 |
|
|---|
| 325 |
$enabled = sql_bool_to_bool($line["enabled"]); |
|---|
| 326 |
$inverse = sql_bool_to_bool($line["inverse"]); |
|---|
| 327 |
|
|---|
| 328 |
$subop == "edit" && $filter_id != $edit_filter_id) { |
|---|
| 329 |
$class .= "Grayed"; |
|---|
| 330 |
$this_row_id = ""; |
|---|
| 331 |
|
|---|
| 332 |
$this_row_id = "id=\"FILRR-$filter_id\""; |
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
$line["filter_type_descr"] = __($line["filter_type_descr"]); |
|---|
| 336 |
$line["action_description"] = __($line["action_description"]); |
|---|
| 337 |
|
|---|
| 338 |
$line["action_description"] != $cur_action_description) { |
|---|
| 339 |
$cur_action_description = $line["action_description"]; |
|---|
| 340 |
|
|---|
| 341 |
"<tr><td class='filterEditCat' colspan='6'>$cur_action_description</td></tr>"; |
|---|
| 342 |
|
|---|
| 343 |
"<tr class=\"title\"> |
|---|
| 344 |
|
|---|
| 345 |
.__('Filter expression')."</a></td> |
|---|
| 346 |
.__('Feed')."</a></td> |
|---|
| 347 |
.__('Match')."</a></td> |
|---|
| 348 |
.__('Action')."</a></td> --> |
|---|
| 349 |
.__('Params')."</a></td>"; |
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
"<tr class=\"$class\" $this_row_id>"; |
|---|
| 354 |
|
|---|
| 355 |
$line["reg_exp"] = htmlspecialchars($line["reg_exp"]); |
|---|
| 356 |
|
|---|
| 357 |
$line["feed_title"]) $line["feed_title"] = __("All feeds"); |
|---|
| 358 |
|
|---|
| 359 |
$line["action_param"]) { |
|---|
| 360 |
$line["action_param"] = "—"; |
|---|
| 361 |
$line["action_name"] == "score") { |
|---|
| 362 |
|
|---|
| 363 |
$score_pic = get_score_pic($line["action_param"]); |
|---|
| 364 |
|
|---|
| 365 |
$score_pic = "<img class='hlScorePic' src=\"images/$score_pic\">"; |
|---|
| 366 |
|
|---|
| 367 |
$line["action_param"] = "$score_pic " . $line["action_param"]; |
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
$line["feed_title"] = htmlspecialchars($line["feed_title"]); |
|---|
| 372 |
|
|---|
| 373 |
"<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");' |
|---|
| 374 |
.$line["id"]."\"></td>"; |
|---|
| 375 |
|
|---|
| 376 |
$enabled) { |
|---|
| 377 |
$line["reg_exp"] = "<span class=\"insensitive\">" . |
|---|
| 378 |
$line["reg_exp"] . " " . __("(Disabled)")."</span>"; |
|---|
| 379 |
$line["feed_title"] = "<span class=\"insensitive\">" . |
|---|
| 380 |
$line["feed_title"] . "</span>"; |
|---|
| 381 |
$line["filter_type_descr"] = "<span class=\"insensitive\">" . |
|---|
| 382 |
$line["filter_type_descr"] . "</span>"; |
|---|
| 383 |
$line["action_description"] = "<span class=\"insensitive\">" . |
|---|
| 384 |
$line["action_description"] . "</span>"; |
|---|
| 385 |
$line["action_param"] = "<span class=\"insensitive\">" . |
|---|
| 386 |
$line["action_param"] . "</span>"; |
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
$onclick = "onclick='editFilter($filter_id)' title='".__('Click to edit')."'"; |
|---|
| 390 |
|
|---|
| 391 |
"<td $onclick>" . $line["reg_exp"] . "</td>"; |
|---|
| 392 |
"<td $onclick>" . $line["feed_title"] . "</td>"; |
|---|
| 393 |
|
|---|
| 394 |
$inverse_label = ""; |
|---|
| 395 |
|
|---|
| 396 |
$inverse) { |
|---|
| 397 |
$inverse_label = " <span class='insensitive'>".__('(Inverse)')."</span>"; |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
"<td $onclick>" . $line["filter_type_descr"] . "$inverse_label</td>"; |
|---|
| 401 |
"<td $onclick>" . $line["action_param"] . "</td>"; |
|---|
| 402 |
|
|---|
| 403 |
"</tr>"; |
|---|
| 404 |
|
|---|
| 405 |
$lnum; |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
"</table>"; |
|---|
| 409 |
|
|---|
| 410 |
"<p id=\"filterOpToolbar\">"; |
|---|
| 411 |
|
|---|
| 412 |
"<input type=\"submit\" class=\"button\" disabled=\"true\" |
|---|
| 413 |
.__('Edit')."\"> |
|---|
| 414 |
|
|---|
| 415 |
.__('Remove')."\">"; |
|---|
| 416 |
|
|---|
| 417 |
"</p>"; |
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
"<p>"; |
|---|
| 422 |
$filter_search) { |
|---|
| 423 |
__('No filters defined.'); |
|---|
| 424 |
|
|---|
| 425 |
__('No matching filters found.'); |
|---|
| 426 |
|
|---|
| 427 |
"</p>"; |
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
?> |
|---|
| 432 |
|
|---|