]>
git.wh0rd.org - tt-rss.git/blob - classes/pref_instances.php
2 class Pref_Instances
extends Protected_Handler
{
5 if ( parent
:: before ()) {
6 if ( $_SESSION [ "access_level" ] < 10 ) {
7 print __ ( "Your access level is insufficient to open this tab." );
16 $ids = db_escape_string ( $_REQUEST [ 'ids' ]);
18 db_query ( $this -> link
, "DELETE FROM ttrss_linked_instances WHERE
23 $id = db_escape_string ( $_REQUEST [ "id" ]);
24 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
25 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
27 db_query ( $this -> link
, "BEGIN" );
29 $result = db_query ( $this -> link
, "SELECT id FROM ttrss_linked_instances
30 WHERE access_url = ' $access_url '" );
32 if ( db_num_rows ( $result ) == 0 ) {
33 db_query ( $this -> link
, "INSERT INTO ttrss_linked_instances
34 (access_url, access_key, last_connected, last_status_in, last_status_out)
36 (' $access_url ', ' $access_key ', '1970-01-01', -1, -1)" );
40 db_query ( $this -> link
, "COMMIT" );
44 $id = db_escape_string ( $_REQUEST [ "id" ]);
46 $result = db_query ( $this -> link
, "SELECT * FROM ttrss_linked_instances WHERE
49 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" id \" value= \" $id\" >" ;
50 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-instances \" >" ;
51 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" editSave \" >" ;
53 print "<div class= \" dlgSec \" >" . __ ( "Instance" ). "</div>" ;
55 print "<div class= \" dlgSecCont \" >" ;
59 $access_url = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_url" ));
61 print __ ( "URL:" ) . " " ;
63 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
64 placeHolder= \" " . __ ( "Instance URL" ). " \"
65 regExp='^(http|https)://.*'
66 style= \" font-size : 16px; width: 20em \" name= \" access_url \"
67 value= \" $access_url\" >" ;
71 $access_key = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_key" ));
75 print __ ( "Access key:" ) . " " ;
77 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
78 placeHolder= \" " . __ ( "Access key" ). " \" regExp='\w{40}'
79 style= \" width: 20em \" name= \" access_key \" id= \" instance_edit_key \"
80 value= \" $access_key\" >" ;
82 print "<p class='insensitive'>" . __ ( "Use one access key for both linked instances." );
86 print "<div class= \" dlgButtons \" >
87 <div style='float : left'>
88 <button dojoType= \" dijit.form.Button \"
89 onclick= \" return dijit.byId('instanceEditDlg').regenKey() \" >" .
90 __ ( 'Generate new key' ). "</button>
92 <button dojoType= \" dijit.form.Button \"
93 onclick= \" return dijit.byId('instanceEditDlg').execute() \" >" .
95 <button dojoType= \" dijit.form.Button \"
96 onclick= \" return dijit.byId('instanceEditDlg').hide() \"\" >" .
97 __ ( 'Cancel' ). "</button></div>" ;
101 function editSave () {
102 $id = db_escape_string ( $_REQUEST [ "id" ]);
103 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
104 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
106 db_query ( $this -> link
, "UPDATE ttrss_linked_instances SET
107 access_key = ' $access_key ', access_url = ' $access_url ',
108 last_connected = '1970-01-01'
115 if (! function_exists ( 'curl_init' )) {
116 print "<div style='padding : 1em'>" ;
117 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." );
121 print "<div id= \" pref-instance-wrap \" dojoType= \" dijit.layout.BorderContainer \" gutters= \" false \" >" ;
122 print "<div id= \" pref-instance-header \" dojoType= \" dijit.layout.ContentPane \" region= \" top \" >" ;
124 print "<div id= \" pref-instance-toolbar \" dojoType= \" dijit.Toolbar \" >" ;
126 $sort = db_escape_string ( $_REQUEST [ "sort" ]);
128 if (! $sort ||
$sort == "undefined" ) {
129 $sort = "access_url" ;
132 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
133 "<span>" . __ ( 'Select' ). "</span>" ;
134 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
135 print "<div onclick= \" selectTableRows('prefInstanceList', 'all') \"
136 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
137 print "<div onclick= \" selectTableRows('prefInstanceList', 'none') \"
138 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
139 print "</div></div>" ;
141 print "<button dojoType= \" dijit.form.Button \" onclick= \" addInstance() \" >" . __ ( 'Link instance' ). "</button>" ;
142 print "<button dojoType= \" dijit.form.Button \" onclick= \" editSelectedInstance() \" >" . __ ( 'Edit' ). "</button>" ;
143 print "<button dojoType= \" dijit.form.Button \" onclick= \" removeSelectedInstances() \" >" . __ ( 'Remove' ). "</button>" ;
145 print "</div>" ; #toolbar
147 $result = db_query ( $this -> link
, "SELECT *,
148 (SELECT COUNT(*) FROM ttrss_linked_feeds
149 WHERE instance_id = ttrss_linked_instances.id) AS num_feeds
150 FROM ttrss_linked_instances
153 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:" );
155 print " <a href= \" # \" onclick= \" alert('" . htmlspecialchars ( get_self_url_prefix ()). "') \" >(display url)</a>" ;
157 print "<p><table width='100%' id='prefInstanceList' class='prefInstanceList' cellspacing='0'>" ;
159 print "<tr class= \" title \" >
160 <td align='center' width= \" 5% \" > </td>
161 <td width=''><a href= \" # \" onclick= \" updateInstanceList('access_url') \" >" . __ ( 'Instance URL' ). "</a></td>
162 <td width='20%'><a href= \" # \" onclick= \" updateInstanceList('access_key') \" >" . __ ( 'Access key' ). "</a></td>
163 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('last_connected') \" >" . __ ( 'Last connected' ). "</a></td>
164 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('num_feeds') \" >" . __ ( 'Stored feeds' ). "</a></td>
169 while ( $line = db_fetch_assoc ( $result )) {
170 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
173 $this_row_id = "id= \" LIRR- $id\" " ;
175 $line [ "last_connected" ] = make_local_datetime ( $this -> link
, $line [ "last_connected" ], false );
177 print "<tr class= \" $class\" $this_row_id >" ;
179 print "<td align='center'><input onclick='toggleSelectRow(this);'
180 type= \" checkbox \" id= \" LICHK- $id\" ></td>" ;
182 $onclick = "onclick='editInstance( $id , event)' title='" . __ ( 'Click to edit' ). "'" ;
184 $access_key = mb_substr ( $line [ 'access_key' ], 0 , 4 ) . '...' .
185 mb_substr ( $line [ 'access_key' ], - 4 );
187 print "<td $onclick >" . htmlspecialchars ( $line [ 'access_url' ]) . "</td>" ;
188 print "<td $onclick >" . htmlspecialchars ( $access_key ) . "</td>" ;
189 print "<td $onclick >" . htmlspecialchars ( $line [ 'last_connected' ]) . "</td>" ;
190 print "<td $onclick >" . htmlspecialchars ( $line [ 'num_feeds' ]) . "</td>" ;
199 print "</div>" ; #pane
200 print "</div>" ; #container