]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-instances.php
2 function module_pref_instances ( $link ) {
4 $subop = $_REQUEST [ 'subop' ];
6 if ( $subop == "remove" ) {
7 $ids = db_escape_string ( $_REQUEST [ 'ids' ]);
9 db_query ( $link , "DELETE FROM ttrss_linked_instances WHERE
15 if ( $subop == "add" ) {
16 $id = db_escape_string ( $_REQUEST [ "id" ]);
17 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
18 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
20 db_query ( $link , "BEGIN" );
22 $result = db_query ( $link , "SELECT id FROM ttrss_linked_instances
23 WHERE access_url = ' $access_url '" );
25 if ( db_num_rows ( $result ) == 0 ) {
26 db_query ( $link , "INSERT INTO ttrss_linked_instances
27 (access_url, access_key, last_connected, last_status_in, last_status_out)
29 (' $access_url ', ' $access_key ', '1970-01-01', -1, -1)" );
33 db_query ( $link , "COMMIT" );
38 if ( $subop == "edit" ) {
40 $id = db_escape_string ( $_REQUEST [ "id" ]);
42 $result = db_query ( $link , "SELECT * FROM ttrss_linked_instances WHERE
45 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" id \" value= \" $id\" >" ;
46 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-instances \" >" ;
47 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" subop \" value= \" editSave \" >" ;
49 print "<div class= \" dlgSec \" >" . __ ( "Instance" ). "</div>" ;
51 print "<div class= \" dlgSecCont \" >" ;
55 $access_url = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_url" ));
57 print __ ( "URL:" ) . " " ;
59 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
60 placeHolder= \" " . __ ( "Instance URL" ). " \"
61 regExp='^(http|https)://.*'
62 style= \" font-size : 16px; width: 20em \" name= \" access_url \"
63 value= \" $access_url\" >" ;
67 $access_key = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_key" ));
71 print __ ( "Access key:" ) . " " ;
73 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
74 placeHolder= \" " . __ ( "Access key" ). " \" regExp='\w{40}'
75 style= \" width: 20em \" name= \" access_key \" id= \" instance_edit_key \"
76 value= \" $access_key\" >" ;
78 print "<p class='insensitive'>" . __ ( "Use one access key for both linked instances." );
82 print "<div class= \" dlgButtons \" >
83 <div style='float : left'>
84 <button dojoType= \" dijit.form.Button \"
85 onclick= \" return dijit.byId('instanceEditDlg').regenKey() \" >" .
86 __ ( 'Generate new key' ). "</button>
88 <button dojoType= \" dijit.form.Button \"
89 onclick= \" return dijit.byId('instanceEditDlg').execute() \" >" .
91 <button dojoType= \" dijit.form.Button \"
92 onclick= \" return dijit.byId('instanceEditDlg').hide() \"\" >" .
93 __ ( 'Cancel' ). "</button></div>" ;
98 if ( $subop == "editSave" ) {
99 $id = db_escape_string ( $_REQUEST [ "id" ]);
100 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
101 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
103 db_query ( $link , "UPDATE ttrss_linked_instances SET
104 access_key = ' $access_key ', access_url = ' $access_url ',
105 last_connected = '1970-01-01'
111 print "<div id= \" pref-instance-wrap \" dojoType= \" dijit.layout.BorderContainer \" gutters= \" false \" >" ;
112 print "<div id= \" pref-instance-header \" dojoType= \" dijit.layout.ContentPane \" region= \" top \" >" ;
114 print "<div id= \" pref-instance-toolbar \" dojoType= \" dijit.Toolbar \" >" ;
116 $sort = db_escape_string ( $_REQUEST [ "sort" ]);
118 if (! $sort ||
$sort == "undefined" ) {
119 $sort = "access_url" ;
122 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
123 "<span>" . __ ( 'Select' ). "</span>" ;
124 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
125 print "<div onclick= \" selectTableRows('prefInstanceList', 'all') \"
126 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
127 print "<div onclick= \" selectTableRows('prefInstanceList', 'none') \"
128 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
129 print "</div></div>" ;
131 print "<button dojoType= \" dijit.form.Button \" onclick= \" addInstance() \" >" . __ ( 'Link instance' ). "</button>" ;
132 print "<button dojoType= \" dijit.form.Button \" onclick= \" editSelectedInstance() \" >" . __ ( 'Edit' ). "</button>" ;
133 print "<button dojoType= \" dijit.form.Button \" onclick= \" removeSelectedInstances() \" >" . __ ( 'Remove' ). "</button>" ;
135 print "</div>" ; #toolbar
137 $result = db_query ( $link , "SELECT *,
138 (SELECT COUNT(*) FROM ttrss_linked_feeds
139 WHERE instance_id = ttrss_linked_instances.id) AS num_feeds
140 FROM ttrss_linked_instances
143 print "<p class= \" insensitive \" style='margin-left : 1em;'>" . __ ( "You can connect other instances of Tiny Tiny RSS to this one to share Popular feeds. Link to this instance of Tiny Tiny RSS by using this URL:" );
145 print " <a href= \" # \" onclick= \" alert('" . htmlspecialchars ( get_self_url_prefix ()). "') \" >(display url)</a>" ;
147 print "<p><table width='100%' id='prefInstanceList' class='prefInstanceList' cellspacing='0'>" ;
149 print "<tr class= \" title \" >
150 <td align='center' width= \" 5% \" > </td>
151 <td width=''><a href= \" # \" onclick= \" updateInstanceList('access_url') \" >" . __ ( 'Instance URL' ). "</a></td>
152 <td width='20%'><a href= \" # \" onclick= \" updateInstanceList('access_key') \" >" . __ ( 'Access key' ). "</a></td>
153 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('last_connected') \" >" . __ ( 'Last connected' ). "</a></td>
154 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('num_feeds') \" >" . __ ( 'Stored feeds' ). "</a></td>
159 while ( $line = db_fetch_assoc ( $result )) {
160 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
163 $this_row_id = "id= \" LIRR- $id\" " ;
165 $line [ "last_connected" ] = make_local_datetime ( $link , $line [ "last_connected" ], false );
167 print "<tr class= \" $class\" $this_row_id >" ;
169 print "<td align='center'><input onclick='toggleSelectRow(this);'
170 type= \" checkbox \" id= \" LICHK- $id\" ></td>" ;
172 $onclick = "onclick='editInstance( $id , event)' title='" . __ ( 'Click to edit' ). "'" ;
174 $access_key = mb_substr ( $line [ 'access_key' ], 0 , 4 ) . '...' .
175 mb_substr ( $line [ 'access_key' ], - 4 );
177 print "<td $onclick >" . htmlspecialchars ( $line [ 'access_url' ]) . "</td>" ;
178 print "<td $onclick >" . htmlspecialchars ( $access_key ) . "</td>" ;
179 print "<td $onclick >" . htmlspecialchars ( $line [ 'last_connected' ]) . "</td>" ;
180 print "<td $onclick >" . htmlspecialchars ( $line [ 'num_feeds' ]) . "</td>" ;
189 print "</div>" ; #pane
190 print "</div>" ; #container