]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/instances.php
2 class Pref_Instances
extends Handler_Protected
{
4 private $status_codes = array (
5 0 => "Connection failed" ,
7 2 => "Invalid object received" ,
8 16 => "Access denied" );
10 function csrf_ignore ( $method ) {
11 $csrf_ignored = array ( "index" , "edit" );
13 return array_search ( $method , $csrf_ignored ) !== false ;
16 function before ( $method ) {
17 if ( parent
:: before ( $method )) {
18 if ( $_SESSION [ "access_level" ] < 10 ) {
19 print __ ( "Your access level is insufficient to open this tab." );
28 $ids = db_escape_string ( $_REQUEST [ 'ids' ]);
30 db_query ( $this -> link
, "DELETE FROM ttrss_linked_instances WHERE
35 $id = db_escape_string ( $_REQUEST [ "id" ]);
36 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
37 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
39 db_query ( $this -> link
, "BEGIN" );
41 $result = db_query ( $this -> link
, "SELECT id FROM ttrss_linked_instances
42 WHERE access_url = ' $access_url '" );
44 if ( db_num_rows ( $result ) == 0 ) {
45 db_query ( $this -> link
, "INSERT INTO ttrss_linked_instances
46 (access_url, access_key, last_connected, last_status_in, last_status_out)
48 (' $access_url ', ' $access_key ', '1970-01-01', -1, -1)" );
52 db_query ( $this -> link
, "COMMIT" );
56 $id = db_escape_string ( $_REQUEST [ "id" ]);
58 $result = db_query ( $this -> link
, "SELECT * FROM ttrss_linked_instances WHERE
61 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" id \" value= \" $id\" >" ;
62 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-instances \" >" ;
63 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" editSave \" >" ;
65 print "<div class= \" dlgSec \" >" . __ ( "Instance" ). "</div>" ;
67 print "<div class= \" dlgSecCont \" >" ;
71 $access_url = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_url" ));
73 print __ ( "URL:" ) . " " ;
75 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
76 placeHolder= \" " . __ ( "Instance URL" ). " \"
77 regExp='^(http|https)://.*'
78 style= \" font-size : 16px; width: 20em \" name= \" access_url \"
79 value= \" $access_url\" >" ;
83 $access_key = htmlspecialchars ( db_fetch_result ( $result , 0 , "access_key" ));
87 print __ ( "Access key:" ) . " " ;
89 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
90 placeHolder= \" " . __ ( "Access key" ). " \" regExp='\w{40}'
91 style= \" width: 20em \" name= \" access_key \" id= \" instance_edit_key \"
92 value= \" $access_key\" >" ;
94 print "<p class='insensitive'>" . __ ( "Use one access key for both linked instances." );
98 print "<div class= \" dlgButtons \" >
99 <div style='float : left'>
100 <button dojoType= \" dijit.form.Button \"
101 onclick= \" return dijit.byId('instanceEditDlg').regenKey() \" >" .
102 __ ( 'Generate new key' ). "</button>
104 <button dojoType= \" dijit.form.Button \"
105 onclick= \" return dijit.byId('instanceEditDlg').execute() \" >" .
106 __ ( 'Save' ). "</button>
107 <button dojoType= \" dijit.form.Button \"
108 onclick= \" return dijit.byId('instanceEditDlg').hide() \"\" >" .
109 __ ( 'Cancel' ). "</button></div>" ;
113 function editSave () {
114 $id = db_escape_string ( $_REQUEST [ "id" ]);
115 $access_url = db_escape_string ( $_REQUEST [ "access_url" ]);
116 $access_key = db_escape_string ( $_REQUEST [ "access_key" ]);
118 db_query ( $this -> link
, "UPDATE ttrss_linked_instances SET
119 access_key = ' $access_key ', access_url = ' $access_url ',
120 last_connected = '1970-01-01'
127 if (! function_exists ( 'curl_init' )) {
128 print "<div style='padding : 1em'>" ;
129 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." );
133 print "<div id= \" pref-instance-wrap \" dojoType= \" dijit.layout.BorderContainer \" gutters= \" false \" >" ;
134 print "<div id= \" pref-instance-header \" dojoType= \" dijit.layout.ContentPane \" region= \" top \" >" ;
136 print "<div id= \" pref-instance-toolbar \" dojoType= \" dijit.Toolbar \" >" ;
138 $sort = db_escape_string ( $_REQUEST [ "sort" ]);
140 if (! $sort ||
$sort == "undefined" ) {
141 $sort = "access_url" ;
144 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
145 "<span>" . __ ( 'Select' ). "</span>" ;
146 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
147 print "<div onclick= \" selectTableRows('prefInstanceList', 'all') \"
148 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
149 print "<div onclick= \" selectTableRows('prefInstanceList', 'none') \"
150 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
151 print "</div></div>" ;
153 print "<button dojoType= \" dijit.form.Button \" onclick= \" addInstance() \" >" . __ ( 'Link instance' ). "</button>" ;
154 print "<button dojoType= \" dijit.form.Button \" onclick= \" editSelectedInstance() \" >" . __ ( 'Edit' ). "</button>" ;
155 print "<button dojoType= \" dijit.form.Button \" onclick= \" removeSelectedInstances() \" >" . __ ( 'Remove' ). "</button>" ;
157 print "</div>" ; #toolbar
159 $result = db_query ( $this -> link
, "SELECT *,
160 (SELECT COUNT(*) FROM ttrss_linked_feeds
161 WHERE instance_id = ttrss_linked_instances.id) AS num_feeds
162 FROM ttrss_linked_instances
165 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:" );
167 print " <a href= \" # \" onclick= \" alert('" . htmlspecialchars ( get_self_url_prefix ()). "') \" >(display url)</a>" ;
169 print "<p><table width='100%' id='prefInstanceList' class='prefInstanceList' cellspacing='0'>" ;
171 print "<tr class= \" title \" >
172 <td align='center' width= \" 5% \" > </td>
173 <td width=''><a href= \" # \" onclick= \" updateInstanceList('access_url') \" >" . __ ( 'Instance URL' ). "</a></td>
174 <td width='20%'><a href= \" # \" onclick= \" updateInstanceList('access_key') \" >" . __ ( 'Access key' ). "</a></td>
175 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('last_connected') \" >" . __ ( 'Last connected' ). "</a></td>
176 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('last_status_out') \" >" . __ ( 'Status' ). "</a></td>
177 <td width='10%'><a href= \" # \" onclick= \" updateUsersList('num_feeds') \" >" . __ ( 'Stored feeds' ). "</a></td>
182 while ( $line = db_fetch_assoc ( $result )) {
183 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
186 $this_row_id = "id= \" LIRR- $id\" " ;
188 $line [ "last_connected" ] = make_local_datetime ( $this -> link
, $line [ "last_connected" ], false );
190 print "<tr class= \" $class\" $this_row_id >" ;
192 print "<td align='center'><input onclick='toggleSelectRow(this);'
193 type= \" checkbox \" id= \" LICHK- $id\" ></td>" ;
195 $onclick = "onclick='editInstance( $id , event)' title='" . __ ( 'Click to edit' ). "'" ;
197 $access_key = mb_substr ( $line [ 'access_key' ], 0 , 4 ) . '...' .
198 mb_substr ( $line [ 'access_key' ], - 4 );
200 print "<td $onclick >" . htmlspecialchars ( $line [ 'access_url' ]) . "</td>" ;
201 print "<td $onclick >" . htmlspecialchars ( $access_key ) . "</td>" ;
202 print "<td $onclick >" . htmlspecialchars ( $line [ 'last_connected' ]) . "</td>" ;
203 print "<td $onclick >" . $this -> status_codes
[ $line [ 'last_status_out' ]] . "</td>" ;
204 print "<td $onclick >" . htmlspecialchars ( $line [ 'num_feeds' ]) . "</td>" ;
213 print "</div>" ; #pane
216 $pluginhost -> run_hooks ( $pluginhost :: HOOK_PREFS_TAB
,
217 "hook_prefs_tab" , "prefInstances" );
219 print "</div>" ; #container