]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-instances.php
2 function module_pref_instances ( $link ) {
4 if (! SINGLE_USER_MODE
&& $_SESSION [ "access_level" ] < 10 ) {
5 print __ ( "Your access level is insufficient to open this tab." );
9 $subop = $_REQUEST [ 'subop' ];
11 if ( $subop == "remove" ) {
12 $ids = db_escape_string ( $_REQUEST [ 'ids' ]);
14 db_query ( $link , "DELETE FROM ttrss_linked_instances WHERE
20 if ( $subop == "add" ) {
21 $id = db_escape_string ( $_REQUEST [ "id" ]);
22 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
23 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
25 db_query ( $link , "BEGIN" );
27 $result = db_query ( $link , "SELECT id FROM ttrss_linked_instances
28 WHERE access_url = ' $access_url '" );
30 if ( db_num_rows ( $result ) == 0 ) {
31 db_query ( $link , "INSERT INTO ttrss_linked_instances
32 (access_url, access_key, last_connected, last_status_in, last_status_out)
34 (' $access_url ', ' $access_key ', '1970-01-01', -1, -1)" );
38 db_query ( $link , "COMMIT" );
43 if ( $subop == "edit" ) {
45 $id = db_escape_string ( $_REQUEST [ "id" ]);
47 $result = db_query ( $link , "SELECT * FROM ttrss_linked_instances WHERE
50 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" id \" value= \" $id\" >" ;
51 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-instances \" >" ;
52 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" subop \" value= \" editSave \" >" ;
54 print "<div class= \" dlgSec \" >" . __ ( "Instance" ). "</div>" ;
56 print "<div class= \" dlgSecCont \" >" ;
60 $access_url = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_url" ));
62 print __ ( "URL:" ) . " " ;
64 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
65 placeHolder= \" " . __ ( "Instance URL" ). " \"
66 regExp='^(http|https)://.*'
67 style= \" font-size : 16px; width: 20em \" name= \" access_url \"
68 value= \" $access_url\" >" ;
72 $access_key = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_key" ));
76 print __ ( "Access key:" ) . " " ;
78 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
79 placeHolder= \" " . __ ( "Access key" ). " \" regExp='\w{40}'
80 style= \" width: 20em \" name= \" access_key \" id= \" instance_edit_key \"
81 value= \" $access_key\" >" ;
83 print "<p class='insensitive'>" . __ ( "Use one access key for both linked instances." );
87 print "<div class= \" dlgButtons \" >
88 <div style='float : left'>
89 <button dojoType= \" dijit.form.Button \"
90 onclick= \" return dijit.byId('instanceEditDlg').regenKey() \" >" .
91 __ ( 'Generate new key' ). "</button>
93 <button dojoType= \" dijit.form.Button \"
94 onclick= \" return dijit.byId('instanceEditDlg').execute() \" >" .
96 <button dojoType= \" dijit.form.Button \"
97 onclick= \" return dijit.byId('instanceEditDlg').hide() \"\" >" .
98 __ ( 'Cancel' ). "</button></div>" ;
103 if ( $subop == "editSave" ) {
104 $id = db_escape_string ( $_REQUEST [ "id" ]);
105 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
106 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
108 db_query ( $link , "UPDATE ttrss_linked_instances SET
109 access_key = ' $access_key ', access_url = ' $access_url ',
110 last_connected = '1970-01-01'
116 if (! function_exists ( 'curl_init' )) {
117 print "<div style='padding : 1em'>" ;
118 print_error ( "This functionality requires CURL functions. Please enable CURL in your PHP configuration (you might also want to disable open_basedir in php.ini) and reload this page." );
122 print "<div id= \" pref-instance-wrap \" dojoType= \" dijit.layout.BorderContainer \" gutters= \" false \" >" ;
123 print "<div id= \" pref-instance-header \" dojoType= \" dijit.layout.ContentPane \" region= \" top \" >" ;
125 print "<div id= \" pref-instance-toolbar \" dojoType= \" dijit.Toolbar \" >" ;
127 $sort = db_escape_string ( $_REQUEST [ "sort" ]);
129 if (! $sort ||
$sort == "undefined" ) {
130 $sort = "access_url" ;
133 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
134 "<span>" . __ ( 'Select' ). "</span>" ;
135 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
136 print "<div onclick= \" selectTableRows('prefInstanceList', 'all') \"
137 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
138 print "<div onclick= \" selectTableRows('prefInstanceList', 'none') \"
139 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
140 print "</div></div>" ;
142 print "<button dojoType= \" dijit.form.Button \" onclick= \" addInstance() \" >" . __ ( 'Link instance' ). "</button>" ;
143 print "<button dojoType= \" dijit.form.Button \" onclick= \" editSelectedInstance() \" >" . __ ( 'Edit' ). "</button>" ;
144 print "<button dojoType= \" dijit.form.Button \" onclick= \" removeSelectedInstances() \" >" . __ ( 'Remove' ). "</button>" ;
146 print "</div>" ; #toolbar
148 $result = db_query ( $link , "SELECT *,
149 (SELECT COUNT(*) FROM ttrss_linked_feeds
150 WHERE instance_id = ttrss_linked_instances.id) AS num_feeds
151 FROM ttrss_linked_instances
154 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:" );
156 print " <a href= \" # \" onclick= \" alert('" . htmlspecialchars ( get_self_url_prefix ()). "') \" >(display url)</a>" ;
158 print "<p><table width='100%' id='prefInstanceList' class='prefInstanceList' cellspacing='0'>" ;
160 print "<tr class= \" title \" >
161 <td align='center' width= \" 5% \" > </td>
162 <td width=''><a href= \" # \" onclick= \" updateInstanceList('access_url') \" >" . __ ( 'Instance URL' ). "</a></td>
163 <td width='20%'><a href= \" # \" onclick= \" updateInstanceList('access_key') \" >" . __ ( 'Access key' ). "</a></td>
164 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('last_connected') \" >" . __ ( 'Last connected' ). "</a></td>
165 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('num_feeds') \" >" . __ ( 'Stored feeds' ). "</a></td>
170 while ( $line = db_fetch_assoc ( $result )) {
171 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
174 $this_row_id = "id= \" LIRR- $id\" " ;
176 $line [ "last_connected" ] = make_local_datetime ( $link , $line [ "last_connected" ], false );
178 print "<tr class= \" $class\" $this_row_id >" ;
180 print "<td align='center'><input onclick='toggleSelectRow(this);'
181 type= \" checkbox \" id= \" LICHK- $id\" ></td>" ;
183 $onclick = "onclick='editInstance( $id , event)' title='" . __ ( 'Click to edit' ). "'" ;
185 $access_key = mb_substr ( $line [ 'access_key' ], 0 , 4 ) . '...' .
186 mb_substr ( $line [ 'access_key' ], - 4 );
188 print "<td $onclick >" . htmlspecialchars ( $line [ 'access_url' ]) . "</td>" ;
189 print "<td $onclick >" . htmlspecialchars ( $access_key ) . "</td>" ;
190 print "<td $onclick >" . htmlspecialchars ( $line [ 'last_connected' ]) . "</td>" ;
191 print "<td $onclick >" . htmlspecialchars ( $line [ 'num_feeds' ]) . "</td>" ;
200 print "</div>" ; #pane
201 print "</div>" ; #container