]> git.mxchange.org Git - friendica-addons.git/blob - advancedcontentfilter/doc/advancedcontentfilter.md
updated examples for advanced content filter
[friendica-addons.git] / advancedcontentfilter / doc / advancedcontentfilter.md
1 <style>
2 .advancedcontentfilter-content-wrapper {
3         min-height: calc(100vh - 150px);
4     padding: 15px;
5     padding-bottom: 20px;
6     margin-bottom: 20px;
7     border: none;
8     /*background-color: #fff;*/
9     background-color: rgba(255,255,255,0.95);
10     border-radius: 4px;
11     position: relative;
12     /*overflow: hidden;*/
13     color: #555;
14     box-shadow: 0 0 3px #dadada;
15     -webkit-box-shadow: 0 0 3px #dadada;
16     -moz-box-shadow: 0 0 3px #dadada;
17 }
18 </style>
19
20 <a href="advancedcontentfilter">🔙 Back to Advanced Content Filter Settings</a>
21
22 # Advanced Content Filter Help
23
24 The advanced Content Filter uses Symfony's Expression Language.
25 This help page includes a summary of [the Symfony's Expression Language documentation page.](https://symfony.com/doc/current/components/expression_language/syntax.html)
26
27 ## Basics
28
29 The advanced content filter matches each post that is about to be displayed against each enabled rule you set.
30
31 A rule is a boolean expression that should return either `true` or `false` depending on post variables.
32
33 If the expression using a post variables returns `true`, the post will be collapsed and the matching rule name will be displayed above the collapsed content.
34
35 A post will be collapsed if at least one rule matches, but all matching rule names will be displayed above the collapsed content.
36
37 ## Examples
38
39
40
41 ## Expression Syntax
42
43 1. To block specific domains  `body matches "/\\.spiegel\\.de/"`
44 2. To block everything that contains the words `body matches "/Guten Morgen/"
45 3. To block every occurence of the word facebook with a space in front and after the word `body matches "//s facebook/s /"`
46 4. To colapse every post that contains more than 1 image `body matches "/(?:(?:(?:\\[url(?:=.*)?\\])?\\[img(?:=.*)?\\].*\\[\\/img\\]\\s*(?:\\[\\/url\\])?)\\s*){2}/"`
47
48
49
50 ### Supported Literals
51
52 - **strings** - single and double quotes (e.g. `'hello'`).
53 - **numbers** - e.g. `103`.
54 - **arrays** - using JSON-like notation (e.g. `[1, 2]`).
55 - **hashes** - using JSON-like notation (e.g. `{ foo: 'bar' }`).
56 - **booleans** - `true` and `false`.
57 - **null** - `null`.
58
59 A backslash (``\``) must be escaped by 2 backslashes (``\\``) in a string and 4 backslashes (``\\\\``) in a regex::
60
61 `"a\\b" matches "/^a\\\\b$/"`
62
63 Control characters (e.g. ``\n``) in expressions are replaced with whitespace. To avoid this, escape the sequence with a single backslash (e.g.  ``\\n``).
64
65 ### Supported Operators
66
67 The component comes with a lot of operators:
68
69 #### Arithmetic Operators
70
71 * ``+`` (addition)
72 * ``-`` (subtraction)
73 * ``*`` (multiplication)
74 * ``/`` (division)
75 * ``%`` (modulus)
76 * ``**`` (pow)
77
78 #### Bitwise Operators
79
80 * ``&`` (and)
81 * ``|`` (or)
82 * ``^`` (xor)
83
84 #### Comparison Operators
85
86 * ``==`` (equal)
87 * ``===`` (identical)
88 * ``!=`` (not equal)
89 * ``!==`` (not identical)
90 * ``<`` (less than)
91 * ``>`` (greater than)
92 * ``<=`` (less than or equal to)
93 * ``>=`` (greater than or equal to)
94 * ``matches`` (regex match)
95
96 To test if a string does *not* match a regex, use the logical ``not`` operator in combination with the ``matches`` operator:
97
98 `not ("foo" matches "/bar/")`
99
100 You must use parenthesis because the unary operator ``not`` has precedence over the binary operator ``matches``.
101
102 #### Logical Operators
103
104 * ``not`` or ``!``
105 * ``and`` or ``&&``
106 * ``or`` or ``||``
107
108 #### String Operators
109
110 * ``~`` (concatenation)
111
112 For example: ``firstName ~ " " ~ lastName``
113
114 #### Array Operators
115
116 * ``in`` (contain)
117 * ``not in`` (does not contain)
118
119 For example: ``user.group in ["human_resources", "marketing"]``
120
121 #### Numeric Operators
122
123 * ``..`` (range)
124
125 For example: ``user.age in 18..45``
126
127 #### Ternary Operators
128
129 * ``foo ? 'yes' : 'no'``
130 * ``foo ?: 'no'`` (equal to ``foo ? foo : 'no'``)
131 * ``foo ? 'yes'`` (equal to ``foo ? 'yes' : ''``)
132
133 ### Supported variables
134
135 Here are a sample of the available variables you can use in your expressions.
136 You can also retrieve the variables of a specific post by pasting its URL below the rule list.
137
138 <table class="table-bordered table-condensed table-striped">
139 <thead>
140         <tr>
141                 <th>Variable</th>
142                 <th>Type</th>
143                 <th>Sample Value</th>
144         </tr>
145 </thead>
146 <tbody>
147         <tr>
148                 <th>author_id</th>
149                 <td>number</td>
150                 <td>6</td>
151         </tr>
152         <tr>
153                 <th>author_link</th>
154                 <td>string</td>
155                 <td>https://friendica.mrpetovan.com/profile/hypolite</td>
156         </tr>
157         <tr>
158                 <th>author_name</th>
159                 <td>string</td>
160                 <td>Hypolite Petovan</td>
161         </tr>
162         <tr>
163                 <th>author_avatar</th>
164                 <td>string</td>
165                 <td>https://friendica.mrpetovan.com/photo/41084997915a94a8c83cc39708500207-5.png</td>
166         </tr>
167         <tr>
168                 <th>owner_id</th>
169                 <td>number</td>
170                 <td>6</td>
171         </tr>
172         <tr>
173                 <th>owner_link</th>
174                 <td>string</td>
175                 <td>https://friendica.mrpetovan.com/profile/hypolite</td>
176         </tr>
177         <tr>
178                 <th>owner_name</th>
179                 <td>string</td>
180                 <td>Hypolite Petovan</td>
181         </tr>
182         <tr>
183                 <th>owner_avatar</th>
184                 <td>string</td>
185                 <td>https://friendica.mrpetovan.com/photo/41084997915a94a8c83cc39708500207-5.png</td>
186         </tr>
187         <tr>
188                 <th>contact_id</th>
189                 <td>number</td>
190                 <td>1</td>
191         </tr>
192         <tr>
193                 <th>uid</th>
194                 <td>number</td>
195                 <td>1</td>
196         </tr>
197         <tr>
198                 <th>id</th>
199                 <td>number</td>
200                 <td>791875</td>
201         </tr>
202         <tr>
203                 <th>parent</th>
204                 <td>number</td>
205                 <td>791875</td>
206         </tr>
207         <tr>
208                 <th>uri</th>
209                 <td>string</td>
210                 <td>urn:X-dfrn:friendica.mrpetovan.com:1:twit:978740198937907200</td>
211         </tr>
212         <tr>
213                 <th>thr_parent</th>
214                 <td>string</td>
215                 <td>urn:X-dfrn:friendica.mrpetovan.com:1:twit:978740198937907200</td>
216         </tr>
217         <tr>
218                 <th>parent_uri</th>
219                 <td>string</td>
220                 <td>urn:X-dfrn:friendica.mrpetovan.com:1:twit:978740198937907200</td>
221         </tr>
222         <tr>
223                 <th>content_warning</th>
224                 <td>string</td>
225                 <td></td>
226         </tr>
227         <tr>
228                 <th>commented</th>
229                 <td>date</td>
230                 <td>2018-03-27 21:10:18</td>
231         </tr>
232         <tr>
233                 <th>created</th>
234                 <td>date</td>
235                 <td>2018-03-27 21:10:18</td>
236         </tr>
237         <tr>
238                 <th>edited</th>
239                 <td>date</td>
240                 <td>2018-03-27 21:10:18</td>
241         </tr>
242         <tr>
243                 <th>received</th>
244                 <td>date</td>
245                 <td>2018-03-27 21:10:18</td>
246         </tr>
247         <tr>
248                 <th>verb</th>
249                 <td>string</td>
250                 <td>http://activitystrea.ms/schema/1.0/post</td>
251         </tr>
252         <tr>
253                 <th>object_type</th>
254                 <td>string</td>
255                 <td>http://activitystrea.ms/schema/1.0/bookmark</td>
256         </tr>
257         <tr>
258                 <th>postopts</th>
259                 <td>string</td>
260                 <td>twitter&lang=pidgin;0.24032407407407:english;0.225:french;0.18055555555556</td>
261         </tr>
262         <tr>
263                 <th>plink</th>
264                 <td>string</td>
265                 <td>https://friendica.mrpetovan.com/display/735a2029995abab33a5c006052376776</td>
266         </tr>
267         <tr>
268                 <th>guid</th>
269                 <td>string</td>
270                 <td>735a2029995abab33a5c006052376776</td>
271         </tr>
272         <tr>
273                 <th>wall</th>
274                 <td>boolean</td>
275                 <td>1</td>
276         </tr>
277         <tr>
278                 <th>private</th>
279                 <td>boolean</td>
280                 <td>0</td>
281         </tr>
282         <tr>
283                 <th>starred</th>
284                 <td>boolean</td>
285                 <td>0</td>
286         </tr>
287         <tr>
288                 <th>title</th>
289                 <td>string</td>
290                 <td></td>
291         </tr>
292         <tr>
293                 <th>body</th>
294                 <td>string</td>
295                 <td>Over-compensation #[url=https://friendica.mrpetovan.com/search?tag=Street]Street[/url] #[url=https://friendica.mrpetovan.com/search?tag=Night]Night[/url] #[url=https://friendica.mrpetovan.com/search?tag=CarLights]CarLights[/url] #[url=https://friendica.mrpetovan.com/search?tag=Jeep]Jeep[/url] #[url=https://friendica.mrpetovan.com/search?tag=NoPeople]NoPeople[/url] #[url=https://friendica.mrpetovan.com/search?tag=Close]Close[/url]-up
296         [attachment type='link' url='https://www.eyeem.com/p/120800309' title='Over-compensation Street Night Car Lights Jeep No | EyeEm' image='https://cdn.eyeem.com/thumb/b2f019738cbeef06e2f8c9517c6286a8adcd3a00-1522184820641/640/480']Photo by @[url=https://twitter.com/MrPetovan]MrPetovan[/url][/attachment]</td>
297         </tr>
298         <tr>
299                 <th>file</th>
300                 <td>string</td>
301                 <td></td>
302         </tr>
303         <tr>
304                 <th>event_id</th>
305                 <td>number</td>
306                 <td>null
307         <tr>
308                 <th>location</th>
309                 <td>string</td>
310                 <td></td>
311         </tr>
312         <tr>
313                 <th>coord</th>
314                 <td>string</td>
315                 <td></td>
316         </tr>
317         <tr>
318                 <th>app</th>
319                 <td>string</td>
320                 <td>EyeEm</td>
321         </tr>
322         <tr>
323                 <th>attach</th>
324                 <td>string</td>
325                 <td></td>
326         </tr>
327         <tr>
328                 <th>rendered_hash</th>
329                 <td>string</td>
330                 <td>b70abdea8b362dc5dcf63e1b2836ad89</td>
331         </tr>
332         <tr>
333                 <th>rendered_html</th>
334                 <td>string</td>
335                 <td>
336                         Over-compensation #&lt;a href="https://friendica.mrpetovan.com/search?tag=Street" class="tag" title="Street"&gt;Street&lt;/a&gt; #&lt;a href="https://friendica.mrpetovan.com/search?tag=Night" class="tag" title="Night"&gt;Night&lt;/a&gt; #&lt;a href="https://friendica.mrpetovan.com/search?tag=CarLights" class="tag" title="CarLights"&gt;CarLights&lt;/a&gt; #&lt;a href="https://friendica.mrpetovan.com/search?tag=Jeep" class="tag" title="Jeep"&gt;Jeep&lt;/a&gt; #&lt;a href="https://friendica.mrpetovan.com/search?tag=NoPeople" class="tag" title="NoPeople"&gt;NoPeople&lt;/a&gt; #&lt;a href="https://friendica.mrpetovan.com/search?tag=Close" class="tag" title="Close"&gt;Close&lt;/a&gt;-up &lt;div class="type-link"&gt;&lt;a href="https://www.eyeem.com/p/120800309" target="_blank"&gt;&lt;img src="https://friendica.mrpetovan.com/proxy/bb/aHR0cHM6Ly9jZG4uZXllZW0uY29tL3RodW1iL2IyZjAxOTczOGNiZWVmMDZlMmY4Yzk1MTdjNjI4NmE4YWRjZDNhMDAtMTUyMjE4NDgyMDY0MS82NDAvNDgw" alt="" title="Over-compensation Street Night Car Lights Jeep No | EyeEm" class="attachment-image"&gt;&lt;/a&gt;&lt;br&gt;&lt;h4&gt;&lt;a href="https://www.eyeem.com/p/120800309"&gt;Over-compensation Street Night Car Lights Jeep No | EyeEm&lt;/a&gt;&lt;/h4&gt;&lt;blockquote&gt;Photo by @&lt;a href="https://twitter.com/MrPetovan" class="userinfo mention" title="MrPetovan"&gt;MrPetovan&lt;/a&gt;&lt;/blockquote&gt;&lt;sup&gt;&lt;a href="https://www.eyeem.com/p/120800309"&gt;www.eyeem.com&lt;/a&gt;&lt;/sup&gt;&lt;/div&gt;
337                 </td>
338         </tr>
339         <tr>
340                 <th>object</th>
341                 <td>string</td>
342                 <td>{"created_at":"Tue Mar 27 21:07:02 +0000 2018","id":978740198937907200,"id_str":"978740198937907200","full_text":"Over-compensation #Street #Night #CarLights #Jeep #NoPeople #Close-up https:\/\/t.co\/7w4ua13QA7","truncated":false,"display_text_range":[0,93],"entities":{"hashtags":[{"text":"Street","indices":[18,25]},{"text":"Night","indices":[26,32]},{"text":"CarLights","indices":[33,43]},{"text":"Jeep","indices":[44,49]},{"text":"NoPeople","indices":[50,59]},{"text":"Close","indices":[60,66]}],"symbols":[],"user_mentions":[],"urls":[{"url":"https:\/\/t.co\/7w4ua13QA7","expanded_url":"http:\/\/EyeEm.com\/p\/120800309","display_url":"EyeEm.com\/p\/120800309","indices":[70,93]}]},"source":"&lt;a href=\"http:\/\/www.eyeem.com\" rel=\"nofollow\"&gt;EyeEm&lt;\/a&gt;","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":403748896,"id_str":"403748896","name":"\ud83d\udc30yp\ud83e\udd5ali\u271d\ufe0fe Pet\ud83e\udd5avan","screen_name":"MrPetovan","location":"NYC","description":"White male form of milquetoast. Avatar by @DearMsDear inspired by @TSG_LAB.\n\nFriendica\/Diaspora\/Mastodon: hypolite@friendica.mrpetovan.com","url":"https:\/\/t.co\/PcARi5OhQO","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/PcARi5OhQO","expanded_url":"https:\/\/mrpetovan.com","display_url":"mrpetovan.com","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":182,"friends_count":146,"listed_count":15,"created_at":"Wed Nov 02 23:13:14 +0000 2011","favourites_count":45826,"utc_offset":-14400,"time_zone":"Eastern Time (US &amp; Canada)","geo_enabled":false,"verified":false,"statuses_count":15554,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/370213187\/fond_twitter_mrpetovan.png","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/370213187\/fond_twitter_mrpetovan.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/968008546322395136\/6qLCiu0o_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/968008546322395136\/6qLCiu0o_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/403748896\/1464321684","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"000000","profile_use_background_image":true,"has_extended_profile":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}</td>
343         </tr>
344         <tr>
345                 <th>allow_cid</th>
346                 <td>string</td>
347                 <td></td>
348         </tr>
349         <tr>
350                 <th>allow_gid</th>
351                 <td>string</td>
352                 <td></td>
353         </tr>
354         <tr>
355                 <th>deny_cid</th>
356                 <td>string</td>
357                 <td></td>
358         </tr>
359         <tr>
360                 <th>deny_gid</th>
361                 <td>string</td>
362                 <td></td>
363         </tr>
364         <tr>
365                 <th>item_id</th>
366                 <td>number</td>
367                 <td>791875</td>
368         </tr>
369         <tr>
370                 <th>item_network</th>
371                 <td>string</td>
372                 <td>dfrn</td>
373         </tr>
374         <tr>
375                 <th>author_thumb</th>
376                 <td>string</td>
377                 <td>https://friendica.mrpetovan.com/photo/0cb3d7231eb751139d7d309c7c686c49-5.png?ts=1522941604</td>
378         </tr>
379         <tr>
380                 <th>owner_thumb</th>
381                 <td>string</td>
382                 <td>https://friendica.mrpetovan.com/photo/0cb3d7231eb751139d7d309c7c686c49-5.png?ts=1522941604</td>
383         </tr>
384         <tr>
385                 <th>network</th>
386                 <td>string</td>
387                 <td></td>
388         </tr>
389         <tr>
390                 <th>url</th>
391                 <td>string</td>
392                 <td>https://friendica.mrpetovan.com/profile/hypolite</td>
393         </tr>
394         <tr>
395                 <th>name</th>
396                 <td>string</td>
397                 <td>Hypolite Petovan</td>
398         </tr>
399         <tr>
400                 <th>writable</th>
401                 <td>boolean</td>
402                 <td>0</td>
403         </tr>
404         <tr>
405                 <th>self</th>
406                 <td>boolean</td>
407                 <td>1</td>
408         </tr>
409         <tr>
410                 <th>cid</th>
411                 <td>number</td>
412                 <td>1</td>
413         </tr>
414         <tr>
415                 <th>alias</th>
416                 <td>string</td>
417                 <td></td>
418         </tr>
419         <tr>
420                 <th>event_created</th>
421                 <td>date</td>
422                 <td>null</td>
423         </tr>
424         <tr>
425                 <th>event_edited</th>
426                 <td>date</td>
427                 <td>null</td>
428         </tr>
429         <tr>
430                 <th>event_start</th>
431                 <td>date</td>
432                 <td>null</td>
433         </tr>
434         <tr>
435                 <th>event_finish</th>
436                 <td>date</td>
437                 <td>null</td>
438         </tr>
439         <tr>
440                 <th>event_summary</th>
441                 <td>string</td>
442                 <td>null</td>
443         </tr>
444         <tr>
445                 <th>event_desc</th>
446                 <td>string</td>
447                 <td>null</td>
448         </tr>
449         <tr>
450                 <th>event_location</th>
451                 <td>string</td>
452                 <td>null</td>
453         </tr>
454         <tr>
455                 <th>event_type</th>
456                 <td>string</td>
457                 <td>null</td>
458         </tr>
459         <tr>
460                 <th>event_nofinish</th>
461                 <td>string</td>
462                 <td>null</td>
463         </tr>
464         <tr>
465                 <th>event_adjust</th>
466                 <td>boolean</td>
467                 <td>null</td>
468         </tr>
469         <tr>
470                 <th>event_ignore</th>
471                 <td>boolean</td>
472                 <td>null</td>
473         </tr>
474         <tr>
475                 <th>pagedrop</th>
476                 <td>string</td>
477                 <td>true</td>
478         </tr>
479         <tr>
480                 <th>tags</th>
481                 <td>list</td>
482                 <td>
483                         <ol start="0">
484                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Street" target="_blank"&gt;street&lt;/a&gt;</li>
485                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Night" target="_blank"&gt;night&lt;/a&gt;</li>
486                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=CarLights" target="_blank"&gt;carlights&lt;/a&gt;</li>
487                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Jeep" target="_blank"&gt;jeep&lt;/a&gt;</li>
488                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=NoPeople" target="_blank"&gt;nopeople&lt;/a&gt;</li>
489                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Close" target="_blank"&gt;close&lt;/a&gt;</li>
490                                 <li>@&lt;a href="https://twitter.com/MrPetovan" target="_blank"&gt;mrpetovan&lt;/a&gt;</li>
491                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Close-up" target="_blank"&gt;close-up&lt;/a&gt;</li>
492                         </ol>
493                 </td>
494         </tr>
495         <tr>
496                 <th>hashtags</th>
497                 <td>list</td>
498                 <td>
499                         <ol start="0">
500                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Street" target="_blank"&gt;street&lt;/a&gt;</li>
501                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Night" target="_blank"&gt;night&lt;/a&gt;</li>
502                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=CarLights" target="_blank"&gt;carlights&lt;/a&gt;</li>
503                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Jeep" target="_blank"&gt;jeep&lt;/a&gt;</li>
504                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=NoPeople" target="_blank"&gt;nopeople&lt;/a&gt;</li>
505                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Close" target="_blank"&gt;close&lt;/a&gt;</li>
506                                 <li>#&lt;a href="https://friendica.mrpetovan.com/search?tag=Close-up" target="_blank"&gt;close-up&lt;/a&gt;</li>
507                         </ol>
508                 </td>
509         </tr>
510         <tr>
511                 <th>mentions</th>
512                 <td>string</td>
513                 <td>
514                         <ol start="0">
515                                 <li>@&lt;a href="https://twitter.com/MrPetovan" target="_blank"&gt;mrpetovan&lt;/a&gt;</li>
516                         </ol>
517                 </td>
518         </tr>
519 </tbody>
520 </table>