]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
2 // We need to accept raw SQL data in label queries, so not everything is escaped
3 // here, this is by design. If you don't like it, disable labels
4 // altogether with GLOBAL_ENABLE_LABELS = false
6 function module_pref_labels ( $link ) {
7 if (! GLOBAL_ENABLE_LABELS
) {
9 print "<p>Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.</p>" ;
13 $subop = $_GET [ "subop" ];
15 if ( $subop == "edit" ) {
17 $label_id = db_escape_string ( $_GET [ "id" ]);
19 $result = db_query ( $link , "SELECT sql_exp,description FROM ttrss_labels WHERE
20 owner_uid = " . $_SESSION [ "uid" ]. " AND id = ' $label_id ' ORDER by description" );
22 $line = db_fetch_assoc ( $result );
24 $sql_exp = htmlspecialchars ( db_unescape_string ( $line [ "sql_exp" ]));
25 $description = htmlspecialchars ( db_unescape_string ( $line [ "description" ]));
27 print "<div id= \" infoBoxTitle \" >Label editor</div>" ;
28 print "<div class= \" infoBoxContents \" >" ;
30 print "<form id= \" label_edit_form \" onsubmit='return false'>" ;
32 print "<input type= \" hidden \" name= \" op \" value= \" pref-labels \" >" ;
33 print "<input type= \" hidden \" name= \" id \" value= \" $label_id\" >" ;
34 print "<input type= \" hidden \" name= \" subop \" value= \" editSave \" >" ;
36 print "<table width='100%'>" ;
38 print "<tr><td>Caption:</td>
39 <td><input onkeypress= \" return filterCR(event, labelEditSave) \"
40 onkeyup= \" toggleSubmitNotEmpty(this, 'infobox_submit') \"
41 onchange= \" toggleSubmitNotEmpty(this, 'infobox_submit') \"
42 name= \" description \" class= \" iedit \" value= \" $description\" >" ;
46 print "<tr><td colspan= \" 2 \" >
47 <p>SQL Expression:</p>" ;
49 print "<textarea onkeyup= \" toggleSubmitNotEmpty(this, 'infobox_submit') \"
50 rows= \" 4 \" name= \" sql_exp \" class= \" iedit \" > $sql_exp </textarea>" ;
52 print "</td></tr></table>" ;
56 print "<div style= \" display : none \" id= \" label_test_result \" ></div>" ;
58 print "<div align='right'>" ;
60 $is_disabled = ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], 'Opera' ) !== FALSE ) ?
"disabled" : "" ;
62 print "<input $is_disabled type= \" submit \" onclick= \" return labelTest() \" value= \" Test \" >
65 print "<input type= \" submit \"
67 class= \" button \" onclick= \" return labelEditSave() \"
70 print "<input class= \" button \"
71 type= \" submit \" onclick= \" return labelEditCancel() \"
79 if ( $subop == "test" ) {
81 $expr = db_unescape_string ( trim ( $_GET [ "expr" ]));
82 $descr = db_unescape_string ( trim ( $_GET [ "descr" ]));
89 $result = db_query ( $link ,
90 "SELECT count(ttrss_entries.id) AS num_matches
91 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
93 ttrss_user_entries.ref_id = ttrss_entries.id AND
94 ttrss_user_entries.feed_id = ttrss_feeds.id AND
95 ttrss_user_entries.owner_uid = " . $_SESSION [ "uid" ], false );
97 error_reporting ( DEFAULT_ERROR_LEVEL
);
100 print "<p>" . db_last_error ( $link ) . "</p>" ;
105 $num_matches = db_fetch_result ( $result , 0 , "num_matches" );;
107 if ( $num_matches > 0 ) {
109 if ( $num_matches > 10 ) {
110 $showing_msg = ", showing first 10" ;
113 print "<p>Query returned <b> $num_matches </b> matches $showing_msg :</p>" ;
115 $result = db_query ( $link ,
116 "SELECT ttrss_entries.title,
117 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
118 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
120 ttrss_user_entries.ref_id = ttrss_entries.id
121 AND ttrss_user_entries.feed_id = ttrss_feeds.id
122 AND ttrss_user_entries.owner_uid = " . $_SESSION [ "uid" ] . "
123 ORDER BY date_entered DESC LIMIT 10" , false );
125 print "<ul class= \" labelTestResults \" >" ;
129 while ( $line = db_fetch_assoc ( $result )) {
130 $row_class = toggleEvenOdd ( $row_class );
132 print "<li class= \" $row_class\" >" . $line [ "title" ].
133 " <span class= \" insensitive \" >(" . $line [ "feed_title" ]. ")</span></li>" ;
138 print "<p>Query didn't return any matches.</p>" ;
146 if ( $subop == "editSave" ) {
148 $sql_exp = trim ( $_GET [ "sql_exp" ]);
149 $descr = db_escape_string ( trim ( $_GET [ "description" ]));
150 $label_id = db_escape_string ( $_GET [ "id" ]);
152 $result = db_query ( $link , "UPDATE ttrss_labels SET
153 sql_exp = ' $sql_exp ',
154 description = ' $descr '
155 WHERE id = ' $label_id '" );
157 if ( db_affected_rows ( $link , $result ) != 0 ) {
158 print_notice ( T_sprintf ( "Saved label <b> %s </b>" , htmlspecialchars ( $descr )));
163 if ( $subop == "remove" ) {
165 if (! WEB_DEMO_MODE
) {
167 $ids = split ( "," , db_escape_string ( $_GET [ "ids" ]));
169 foreach ( $ids as $id ) {
170 db_query ( $link , "DELETE FROM ttrss_labels WHERE id = ' $id '" );
176 if ( $subop == "add" ) {
178 // no escaping is done here on purpose
179 $sql_exp = trim ( $_GET [ "sql_exp" ]);
180 $description = db_escape_string ( $_GET [ "description" ]);
182 if (! $sql_exp ||
! $description ) return ;
184 $result = db_query ( $link ,
185 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
186 VALUES (' $sql_exp ', ' $description ', '" . $_SESSION [ "uid" ]. "')" );
188 if ( db_affected_rows ( $link , $result ) != 0 ) {
189 print T_sprintf ( "Created label <b> %s </b>" , htmlspecialchars ( $description ));
195 set_pref ( $link , "_PREFS_ACTIVE_TAB" , "labelConfig" );
197 $sort = db_escape_string ( $_GET [ "sort" ]);
199 if (! $sort ||
$sort == "undefined" ) {
200 $sort = "description" ;
203 print "<a class='helpLinkPic' href= \" javascript:displayHelpInfobox(1) \" >
204 <img src='images/sign_quest.png'></a>" ;
206 print "<div class= \" prefGenericAddBox \" >" ;
208 print "<input type= \" submit \" class= \" button \"
209 id= \" label_create_btn \"
210 onclick= \" return displayDlg('quickAddLabel', false) \"
211 value= \" " . __ ( 'Create label' ). " \" ></div>" ;
213 $result = db_query ( $link , "SELECT
214 id,sql_exp,description
218 owner_uid = " . $_SESSION [ "uid" ]. "
221 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
223 if ( db_num_rows ( $result ) != 0 ) {
225 print "<p><table width= \" 100% \" cellspacing= \" 0 \"
226 class= \" prefLabelList \" id= \" prefLabelList \" >" ;
228 print "<tr><td class= \" selectPrompt \" colspan= \" 8 \" >
230 <a href= \" javascript:selectPrefRows('label', true) \" >" . __ ( 'All' ). "</a>,
231 <a href= \" javascript:selectPrefRows('label', false) \" >" . __ ( 'None' ). "</a>
234 print "<tr class= \" title \" >
235 <td width= \" 5% \" > </td>
236 <td width= \" 30% \" ><a href= \" javascript:updateLabelList('description') \" >" . __ ( 'Caption' ). "</a></td>
237 <td width= \"\" ><a href= \" javascript:updateLabelList('sql_exp') \" >" . __ ( 'SQL Expression' ). "</a>
243 while ( $line = db_fetch_assoc ( $result )) {
245 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
247 $label_id = $line [ "id" ];
248 $edit_label_id = $_GET [ "id" ];
250 if ( $subop == "edit" && $label_id != $edit_label_id ) {
254 $this_row_id = "id= \" LILRR- $label_id\" " ;
257 print "<tr class= \" $class\" $this_row_id >" ;
259 $line [ "sql_exp" ] = htmlspecialchars ( db_unescape_string ( $line [ "sql_exp" ]));
260 $line [ "description" ] = htmlspecialchars (
261 db_unescape_string ( $line [ "description" ]));
263 if (! $line [ "description" ]) $line [ "description" ] = "[No caption]" ;
265 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \" label \" );'
266 type= \" checkbox \" id= \" LICHK-" . $line [ "id" ]. " \" ></td>" ;
268 print "<td><a href= \" javascript:editLabel( $label_id ); \" >" .
269 $line [ "description" ] . "</td>" ;
271 print "<td><a href= \" javascript:editLabel( $label_id ); \" >" .
272 $line [ "sql_exp" ] . "</td>" ;
280 print "<tr><td colspan= \" 4 \" align= \" center \" >" . __ ( 'No labels defined.' ). "</td></tr>" ;
285 print "<p id= \" labelOpToolbar \" >" ;
287 print "<input type= \" submit \" class= \" button \" disabled= \" true \"
288 onclick= \" javascript:editSelectedLabel() \" value= \" " . __ ( 'Edit' ). " \" >
289 <input type= \" submit \" class= \" button \" disabled= \" true \"
290 onclick= \" javascript:removeSelectedLabels() \" value= \" " . __ ( 'Remove' ). " \" >" ;
293 print "<p>" . __ ( 'No labels defined.' ). "</p>" ;