@@ -1003,22 +1003,22 @@ discard block |
||
| 1003 | 1003 | $req .= pack ( "N", $filter["type"] ); |
| 1004 | 1004 | switch ( $filter["type"] ) |
| 1005 | 1005 | { |
| 1006 | - case SPH_FILTER_VALUES: |
|
| 1007 | - $req .= pack ( "N", count($filter["values"]) ); |
|
| 1008 | - foreach ( $filter["values"] as $value ) |
|
| 1009 | - $req .= sphPackI64 ( $value ); |
|
| 1010 | - break; |
|
| 1011 | - |
|
| 1012 | - case SPH_FILTER_RANGE: |
|
| 1013 | - $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); |
|
| 1014 | - break; |
|
| 1015 | - |
|
| 1016 | - case SPH_FILTER_FLOATRANGE: |
|
| 1017 | - $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); |
|
| 1018 | - break; |
|
| 1019 | - |
|
| 1020 | - default: |
|
| 1021 | - assert ( 0 && "internal error: unhandled filter type" ); |
|
| 1006 | + case SPH_FILTER_VALUES: |
|
| 1007 | + $req .= pack ( "N", count($filter["values"]) ); |
|
| 1008 | + foreach ( $filter["values"] as $value ) |
|
| 1009 | + $req .= sphPackI64 ( $value ); |
|
| 1010 | + break; |
|
| 1011 | + |
|
| 1012 | + case SPH_FILTER_RANGE: |
|
| 1013 | + $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); |
|
| 1014 | + break; |
|
| 1015 | + |
|
| 1016 | + case SPH_FILTER_FLOATRANGE: |
|
| 1017 | + $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); |
|
| 1018 | + break; |
|
| 1019 | + |
|
| 1020 | + default: |
|
| 1021 | + assert ( 0 && "internal error: unhandled filter type" ); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | $req .= pack ( "N", $filter["exclude"] ); |
| 1024 | 1024 | } |
@@ -1073,9 +1073,9 @@ discard block |
||
| 1073 | 1073 | $req .= sphPackU64 ( $id ); |
| 1074 | 1074 | switch ( $entry["type"] ) |
| 1075 | 1075 | { |
| 1076 | - case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; |
|
| 1077 | - case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; |
|
| 1078 | - default: $req .= pack ( "N", $val ); break; |
|
| 1076 | + case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; |
|
| 1077 | + case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; |
|
| 1078 | + default: $req .= pack ( "N", $val ); break; |
|
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
@@ -123,1571 +123,1571 @@ |
||
| 123 | 123 | /// pack 64-bit signed |
| 124 | 124 | function sphPackI64 ( $v ) |
| 125 | 125 | { |
| 126 | - assert ( is_numeric($v) ); |
|
| 127 | - |
|
| 128 | - // x64 |
|
| 129 | - if ( PHP_INT_SIZE>=8 ) |
|
| 130 | - { |
|
| 131 | - $v = (int)$v; |
|
| 132 | - return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // x32, int |
|
| 136 | - if ( is_int($v) ) |
|
| 137 | - return pack ( "NN", $v < 0 ? -1 : 0, $v ); |
|
| 138 | - |
|
| 139 | - // x32, bcmath |
|
| 140 | - if ( function_exists("bcmul") ) |
|
| 141 | - { |
|
| 142 | - if ( bccomp ( $v, 0 ) == -1 ) |
|
| 143 | - $v = bcadd ( "18446744073709551616", $v ); |
|
| 144 | - $h = bcdiv ( $v, "4294967296", 0 ); |
|
| 145 | - $l = bcmod ( $v, "4294967296" ); |
|
| 146 | - return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // x32, no-bcmath |
|
| 150 | - $p = max(0, strlen($v) - 13); |
|
| 151 | - $lo = abs((float)substr($v, $p)); |
|
| 152 | - $hi = abs((float)substr($v, 0, $p)); |
|
| 153 | - |
|
| 154 | - $m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 |
|
| 155 | - $q = floor($m/4294967296.0); |
|
| 156 | - $l = $m - ($q*4294967296.0); |
|
| 157 | - $h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 |
|
| 158 | - |
|
| 159 | - if ( $v<0 ) |
|
| 160 | - { |
|
| 161 | - if ( $l==0 ) |
|
| 162 | - $h = 4294967296.0 - $h; |
|
| 163 | - else |
|
| 164 | - { |
|
| 165 | - $h = 4294967295.0 - $h; |
|
| 166 | - $l = 4294967296.0 - $l; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - return pack ( "NN", $h, $l ); |
|
| 126 | + assert ( is_numeric($v) ); |
|
| 127 | + |
|
| 128 | + // x64 |
|
| 129 | + if ( PHP_INT_SIZE>=8 ) |
|
| 130 | + { |
|
| 131 | + $v = (int)$v; |
|
| 132 | + return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // x32, int |
|
| 136 | + if ( is_int($v) ) |
|
| 137 | + return pack ( "NN", $v < 0 ? -1 : 0, $v ); |
|
| 138 | + |
|
| 139 | + // x32, bcmath |
|
| 140 | + if ( function_exists("bcmul") ) |
|
| 141 | + { |
|
| 142 | + if ( bccomp ( $v, 0 ) == -1 ) |
|
| 143 | + $v = bcadd ( "18446744073709551616", $v ); |
|
| 144 | + $h = bcdiv ( $v, "4294967296", 0 ); |
|
| 145 | + $l = bcmod ( $v, "4294967296" ); |
|
| 146 | + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // x32, no-bcmath |
|
| 150 | + $p = max(0, strlen($v) - 13); |
|
| 151 | + $lo = abs((float)substr($v, $p)); |
|
| 152 | + $hi = abs((float)substr($v, 0, $p)); |
|
| 153 | + |
|
| 154 | + $m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 |
|
| 155 | + $q = floor($m/4294967296.0); |
|
| 156 | + $l = $m - ($q*4294967296.0); |
|
| 157 | + $h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 |
|
| 158 | + |
|
| 159 | + if ( $v<0 ) |
|
| 160 | + { |
|
| 161 | + if ( $l==0 ) |
|
| 162 | + $h = 4294967296.0 - $h; |
|
| 163 | + else |
|
| 164 | + { |
|
| 165 | + $h = 4294967295.0 - $h; |
|
| 166 | + $l = 4294967296.0 - $l; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + return pack ( "NN", $h, $l ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /// pack 64-bit unsigned |
| 173 | 173 | function sphPackU64 ( $v ) |
| 174 | 174 | { |
| 175 | - assert ( is_numeric($v) ); |
|
| 176 | - |
|
| 177 | - // x64 |
|
| 178 | - if ( PHP_INT_SIZE>=8 ) |
|
| 179 | - { |
|
| 180 | - assert ( $v>=0 ); |
|
| 181 | - |
|
| 182 | - // x64, int |
|
| 183 | - if ( is_int($v) ) |
|
| 184 | - return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); |
|
| 185 | - |
|
| 186 | - // x64, bcmath |
|
| 187 | - if ( function_exists("bcmul") ) |
|
| 188 | - { |
|
| 189 | - $h = bcdiv ( $v, 4294967296, 0 ); |
|
| 190 | - $l = bcmod ( $v, 4294967296 ); |
|
| 191 | - return pack ( "NN", $h, $l ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // x64, no-bcmath |
|
| 195 | - $p = max ( 0, strlen($v) - 13 ); |
|
| 196 | - $lo = (int)substr ( $v, $p ); |
|
| 197 | - $hi = (int)substr ( $v, 0, $p ); |
|
| 198 | - |
|
| 199 | - $m = $lo + $hi*1316134912; |
|
| 200 | - $l = $m % 4294967296; |
|
| 201 | - $h = $hi*2328 + (int)($m/4294967296); |
|
| 202 | - |
|
| 203 | - return pack ( "NN", $h, $l ); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // x32, int |
|
| 207 | - if ( is_int($v) ) |
|
| 208 | - return pack ( "NN", 0, $v ); |
|
| 209 | - |
|
| 210 | - // x32, bcmath |
|
| 211 | - if ( function_exists("bcmul") ) |
|
| 212 | - { |
|
| 213 | - $h = bcdiv ( $v, "4294967296", 0 ); |
|
| 214 | - $l = bcmod ( $v, "4294967296" ); |
|
| 215 | - return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // x32, no-bcmath |
|
| 219 | - $p = max(0, strlen($v) - 13); |
|
| 220 | - $lo = (float)substr($v, $p); |
|
| 221 | - $hi = (float)substr($v, 0, $p); |
|
| 222 | - |
|
| 223 | - $m = $lo + $hi*1316134912.0; |
|
| 224 | - $q = floor($m / 4294967296.0); |
|
| 225 | - $l = $m - ($q * 4294967296.0); |
|
| 226 | - $h = $hi*2328.0 + $q; |
|
| 227 | - |
|
| 228 | - return pack ( "NN", $h, $l ); |
|
| 175 | + assert ( is_numeric($v) ); |
|
| 176 | + |
|
| 177 | + // x64 |
|
| 178 | + if ( PHP_INT_SIZE>=8 ) |
|
| 179 | + { |
|
| 180 | + assert ( $v>=0 ); |
|
| 181 | + |
|
| 182 | + // x64, int |
|
| 183 | + if ( is_int($v) ) |
|
| 184 | + return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); |
|
| 185 | + |
|
| 186 | + // x64, bcmath |
|
| 187 | + if ( function_exists("bcmul") ) |
|
| 188 | + { |
|
| 189 | + $h = bcdiv ( $v, 4294967296, 0 ); |
|
| 190 | + $l = bcmod ( $v, 4294967296 ); |
|
| 191 | + return pack ( "NN", $h, $l ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // x64, no-bcmath |
|
| 195 | + $p = max ( 0, strlen($v) - 13 ); |
|
| 196 | + $lo = (int)substr ( $v, $p ); |
|
| 197 | + $hi = (int)substr ( $v, 0, $p ); |
|
| 198 | + |
|
| 199 | + $m = $lo + $hi*1316134912; |
|
| 200 | + $l = $m % 4294967296; |
|
| 201 | + $h = $hi*2328 + (int)($m/4294967296); |
|
| 202 | + |
|
| 203 | + return pack ( "NN", $h, $l ); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // x32, int |
|
| 207 | + if ( is_int($v) ) |
|
| 208 | + return pack ( "NN", 0, $v ); |
|
| 209 | + |
|
| 210 | + // x32, bcmath |
|
| 211 | + if ( function_exists("bcmul") ) |
|
| 212 | + { |
|
| 213 | + $h = bcdiv ( $v, "4294967296", 0 ); |
|
| 214 | + $l = bcmod ( $v, "4294967296" ); |
|
| 215 | + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // x32, no-bcmath |
|
| 219 | + $p = max(0, strlen($v) - 13); |
|
| 220 | + $lo = (float)substr($v, $p); |
|
| 221 | + $hi = (float)substr($v, 0, $p); |
|
| 222 | + |
|
| 223 | + $m = $lo + $hi*1316134912.0; |
|
| 224 | + $q = floor($m / 4294967296.0); |
|
| 225 | + $l = $m - ($q * 4294967296.0); |
|
| 226 | + $h = $hi*2328.0 + $q; |
|
| 227 | + |
|
| 228 | + return pack ( "NN", $h, $l ); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // unpack 64-bit unsigned |
| 232 | 232 | function sphUnpackU64 ( $v ) |
| 233 | 233 | { |
| 234 | - list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); |
|
| 235 | - |
|
| 236 | - if ( PHP_INT_SIZE>=8 ) |
|
| 237 | - { |
|
| 238 | - if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
| 239 | - if ( $lo<0 ) $lo += (1<<32); |
|
| 240 | - |
|
| 241 | - // x64, int |
|
| 242 | - if ( $hi<=2147483647 ) |
|
| 243 | - return ($hi<<32) + $lo; |
|
| 244 | - |
|
| 245 | - // x64, bcmath |
|
| 246 | - if ( function_exists("bcmul") ) |
|
| 247 | - return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); |
|
| 248 | - |
|
| 249 | - // x64, no-bcmath |
|
| 250 | - $C = 100000; |
|
| 251 | - $h = ((int)($hi / $C) << 32) + (int)($lo / $C); |
|
| 252 | - $l = (($hi % $C) << 32) + ($lo % $C); |
|
| 253 | - if ( $l>$C ) |
|
| 254 | - { |
|
| 255 | - $h += (int)($l / $C); |
|
| 256 | - $l = $l % $C; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if ( $h==0 ) |
|
| 260 | - return $l; |
|
| 261 | - return sprintf ( "%d%05d", $h, $l ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // x32, int |
|
| 265 | - if ( $hi==0 ) |
|
| 266 | - { |
|
| 267 | - if ( $lo>0 ) |
|
| 268 | - return $lo; |
|
| 269 | - return sprintf ( "%u", $lo ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $hi = sprintf ( "%u", $hi ); |
|
| 273 | - $lo = sprintf ( "%u", $lo ); |
|
| 274 | - |
|
| 275 | - // x32, bcmath |
|
| 276 | - if ( function_exists("bcmul") ) |
|
| 277 | - return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); |
|
| 278 | - |
|
| 279 | - // x32, no-bcmath |
|
| 280 | - $hi = (float)$hi; |
|
| 281 | - $lo = (float)$lo; |
|
| 282 | - |
|
| 283 | - $q = floor($hi/10000000.0); |
|
| 284 | - $r = $hi - $q*10000000.0; |
|
| 285 | - $m = $lo + $r*4967296.0; |
|
| 286 | - $mq = floor($m/10000000.0); |
|
| 287 | - $l = $m - $mq*10000000.0; |
|
| 288 | - $h = $q*4294967296.0 + $r*429.0 + $mq; |
|
| 289 | - |
|
| 290 | - $h = sprintf ( "%.0f", $h ); |
|
| 291 | - $l = sprintf ( "%07.0f", $l ); |
|
| 292 | - if ( $h=="0" ) |
|
| 293 | - return sprintf( "%.0f", (float)$l ); |
|
| 294 | - return $h . $l; |
|
| 234 | + list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); |
|
| 235 | + |
|
| 236 | + if ( PHP_INT_SIZE>=8 ) |
|
| 237 | + { |
|
| 238 | + if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
| 239 | + if ( $lo<0 ) $lo += (1<<32); |
|
| 240 | + |
|
| 241 | + // x64, int |
|
| 242 | + if ( $hi<=2147483647 ) |
|
| 243 | + return ($hi<<32) + $lo; |
|
| 244 | + |
|
| 245 | + // x64, bcmath |
|
| 246 | + if ( function_exists("bcmul") ) |
|
| 247 | + return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); |
|
| 248 | + |
|
| 249 | + // x64, no-bcmath |
|
| 250 | + $C = 100000; |
|
| 251 | + $h = ((int)($hi / $C) << 32) + (int)($lo / $C); |
|
| 252 | + $l = (($hi % $C) << 32) + ($lo % $C); |
|
| 253 | + if ( $l>$C ) |
|
| 254 | + { |
|
| 255 | + $h += (int)($l / $C); |
|
| 256 | + $l = $l % $C; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if ( $h==0 ) |
|
| 260 | + return $l; |
|
| 261 | + return sprintf ( "%d%05d", $h, $l ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // x32, int |
|
| 265 | + if ( $hi==0 ) |
|
| 266 | + { |
|
| 267 | + if ( $lo>0 ) |
|
| 268 | + return $lo; |
|
| 269 | + return sprintf ( "%u", $lo ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $hi = sprintf ( "%u", $hi ); |
|
| 273 | + $lo = sprintf ( "%u", $lo ); |
|
| 274 | + |
|
| 275 | + // x32, bcmath |
|
| 276 | + if ( function_exists("bcmul") ) |
|
| 277 | + return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); |
|
| 278 | + |
|
| 279 | + // x32, no-bcmath |
|
| 280 | + $hi = (float)$hi; |
|
| 281 | + $lo = (float)$lo; |
|
| 282 | + |
|
| 283 | + $q = floor($hi/10000000.0); |
|
| 284 | + $r = $hi - $q*10000000.0; |
|
| 285 | + $m = $lo + $r*4967296.0; |
|
| 286 | + $mq = floor($m/10000000.0); |
|
| 287 | + $l = $m - $mq*10000000.0; |
|
| 288 | + $h = $q*4294967296.0 + $r*429.0 + $mq; |
|
| 289 | + |
|
| 290 | + $h = sprintf ( "%.0f", $h ); |
|
| 291 | + $l = sprintf ( "%07.0f", $l ); |
|
| 292 | + if ( $h=="0" ) |
|
| 293 | + return sprintf( "%.0f", (float)$l ); |
|
| 294 | + return $h . $l; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // unpack 64-bit signed |
| 298 | 298 | function sphUnpackI64 ( $v ) |
| 299 | 299 | { |
| 300 | - list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); |
|
| 301 | - |
|
| 302 | - // x64 |
|
| 303 | - if ( PHP_INT_SIZE>=8 ) |
|
| 304 | - { |
|
| 305 | - if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
| 306 | - if ( $lo<0 ) $lo += (1<<32); |
|
| 307 | - |
|
| 308 | - return ($hi<<32) + $lo; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // x32, int |
|
| 312 | - if ( $hi==0 ) |
|
| 313 | - { |
|
| 314 | - if ( $lo>0 ) |
|
| 315 | - return $lo; |
|
| 316 | - return sprintf ( "%u", $lo ); |
|
| 317 | - } |
|
| 318 | - // x32, int |
|
| 319 | - elseif ( $hi==-1 ) |
|
| 320 | - { |
|
| 321 | - if ( $lo<0 ) |
|
| 322 | - return $lo; |
|
| 323 | - return sprintf ( "%.0f", $lo - 4294967296.0 ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $neg = ""; |
|
| 327 | - $c = 0; |
|
| 328 | - if ( $hi<0 ) |
|
| 329 | - { |
|
| 330 | - $hi = ~$hi; |
|
| 331 | - $lo = ~$lo; |
|
| 332 | - $c = 1; |
|
| 333 | - $neg = "-"; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - $hi = sprintf ( "%u", $hi ); |
|
| 337 | - $lo = sprintf ( "%u", $lo ); |
|
| 338 | - |
|
| 339 | - // x32, bcmath |
|
| 340 | - if ( function_exists("bcmul") ) |
|
| 341 | - return $neg . bcadd ( bcadd ( $lo, bcmul ( $hi, "4294967296" ) ), $c ); |
|
| 342 | - |
|
| 343 | - // x32, no-bcmath |
|
| 344 | - $hi = (float)$hi; |
|
| 345 | - $lo = (float)$lo; |
|
| 346 | - |
|
| 347 | - $q = floor($hi/10000000.0); |
|
| 348 | - $r = $hi - $q*10000000.0; |
|
| 349 | - $m = $lo + $r*4967296.0; |
|
| 350 | - $mq = floor($m/10000000.0); |
|
| 351 | - $l = $m - $mq*10000000.0 + $c; |
|
| 352 | - $h = $q*4294967296.0 + $r*429.0 + $mq; |
|
| 353 | - if ( $l==10000000 ) |
|
| 354 | - { |
|
| 355 | - $l = 0; |
|
| 356 | - $h += 1; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $h = sprintf ( "%.0f", $h ); |
|
| 360 | - $l = sprintf ( "%07.0f", $l ); |
|
| 361 | - if ( $h=="0" ) |
|
| 362 | - return $neg . sprintf( "%.0f", (float)$l ); |
|
| 363 | - return $neg . $h . $l; |
|
| 300 | + list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); |
|
| 301 | + |
|
| 302 | + // x64 |
|
| 303 | + if ( PHP_INT_SIZE>=8 ) |
|
| 304 | + { |
|
| 305 | + if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
| 306 | + if ( $lo<0 ) $lo += (1<<32); |
|
| 307 | + |
|
| 308 | + return ($hi<<32) + $lo; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // x32, int |
|
| 312 | + if ( $hi==0 ) |
|
| 313 | + { |
|
| 314 | + if ( $lo>0 ) |
|
| 315 | + return $lo; |
|
| 316 | + return sprintf ( "%u", $lo ); |
|
| 317 | + } |
|
| 318 | + // x32, int |
|
| 319 | + elseif ( $hi==-1 ) |
|
| 320 | + { |
|
| 321 | + if ( $lo<0 ) |
|
| 322 | + return $lo; |
|
| 323 | + return sprintf ( "%.0f", $lo - 4294967296.0 ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $neg = ""; |
|
| 327 | + $c = 0; |
|
| 328 | + if ( $hi<0 ) |
|
| 329 | + { |
|
| 330 | + $hi = ~$hi; |
|
| 331 | + $lo = ~$lo; |
|
| 332 | + $c = 1; |
|
| 333 | + $neg = "-"; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + $hi = sprintf ( "%u", $hi ); |
|
| 337 | + $lo = sprintf ( "%u", $lo ); |
|
| 338 | + |
|
| 339 | + // x32, bcmath |
|
| 340 | + if ( function_exists("bcmul") ) |
|
| 341 | + return $neg . bcadd ( bcadd ( $lo, bcmul ( $hi, "4294967296" ) ), $c ); |
|
| 342 | + |
|
| 343 | + // x32, no-bcmath |
|
| 344 | + $hi = (float)$hi; |
|
| 345 | + $lo = (float)$lo; |
|
| 346 | + |
|
| 347 | + $q = floor($hi/10000000.0); |
|
| 348 | + $r = $hi - $q*10000000.0; |
|
| 349 | + $m = $lo + $r*4967296.0; |
|
| 350 | + $mq = floor($m/10000000.0); |
|
| 351 | + $l = $m - $mq*10000000.0 + $c; |
|
| 352 | + $h = $q*4294967296.0 + $r*429.0 + $mq; |
|
| 353 | + if ( $l==10000000 ) |
|
| 354 | + { |
|
| 355 | + $l = 0; |
|
| 356 | + $h += 1; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $h = sprintf ( "%.0f", $h ); |
|
| 360 | + $l = sprintf ( "%07.0f", $l ); |
|
| 361 | + if ( $h=="0" ) |
|
| 362 | + return $neg . sprintf( "%.0f", (float)$l ); |
|
| 363 | + return $neg . $h . $l; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | function sphFixUint ( $value ) |
| 368 | 368 | { |
| 369 | - if ( PHP_INT_SIZE>=8 ) |
|
| 370 | - { |
|
| 371 | - // x64 route, workaround broken unpack() in 5.2.2+ |
|
| 372 | - if ( $value<0 ) $value += (1<<32); |
|
| 373 | - return $value; |
|
| 374 | - } |
|
| 375 | - else |
|
| 376 | - { |
|
| 377 | - // x32 route, workaround php signed/unsigned braindamage |
|
| 378 | - return sprintf ( "%u", $value ); |
|
| 379 | - } |
|
| 369 | + if ( PHP_INT_SIZE>=8 ) |
|
| 370 | + { |
|
| 371 | + // x64 route, workaround broken unpack() in 5.2.2+ |
|
| 372 | + if ( $value<0 ) $value += (1<<32); |
|
| 373 | + return $value; |
|
| 374 | + } |
|
| 375 | + else |
|
| 376 | + { |
|
| 377 | + // x32 route, workaround php signed/unsigned braindamage |
|
| 378 | + return sprintf ( "%u", $value ); |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | |
| 383 | 383 | /// sphinx searchd client class |
| 384 | 384 | class SphinxClient |
| 385 | 385 | { |
| 386 | - var $_host; ///< searchd host (default is "localhost") |
|
| 387 | - var $_port; ///< searchd port (default is 9312) |
|
| 388 | - var $_offset; ///< how many records to seek from result-set start (default is 0) |
|
| 389 | - var $_limit; ///< how many records to return from result-set starting at offset (default is 20) |
|
| 390 | - var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) |
|
| 391 | - var $_weights; ///< per-field weights (default is 1 for all fields) |
|
| 392 | - var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) |
|
| 393 | - var $_sortby; ///< attribute to sort by (defualt is "") |
|
| 394 | - var $_min_id; ///< min ID to match (default is 0, which means no limit) |
|
| 395 | - var $_max_id; ///< max ID to match (default is 0, which means no limit) |
|
| 396 | - var $_filters; ///< search filters |
|
| 397 | - var $_groupby; ///< group-by attribute name |
|
| 398 | - var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) |
|
| 399 | - var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) |
|
| 400 | - var $_groupdistinct;///< group-by count-distinct attribute |
|
| 401 | - var $_maxmatches; ///< max matches to retrieve |
|
| 402 | - var $_cutoff; ///< cutoff to stop searching at (default is 0) |
|
| 403 | - var $_retrycount; ///< distributed retries count |
|
| 404 | - var $_retrydelay; ///< distributed retries delay |
|
| 405 | - var $_anchor; ///< geographical anchor point |
|
| 406 | - var $_indexweights; ///< per-index weights |
|
| 407 | - var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) |
|
| 408 | - var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) |
|
| 409 | - var $_fieldweights; ///< per-field-name weights |
|
| 410 | - var $_overrides; ///< per-query attribute values overrides |
|
| 411 | - var $_select; ///< select-list (attributes or expressions, with optional aliases) |
|
| 412 | - |
|
| 413 | - var $_error; ///< last error message |
|
| 414 | - var $_warning; ///< last warning message |
|
| 415 | - var $_connerror; ///< connection error vs remote error flag |
|
| 416 | - |
|
| 417 | - var $_reqs; ///< requests array for multi-query |
|
| 418 | - var $_mbenc; ///< stored mbstring encoding |
|
| 419 | - var $_arrayresult; ///< whether $result["matches"] should be a hash or an array |
|
| 420 | - var $_timeout; ///< connect timeout |
|
| 421 | - |
|
| 422 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 423 | - // common stuff |
|
| 424 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 425 | - |
|
| 426 | - /// create a new client object and fill defaults |
|
| 427 | - public function __construct() |
|
| 428 | - { |
|
| 429 | - // per-client-object settings |
|
| 430 | - $this->_host = "localhost"; |
|
| 431 | - $this->_port = 9312; |
|
| 432 | - $this->_path = false; |
|
| 433 | - $this->_socket = false; |
|
| 434 | - |
|
| 435 | - // per-query settings |
|
| 436 | - $this->_offset = 0; |
|
| 437 | - $this->_limit = 20; |
|
| 438 | - $this->_mode = SPH_MATCH_ALL; |
|
| 439 | - $this->_weights = array (); |
|
| 440 | - $this->_sort = SPH_SORT_RELEVANCE; |
|
| 441 | - $this->_sortby = ""; |
|
| 442 | - $this->_min_id = 0; |
|
| 443 | - $this->_max_id = 0; |
|
| 444 | - $this->_filters = array (); |
|
| 445 | - $this->_groupby = ""; |
|
| 446 | - $this->_groupfunc = SPH_GROUPBY_DAY; |
|
| 447 | - $this->_groupsort = "@group desc"; |
|
| 448 | - $this->_groupdistinct= ""; |
|
| 449 | - $this->_maxmatches = 1000; |
|
| 450 | - $this->_cutoff = 0; |
|
| 451 | - $this->_retrycount = 0; |
|
| 452 | - $this->_retrydelay = 0; |
|
| 453 | - $this->_anchor = array (); |
|
| 454 | - $this->_indexweights= array (); |
|
| 455 | - $this->_ranker = SPH_RANK_PROXIMITY_BM25; |
|
| 456 | - $this->_maxquerytime= 0; |
|
| 457 | - $this->_fieldweights= array(); |
|
| 458 | - $this->_overrides = array(); |
|
| 459 | - $this->_select = "*"; |
|
| 460 | - |
|
| 461 | - $this->_error = ""; // per-reply fields (for single-query case) |
|
| 462 | - $this->_warning = ""; |
|
| 463 | - $this->_connerror = false; |
|
| 464 | - |
|
| 465 | - $this->_reqs = array (); // requests storage (for multi-query case) |
|
| 466 | - $this->_mbenc = ""; |
|
| 467 | - $this->_arrayresult = false; |
|
| 468 | - $this->_timeout = 0; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - public function __destruct() |
|
| 472 | - { |
|
| 473 | - if ( $this->_socket !== false ) |
|
| 474 | - fclose ( $this->_socket ); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /// get last error message (string) |
|
| 478 | - public function GetLastError () |
|
| 479 | - { |
|
| 480 | - return $this->_error; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /// get last warning message (string) |
|
| 484 | - public function GetLastWarning () |
|
| 485 | - { |
|
| 486 | - return $this->_warning; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /// get last error flag (to tell network connection errors from searchd errors or broken responses) |
|
| 490 | - public function IsConnectError() |
|
| 491 | - { |
|
| 492 | - return $this->_connerror; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /// set searchd host name (string) and port (integer) |
|
| 496 | - public function SetServer ( $host, $port = 0 ) |
|
| 497 | - { |
|
| 498 | - assert ( is_string($host) ); |
|
| 499 | - if ( $host[0] == '/') |
|
| 500 | - { |
|
| 501 | - $this->_path = 'unix://' . $host; |
|
| 502 | - return; |
|
| 503 | - } |
|
| 504 | - if ( substr ( $host, 0, 7 )=="unix://" ) |
|
| 505 | - { |
|
| 506 | - $this->_path = $host; |
|
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - assert ( is_int($port) ); |
|
| 511 | - $this->_host = $host; |
|
| 512 | - $this->_port = $port; |
|
| 513 | - $this->_path = ''; |
|
| 514 | - |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /// set server connection timeout (0 to remove) |
|
| 518 | - public function SetConnectTimeout ( $timeout ) |
|
| 519 | - { |
|
| 520 | - assert ( is_numeric($timeout) ); |
|
| 521 | - $this->_timeout = $timeout; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - public function _Send ( $handle, $data, $length ) |
|
| 526 | - { |
|
| 527 | - if ( feof($handle) || fwrite ( $handle, $data, $length ) !== $length ) |
|
| 528 | - { |
|
| 529 | - $this->_error = 'connection unexpectedly closed (timed out?)'; |
|
| 530 | - $this->_connerror = true; |
|
| 531 | - return false; |
|
| 532 | - } |
|
| 533 | - return true; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 537 | - |
|
| 538 | - /// enter mbstring workaround mode |
|
| 539 | - public function _MBPush () |
|
| 540 | - { |
|
| 541 | - $this->_mbenc = ""; |
|
| 542 | - if ( ini_get ( "mbstring.func_overload" ) & 2 ) |
|
| 543 | - { |
|
| 544 | - $this->_mbenc = mb_internal_encoding(); |
|
| 545 | - mb_internal_encoding ( "latin1" ); |
|
| 546 | - } |
|
| 386 | + var $_host; ///< searchd host (default is "localhost") |
|
| 387 | + var $_port; ///< searchd port (default is 9312) |
|
| 388 | + var $_offset; ///< how many records to seek from result-set start (default is 0) |
|
| 389 | + var $_limit; ///< how many records to return from result-set starting at offset (default is 20) |
|
| 390 | + var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) |
|
| 391 | + var $_weights; ///< per-field weights (default is 1 for all fields) |
|
| 392 | + var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) |
|
| 393 | + var $_sortby; ///< attribute to sort by (defualt is "") |
|
| 394 | + var $_min_id; ///< min ID to match (default is 0, which means no limit) |
|
| 395 | + var $_max_id; ///< max ID to match (default is 0, which means no limit) |
|
| 396 | + var $_filters; ///< search filters |
|
| 397 | + var $_groupby; ///< group-by attribute name |
|
| 398 | + var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) |
|
| 399 | + var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) |
|
| 400 | + var $_groupdistinct;///< group-by count-distinct attribute |
|
| 401 | + var $_maxmatches; ///< max matches to retrieve |
|
| 402 | + var $_cutoff; ///< cutoff to stop searching at (default is 0) |
|
| 403 | + var $_retrycount; ///< distributed retries count |
|
| 404 | + var $_retrydelay; ///< distributed retries delay |
|
| 405 | + var $_anchor; ///< geographical anchor point |
|
| 406 | + var $_indexweights; ///< per-index weights |
|
| 407 | + var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) |
|
| 408 | + var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) |
|
| 409 | + var $_fieldweights; ///< per-field-name weights |
|
| 410 | + var $_overrides; ///< per-query attribute values overrides |
|
| 411 | + var $_select; ///< select-list (attributes or expressions, with optional aliases) |
|
| 412 | + |
|
| 413 | + var $_error; ///< last error message |
|
| 414 | + var $_warning; ///< last warning message |
|
| 415 | + var $_connerror; ///< connection error vs remote error flag |
|
| 416 | + |
|
| 417 | + var $_reqs; ///< requests array for multi-query |
|
| 418 | + var $_mbenc; ///< stored mbstring encoding |
|
| 419 | + var $_arrayresult; ///< whether $result["matches"] should be a hash or an array |
|
| 420 | + var $_timeout; ///< connect timeout |
|
| 421 | + |
|
| 422 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 423 | + // common stuff |
|
| 424 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 425 | + |
|
| 426 | + /// create a new client object and fill defaults |
|
| 427 | + public function __construct() |
|
| 428 | + { |
|
| 429 | + // per-client-object settings |
|
| 430 | + $this->_host = "localhost"; |
|
| 431 | + $this->_port = 9312; |
|
| 432 | + $this->_path = false; |
|
| 433 | + $this->_socket = false; |
|
| 434 | + |
|
| 435 | + // per-query settings |
|
| 436 | + $this->_offset = 0; |
|
| 437 | + $this->_limit = 20; |
|
| 438 | + $this->_mode = SPH_MATCH_ALL; |
|
| 439 | + $this->_weights = array (); |
|
| 440 | + $this->_sort = SPH_SORT_RELEVANCE; |
|
| 441 | + $this->_sortby = ""; |
|
| 442 | + $this->_min_id = 0; |
|
| 443 | + $this->_max_id = 0; |
|
| 444 | + $this->_filters = array (); |
|
| 445 | + $this->_groupby = ""; |
|
| 446 | + $this->_groupfunc = SPH_GROUPBY_DAY; |
|
| 447 | + $this->_groupsort = "@group desc"; |
|
| 448 | + $this->_groupdistinct= ""; |
|
| 449 | + $this->_maxmatches = 1000; |
|
| 450 | + $this->_cutoff = 0; |
|
| 451 | + $this->_retrycount = 0; |
|
| 452 | + $this->_retrydelay = 0; |
|
| 453 | + $this->_anchor = array (); |
|
| 454 | + $this->_indexweights= array (); |
|
| 455 | + $this->_ranker = SPH_RANK_PROXIMITY_BM25; |
|
| 456 | + $this->_maxquerytime= 0; |
|
| 457 | + $this->_fieldweights= array(); |
|
| 458 | + $this->_overrides = array(); |
|
| 459 | + $this->_select = "*"; |
|
| 460 | + |
|
| 461 | + $this->_error = ""; // per-reply fields (for single-query case) |
|
| 462 | + $this->_warning = ""; |
|
| 463 | + $this->_connerror = false; |
|
| 464 | + |
|
| 465 | + $this->_reqs = array (); // requests storage (for multi-query case) |
|
| 466 | + $this->_mbenc = ""; |
|
| 467 | + $this->_arrayresult = false; |
|
| 468 | + $this->_timeout = 0; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + public function __destruct() |
|
| 472 | + { |
|
| 473 | + if ( $this->_socket !== false ) |
|
| 474 | + fclose ( $this->_socket ); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /// get last error message (string) |
|
| 478 | + public function GetLastError () |
|
| 479 | + { |
|
| 480 | + return $this->_error; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /// get last warning message (string) |
|
| 484 | + public function GetLastWarning () |
|
| 485 | + { |
|
| 486 | + return $this->_warning; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /// get last error flag (to tell network connection errors from searchd errors or broken responses) |
|
| 490 | + public function IsConnectError() |
|
| 491 | + { |
|
| 492 | + return $this->_connerror; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /// set searchd host name (string) and port (integer) |
|
| 496 | + public function SetServer ( $host, $port = 0 ) |
|
| 497 | + { |
|
| 498 | + assert ( is_string($host) ); |
|
| 499 | + if ( $host[0] == '/') |
|
| 500 | + { |
|
| 501 | + $this->_path = 'unix://' . $host; |
|
| 502 | + return; |
|
| 503 | + } |
|
| 504 | + if ( substr ( $host, 0, 7 )=="unix://" ) |
|
| 505 | + { |
|
| 506 | + $this->_path = $host; |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + assert ( is_int($port) ); |
|
| 511 | + $this->_host = $host; |
|
| 512 | + $this->_port = $port; |
|
| 513 | + $this->_path = ''; |
|
| 514 | + |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /// set server connection timeout (0 to remove) |
|
| 518 | + public function SetConnectTimeout ( $timeout ) |
|
| 519 | + { |
|
| 520 | + assert ( is_numeric($timeout) ); |
|
| 521 | + $this->_timeout = $timeout; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + public function _Send ( $handle, $data, $length ) |
|
| 526 | + { |
|
| 527 | + if ( feof($handle) || fwrite ( $handle, $data, $length ) !== $length ) |
|
| 528 | + { |
|
| 529 | + $this->_error = 'connection unexpectedly closed (timed out?)'; |
|
| 530 | + $this->_connerror = true; |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | + return true; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 537 | + |
|
| 538 | + /// enter mbstring workaround mode |
|
| 539 | + public function _MBPush () |
|
| 540 | + { |
|
| 541 | + $this->_mbenc = ""; |
|
| 542 | + if ( ini_get ( "mbstring.func_overload" ) & 2 ) |
|
| 543 | + { |
|
| 544 | + $this->_mbenc = mb_internal_encoding(); |
|
| 545 | + mb_internal_encoding ( "latin1" ); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /// leave mbstring workaround mode |
|
| 550 | + public function _MBPop () |
|
| 551 | + { |
|
| 552 | + if ( $this->_mbenc ) |
|
| 553 | + mb_internal_encoding ( $this->_mbenc ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /// connect to searchd server |
|
| 557 | + public function _Connect () |
|
| 558 | + { |
|
| 559 | + if ( $this->_socket!==false ) |
|
| 560 | + { |
|
| 561 | + // we are in persistent connection mode, so we have a socket |
|
| 562 | + // however, need to check whether it's still alive |
|
| 563 | + if ( !@feof ( $this->_socket ) ) |
|
| 564 | + return $this->_socket; |
|
| 565 | + |
|
| 566 | + // force reopen |
|
| 567 | + $this->_socket = false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + $errno = 0; |
|
| 571 | + $errstr = ""; |
|
| 572 | + $this->_connerror = false; |
|
| 573 | + |
|
| 574 | + if ( $this->_path ) |
|
| 575 | + { |
|
| 576 | + $host = $this->_path; |
|
| 577 | + $port = 0; |
|
| 578 | + } |
|
| 579 | + else |
|
| 580 | + { |
|
| 581 | + $host = $this->_host; |
|
| 582 | + $port = $this->_port; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + if ( $this->_timeout<=0 ) |
|
| 586 | + $fp = @fsockopen ( $host, $port, $errno, $errstr ); |
|
| 587 | + else |
|
| 588 | + $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); |
|
| 589 | + |
|
| 590 | + if ( !$fp ) |
|
| 591 | + { |
|
| 592 | + if ( $this->_path ) |
|
| 593 | + $location = $this->_path; |
|
| 594 | + else |
|
| 595 | + $location = "{$this->_host}:{$this->_port}"; |
|
| 596 | + |
|
| 597 | + $errstr = trim ( $errstr ); |
|
| 598 | + $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; |
|
| 599 | + $this->_connerror = true; |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + // send my version |
|
| 604 | + // this is a subtle part. we must do it before (!) reading back from searchd. |
|
| 605 | + // because otherwise under some conditions (reported on FreeBSD for instance) |
|
| 606 | + // TCP stack could throttle write-write-read pattern because of Nagle. |
|
| 607 | + if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) ) |
|
| 608 | + { |
|
| 609 | + fclose ( $fp ); |
|
| 610 | + $this->_error = "failed to send client protocol version"; |
|
| 611 | + return false; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // check version |
|
| 615 | + list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); |
|
| 616 | + $v = (int)$v; |
|
| 617 | + if ( $v<1 ) |
|
| 618 | + { |
|
| 619 | + fclose ( $fp ); |
|
| 620 | + $this->_error = "expected searchd protocol version 1+, got version '$v'"; |
|
| 621 | + return false; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + return $fp; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /// get and check response packet from searchd server |
|
| 628 | + public function _GetResponse ( $fp, $client_ver ) |
|
| 629 | + { |
|
| 630 | + $response = ""; |
|
| 631 | + $len = 0; |
|
| 632 | + |
|
| 633 | + $header = fread ( $fp, 8 ); |
|
| 634 | + if ( strlen($header)==8 ) |
|
| 635 | + { |
|
| 636 | + list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); |
|
| 637 | + $left = $len; |
|
| 638 | + while ( $left>0 && !feof($fp) ) |
|
| 639 | + { |
|
| 640 | + $chunk = fread ( $fp, min ( 8192, $left ) ); |
|
| 641 | + if ( $chunk ) |
|
| 642 | + { |
|
| 643 | + $response .= $chunk; |
|
| 644 | + $left -= strlen($chunk); |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + if ( $this->_socket === false ) |
|
| 649 | + fclose ( $fp ); |
|
| 650 | + |
|
| 651 | + // check response |
|
| 652 | + $read = strlen ( $response ); |
|
| 653 | + if ( !$response || $read!=$len ) |
|
| 654 | + { |
|
| 655 | + $this->_error = $len |
|
| 656 | + ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" |
|
| 657 | + : "received zero-sized searchd response"; |
|
| 658 | + return false; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + // check status |
|
| 662 | + if ( $status==SEARCHD_WARNING ) |
|
| 663 | + { |
|
| 664 | + list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); |
|
| 665 | + $this->_warning = substr ( $response, 4, $wlen ); |
|
| 666 | + return substr ( $response, 4+$wlen ); |
|
| 667 | + } |
|
| 668 | + if ( $status==SEARCHD_ERROR ) |
|
| 669 | + { |
|
| 670 | + $this->_error = "searchd error: " . substr ( $response, 4 ); |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + if ( $status==SEARCHD_RETRY ) |
|
| 674 | + { |
|
| 675 | + $this->_error = "temporary searchd error: " . substr ( $response, 4 ); |
|
| 676 | + return false; |
|
| 677 | + } |
|
| 678 | + if ( $status!=SEARCHD_OK ) |
|
| 679 | + { |
|
| 680 | + $this->_error = "unknown status code '$status'"; |
|
| 681 | + return false; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // check version |
|
| 685 | + if ( $ver<$client_ver ) |
|
| 686 | + { |
|
| 687 | + $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", |
|
| 688 | + $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + return $response; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 695 | + // searching |
|
| 696 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 697 | + |
|
| 698 | + /// set offset and count into result set, |
|
| 699 | + /// and optionally set max-matches and cutoff limits |
|
| 700 | + public function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) |
|
| 701 | + { |
|
| 702 | + assert ( is_int($offset) ); |
|
| 703 | + assert ( is_int($limit) ); |
|
| 704 | + assert ( $offset>=0 ); |
|
| 705 | + assert ( $limit>0 ); |
|
| 706 | + assert ( $max>=0 ); |
|
| 707 | + $this->_offset = $offset; |
|
| 708 | + $this->_limit = $limit; |
|
| 709 | + if ( $max>0 ) |
|
| 710 | + $this->_maxmatches = $max; |
|
| 711 | + if ( $cutoff>0 ) |
|
| 712 | + $this->_cutoff = $cutoff; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + /// set maximum query time, in milliseconds, per-index |
|
| 716 | + /// integer, 0 means "do not limit" |
|
| 717 | + public function SetMaxQueryTime ( $max ) |
|
| 718 | + { |
|
| 719 | + assert ( is_int($max) ); |
|
| 720 | + assert ( $max>=0 ); |
|
| 721 | + $this->_maxquerytime = $max; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /// set matching mode |
|
| 725 | + public function SetMatchMode ( $mode ) |
|
| 726 | + { |
|
| 727 | + assert ( $mode==SPH_MATCH_ALL |
|
| 728 | + || $mode==SPH_MATCH_ANY |
|
| 729 | + || $mode==SPH_MATCH_PHRASE |
|
| 730 | + || $mode==SPH_MATCH_BOOLEAN |
|
| 731 | + || $mode==SPH_MATCH_EXTENDED |
|
| 732 | + || $mode==SPH_MATCH_FULLSCAN |
|
| 733 | + || $mode==SPH_MATCH_EXTENDED2 ); |
|
| 734 | + $this->_mode = $mode; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /// set ranking mode |
|
| 738 | + public function SetRankingMode ( $ranker ) |
|
| 739 | + { |
|
| 740 | + assert ( $ranker>=0 && $ranker<SPH_RANK_TOTAL ); |
|
| 741 | + $this->_ranker = $ranker; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /// set matches sorting mode |
|
| 745 | + public function SetSortMode ( $mode, $sortby="" ) |
|
| 746 | + { |
|
| 747 | + assert ( |
|
| 748 | + $mode==SPH_SORT_RELEVANCE || |
|
| 749 | + $mode==SPH_SORT_ATTR_DESC || |
|
| 750 | + $mode==SPH_SORT_ATTR_ASC || |
|
| 751 | + $mode==SPH_SORT_TIME_SEGMENTS || |
|
| 752 | + $mode==SPH_SORT_EXTENDED || |
|
| 753 | + $mode==SPH_SORT_EXPR ); |
|
| 754 | + assert ( is_string($sortby) ); |
|
| 755 | + assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); |
|
| 756 | + |
|
| 757 | + $this->_sort = $mode; |
|
| 758 | + $this->_sortby = $sortby; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /// bind per-field weights by order |
|
| 762 | + /// DEPRECATED; use SetFieldWeights() instead |
|
| 763 | + public function SetWeights ( $weights ) |
|
| 764 | + { |
|
| 765 | + assert ( is_array($weights) ); |
|
| 766 | + foreach ( $weights as $weight ) |
|
| 767 | + assert ( is_int($weight) ); |
|
| 768 | + |
|
| 769 | + $this->_weights = $weights; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + /// bind per-field weights by name |
|
| 773 | + public function SetFieldWeights ( $weights ) |
|
| 774 | + { |
|
| 775 | + assert ( is_array($weights) ); |
|
| 776 | + foreach ( $weights as $name=>$weight ) |
|
| 777 | + { |
|
| 778 | + assert ( is_string($name) ); |
|
| 779 | + assert ( is_int($weight) ); |
|
| 780 | + } |
|
| 781 | + $this->_fieldweights = $weights; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + /// bind per-index weights by name |
|
| 785 | + public function SetIndexWeights ( $weights ) |
|
| 786 | + { |
|
| 787 | + assert ( is_array($weights) ); |
|
| 788 | + foreach ( $weights as $index=>$weight ) |
|
| 789 | + { |
|
| 790 | + assert ( is_string($index) ); |
|
| 791 | + assert ( is_int($weight) ); |
|
| 792 | + } |
|
| 793 | + $this->_indexweights = $weights; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + /// set IDs range to match |
|
| 797 | + /// only match records if document ID is beetwen $min and $max (inclusive) |
|
| 798 | + public function SetIDRange ( $min, $max ) |
|
| 799 | + { |
|
| 800 | + assert ( is_numeric($min) ); |
|
| 801 | + assert ( is_numeric($max) ); |
|
| 802 | + assert ( $min<=$max ); |
|
| 803 | + $this->_min_id = $min; |
|
| 804 | + $this->_max_id = $max; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + /// set values set filter |
|
| 808 | + /// only match records where $attribute value is in given set |
|
| 809 | + public function SetFilter ( $attribute, $values, $exclude=false ) |
|
| 810 | + { |
|
| 811 | + assert ( is_string($attribute) ); |
|
| 812 | + assert ( is_array($values) ); |
|
| 813 | + assert ( count($values) ); |
|
| 814 | + |
|
| 815 | + if ( is_array($values) && count($values) ) |
|
| 816 | + { |
|
| 817 | + foreach ( $values as $value ) |
|
| 818 | + assert ( is_numeric($value) ); |
|
| 819 | + |
|
| 820 | + $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + /// set range filter |
|
| 825 | + /// only match records if $attribute value is beetwen $min and $max (inclusive) |
|
| 826 | + public function SetFilterRange ( $attribute, $min, $max, $exclude=false ) |
|
| 827 | + { |
|
| 828 | + assert ( is_string($attribute) ); |
|
| 829 | + assert ( is_numeric($min) ); |
|
| 830 | + assert ( is_numeric($max) ); |
|
| 831 | + assert ( $min<=$max ); |
|
| 832 | + |
|
| 833 | + $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + /// set float range filter |
|
| 837 | + /// only match records if $attribute value is beetwen $min and $max (inclusive) |
|
| 838 | + public function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) |
|
| 839 | + { |
|
| 840 | + assert ( is_string($attribute) ); |
|
| 841 | + assert ( is_float($min) ); |
|
| 842 | + assert ( is_float($max) ); |
|
| 843 | + assert ( $min<=$max ); |
|
| 844 | + |
|
| 845 | + $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + /// setup anchor point for geosphere distance calculations |
|
| 849 | + /// required to use @geodist in filters and sorting |
|
| 850 | + /// latitude and longitude must be in radians |
|
| 851 | + public function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) |
|
| 852 | + { |
|
| 853 | + assert ( is_string($attrlat) ); |
|
| 854 | + assert ( is_string($attrlong) ); |
|
| 855 | + assert ( is_float($lat) ); |
|
| 856 | + assert ( is_float($long) ); |
|
| 857 | + |
|
| 858 | + $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + /// set grouping attribute and function |
|
| 862 | + public function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) |
|
| 863 | + { |
|
| 864 | + assert ( is_string($attribute) ); |
|
| 865 | + assert ( is_string($groupsort) ); |
|
| 866 | + assert ( $func==SPH_GROUPBY_DAY |
|
| 867 | + || $func==SPH_GROUPBY_WEEK |
|
| 868 | + || $func==SPH_GROUPBY_MONTH |
|
| 869 | + || $func==SPH_GROUPBY_YEAR |
|
| 870 | + || $func==SPH_GROUPBY_ATTR |
|
| 871 | + || $func==SPH_GROUPBY_ATTRPAIR ); |
|
| 872 | + |
|
| 873 | + $this->_groupby = $attribute; |
|
| 874 | + $this->_groupfunc = $func; |
|
| 875 | + $this->_groupsort = $groupsort; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + /// set count-distinct attribute for group-by queries |
|
| 879 | + public function SetGroupDistinct ( $attribute ) |
|
| 880 | + { |
|
| 881 | + assert ( is_string($attribute) ); |
|
| 882 | + $this->_groupdistinct = $attribute; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + /// set distributed retries count and delay |
|
| 886 | + public function SetRetries ( $count, $delay=0 ) |
|
| 887 | + { |
|
| 888 | + assert ( is_int($count) && $count>=0 ); |
|
| 889 | + assert ( is_int($delay) && $delay>=0 ); |
|
| 890 | + $this->_retrycount = $count; |
|
| 891 | + $this->_retrydelay = $delay; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /// set result set format (hash or array; hash by default) |
|
| 895 | + /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs |
|
| 896 | + public function SetArrayResult ( $arrayresult ) |
|
| 897 | + { |
|
| 898 | + assert ( is_bool($arrayresult) ); |
|
| 899 | + $this->_arrayresult = $arrayresult; |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + /// set attribute values override |
|
| 903 | + /// there can be only one override per attribute |
|
| 904 | + /// $values must be a hash that maps document IDs to attribute values |
|
| 905 | + public function SetOverride ( $attrname, $attrtype, $values ) |
|
| 906 | + { |
|
| 907 | + assert ( is_string ( $attrname ) ); |
|
| 908 | + assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) ); |
|
| 909 | + assert ( is_array ( $values ) ); |
|
| 910 | + |
|
| 911 | + $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values ); |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + /// set select-list (attributes or expressions), SQL-like syntax |
|
| 915 | + public function SetSelect ( $select ) |
|
| 916 | + { |
|
| 917 | + assert ( is_string ( $select ) ); |
|
| 918 | + $this->_select = $select; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + ////////////////////////////////////////////////////////////////////////////// |
|
| 922 | + |
|
| 923 | + /// clear all filters (for multi-queries) |
|
| 924 | + public function ResetFilters () |
|
| 925 | + { |
|
| 926 | + $this->_filters = array(); |
|
| 927 | + $this->_anchor = array(); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /// clear groupby settings (for multi-queries) |
|
| 931 | + public function ResetGroupBy () |
|
| 932 | + { |
|
| 933 | + $this->_groupby = ""; |
|
| 934 | + $this->_groupfunc = SPH_GROUPBY_DAY; |
|
| 935 | + $this->_groupsort = "@group desc"; |
|
| 936 | + $this->_groupdistinct= ""; |
|
| 547 | 937 | } |
| 548 | 938 | |
| 549 | - /// leave mbstring workaround mode |
|
| 550 | - public function _MBPop () |
|
| 551 | - { |
|
| 552 | - if ( $this->_mbenc ) |
|
| 553 | - mb_internal_encoding ( $this->_mbenc ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /// connect to searchd server |
|
| 557 | - public function _Connect () |
|
| 558 | - { |
|
| 559 | - if ( $this->_socket!==false ) |
|
| 560 | - { |
|
| 561 | - // we are in persistent connection mode, so we have a socket |
|
| 562 | - // however, need to check whether it's still alive |
|
| 563 | - if ( !@feof ( $this->_socket ) ) |
|
| 564 | - return $this->_socket; |
|
| 565 | - |
|
| 566 | - // force reopen |
|
| 567 | - $this->_socket = false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - $errno = 0; |
|
| 571 | - $errstr = ""; |
|
| 572 | - $this->_connerror = false; |
|
| 573 | - |
|
| 574 | - if ( $this->_path ) |
|
| 575 | - { |
|
| 576 | - $host = $this->_path; |
|
| 577 | - $port = 0; |
|
| 578 | - } |
|
| 579 | - else |
|
| 580 | - { |
|
| 581 | - $host = $this->_host; |
|
| 582 | - $port = $this->_port; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - if ( $this->_timeout<=0 ) |
|
| 586 | - $fp = @fsockopen ( $host, $port, $errno, $errstr ); |
|
| 587 | - else |
|
| 588 | - $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); |
|
| 589 | - |
|
| 590 | - if ( !$fp ) |
|
| 591 | - { |
|
| 592 | - if ( $this->_path ) |
|
| 593 | - $location = $this->_path; |
|
| 594 | - else |
|
| 595 | - $location = "{$this->_host}:{$this->_port}"; |
|
| 596 | - |
|
| 597 | - $errstr = trim ( $errstr ); |
|
| 598 | - $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; |
|
| 599 | - $this->_connerror = true; |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - // send my version |
|
| 604 | - // this is a subtle part. we must do it before (!) reading back from searchd. |
|
| 605 | - // because otherwise under some conditions (reported on FreeBSD for instance) |
|
| 606 | - // TCP stack could throttle write-write-read pattern because of Nagle. |
|
| 607 | - if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) ) |
|
| 608 | - { |
|
| 609 | - fclose ( $fp ); |
|
| 610 | - $this->_error = "failed to send client protocol version"; |
|
| 611 | - return false; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // check version |
|
| 615 | - list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); |
|
| 616 | - $v = (int)$v; |
|
| 617 | - if ( $v<1 ) |
|
| 618 | - { |
|
| 619 | - fclose ( $fp ); |
|
| 620 | - $this->_error = "expected searchd protocol version 1+, got version '$v'"; |
|
| 621 | - return false; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - return $fp; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /// get and check response packet from searchd server |
|
| 628 | - public function _GetResponse ( $fp, $client_ver ) |
|
| 629 | - { |
|
| 630 | - $response = ""; |
|
| 631 | - $len = 0; |
|
| 632 | - |
|
| 633 | - $header = fread ( $fp, 8 ); |
|
| 634 | - if ( strlen($header)==8 ) |
|
| 635 | - { |
|
| 636 | - list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); |
|
| 637 | - $left = $len; |
|
| 638 | - while ( $left>0 && !feof($fp) ) |
|
| 639 | - { |
|
| 640 | - $chunk = fread ( $fp, min ( 8192, $left ) ); |
|
| 641 | - if ( $chunk ) |
|
| 642 | - { |
|
| 643 | - $response .= $chunk; |
|
| 644 | - $left -= strlen($chunk); |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - if ( $this->_socket === false ) |
|
| 649 | - fclose ( $fp ); |
|
| 650 | - |
|
| 651 | - // check response |
|
| 652 | - $read = strlen ( $response ); |
|
| 653 | - if ( !$response || $read!=$len ) |
|
| 654 | - { |
|
| 655 | - $this->_error = $len |
|
| 656 | - ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" |
|
| 657 | - : "received zero-sized searchd response"; |
|
| 658 | - return false; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - // check status |
|
| 662 | - if ( $status==SEARCHD_WARNING ) |
|
| 663 | - { |
|
| 664 | - list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); |
|
| 665 | - $this->_warning = substr ( $response, 4, $wlen ); |
|
| 666 | - return substr ( $response, 4+$wlen ); |
|
| 667 | - } |
|
| 668 | - if ( $status==SEARCHD_ERROR ) |
|
| 669 | - { |
|
| 670 | - $this->_error = "searchd error: " . substr ( $response, 4 ); |
|
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - if ( $status==SEARCHD_RETRY ) |
|
| 674 | - { |
|
| 675 | - $this->_error = "temporary searchd error: " . substr ( $response, 4 ); |
|
| 676 | - return false; |
|
| 677 | - } |
|
| 678 | - if ( $status!=SEARCHD_OK ) |
|
| 679 | - { |
|
| 680 | - $this->_error = "unknown status code '$status'"; |
|
| 681 | - return false; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // check version |
|
| 685 | - if ( $ver<$client_ver ) |
|
| 686 | - { |
|
| 687 | - $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", |
|
| 688 | - $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - return $response; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 695 | - // searching |
|
| 696 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 697 | - |
|
| 698 | - /// set offset and count into result set, |
|
| 699 | - /// and optionally set max-matches and cutoff limits |
|
| 700 | - public function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) |
|
| 701 | - { |
|
| 702 | - assert ( is_int($offset) ); |
|
| 703 | - assert ( is_int($limit) ); |
|
| 704 | - assert ( $offset>=0 ); |
|
| 705 | - assert ( $limit>0 ); |
|
| 706 | - assert ( $max>=0 ); |
|
| 707 | - $this->_offset = $offset; |
|
| 708 | - $this->_limit = $limit; |
|
| 709 | - if ( $max>0 ) |
|
| 710 | - $this->_maxmatches = $max; |
|
| 711 | - if ( $cutoff>0 ) |
|
| 712 | - $this->_cutoff = $cutoff; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - /// set maximum query time, in milliseconds, per-index |
|
| 716 | - /// integer, 0 means "do not limit" |
|
| 717 | - public function SetMaxQueryTime ( $max ) |
|
| 718 | - { |
|
| 719 | - assert ( is_int($max) ); |
|
| 720 | - assert ( $max>=0 ); |
|
| 721 | - $this->_maxquerytime = $max; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /// set matching mode |
|
| 725 | - public function SetMatchMode ( $mode ) |
|
| 726 | - { |
|
| 727 | - assert ( $mode==SPH_MATCH_ALL |
|
| 728 | - || $mode==SPH_MATCH_ANY |
|
| 729 | - || $mode==SPH_MATCH_PHRASE |
|
| 730 | - || $mode==SPH_MATCH_BOOLEAN |
|
| 731 | - || $mode==SPH_MATCH_EXTENDED |
|
| 732 | - || $mode==SPH_MATCH_FULLSCAN |
|
| 733 | - || $mode==SPH_MATCH_EXTENDED2 ); |
|
| 734 | - $this->_mode = $mode; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /// set ranking mode |
|
| 738 | - public function SetRankingMode ( $ranker ) |
|
| 739 | - { |
|
| 740 | - assert ( $ranker>=0 && $ranker<SPH_RANK_TOTAL ); |
|
| 741 | - $this->_ranker = $ranker; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /// set matches sorting mode |
|
| 745 | - public function SetSortMode ( $mode, $sortby="" ) |
|
| 746 | - { |
|
| 747 | - assert ( |
|
| 748 | - $mode==SPH_SORT_RELEVANCE || |
|
| 749 | - $mode==SPH_SORT_ATTR_DESC || |
|
| 750 | - $mode==SPH_SORT_ATTR_ASC || |
|
| 751 | - $mode==SPH_SORT_TIME_SEGMENTS || |
|
| 752 | - $mode==SPH_SORT_EXTENDED || |
|
| 753 | - $mode==SPH_SORT_EXPR ); |
|
| 754 | - assert ( is_string($sortby) ); |
|
| 755 | - assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); |
|
| 756 | - |
|
| 757 | - $this->_sort = $mode; |
|
| 758 | - $this->_sortby = $sortby; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /// bind per-field weights by order |
|
| 762 | - /// DEPRECATED; use SetFieldWeights() instead |
|
| 763 | - public function SetWeights ( $weights ) |
|
| 764 | - { |
|
| 765 | - assert ( is_array($weights) ); |
|
| 766 | - foreach ( $weights as $weight ) |
|
| 767 | - assert ( is_int($weight) ); |
|
| 768 | - |
|
| 769 | - $this->_weights = $weights; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - /// bind per-field weights by name |
|
| 773 | - public function SetFieldWeights ( $weights ) |
|
| 774 | - { |
|
| 775 | - assert ( is_array($weights) ); |
|
| 776 | - foreach ( $weights as $name=>$weight ) |
|
| 777 | - { |
|
| 778 | - assert ( is_string($name) ); |
|
| 779 | - assert ( is_int($weight) ); |
|
| 780 | - } |
|
| 781 | - $this->_fieldweights = $weights; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - /// bind per-index weights by name |
|
| 785 | - public function SetIndexWeights ( $weights ) |
|
| 786 | - { |
|
| 787 | - assert ( is_array($weights) ); |
|
| 788 | - foreach ( $weights as $index=>$weight ) |
|
| 789 | - { |
|
| 790 | - assert ( is_string($index) ); |
|
| 791 | - assert ( is_int($weight) ); |
|
| 792 | - } |
|
| 793 | - $this->_indexweights = $weights; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - /// set IDs range to match |
|
| 797 | - /// only match records if document ID is beetwen $min and $max (inclusive) |
|
| 798 | - public function SetIDRange ( $min, $max ) |
|
| 799 | - { |
|
| 800 | - assert ( is_numeric($min) ); |
|
| 801 | - assert ( is_numeric($max) ); |
|
| 802 | - assert ( $min<=$max ); |
|
| 803 | - $this->_min_id = $min; |
|
| 804 | - $this->_max_id = $max; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - /// set values set filter |
|
| 808 | - /// only match records where $attribute value is in given set |
|
| 809 | - public function SetFilter ( $attribute, $values, $exclude=false ) |
|
| 810 | - { |
|
| 811 | - assert ( is_string($attribute) ); |
|
| 812 | - assert ( is_array($values) ); |
|
| 813 | - assert ( count($values) ); |
|
| 814 | - |
|
| 815 | - if ( is_array($values) && count($values) ) |
|
| 816 | - { |
|
| 817 | - foreach ( $values as $value ) |
|
| 818 | - assert ( is_numeric($value) ); |
|
| 819 | - |
|
| 820 | - $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - /// set range filter |
|
| 825 | - /// only match records if $attribute value is beetwen $min and $max (inclusive) |
|
| 826 | - public function SetFilterRange ( $attribute, $min, $max, $exclude=false ) |
|
| 827 | - { |
|
| 828 | - assert ( is_string($attribute) ); |
|
| 829 | - assert ( is_numeric($min) ); |
|
| 830 | - assert ( is_numeric($max) ); |
|
| 831 | - assert ( $min<=$max ); |
|
| 832 | - |
|
| 833 | - $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - /// set float range filter |
|
| 837 | - /// only match records if $attribute value is beetwen $min and $max (inclusive) |
|
| 838 | - public function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) |
|
| 839 | - { |
|
| 840 | - assert ( is_string($attribute) ); |
|
| 841 | - assert ( is_float($min) ); |
|
| 842 | - assert ( is_float($max) ); |
|
| 843 | - assert ( $min<=$max ); |
|
| 844 | - |
|
| 845 | - $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - /// setup anchor point for geosphere distance calculations |
|
| 849 | - /// required to use @geodist in filters and sorting |
|
| 850 | - /// latitude and longitude must be in radians |
|
| 851 | - public function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) |
|
| 852 | - { |
|
| 853 | - assert ( is_string($attrlat) ); |
|
| 854 | - assert ( is_string($attrlong) ); |
|
| 855 | - assert ( is_float($lat) ); |
|
| 856 | - assert ( is_float($long) ); |
|
| 857 | - |
|
| 858 | - $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - /// set grouping attribute and function |
|
| 862 | - public function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) |
|
| 863 | - { |
|
| 864 | - assert ( is_string($attribute) ); |
|
| 865 | - assert ( is_string($groupsort) ); |
|
| 866 | - assert ( $func==SPH_GROUPBY_DAY |
|
| 867 | - || $func==SPH_GROUPBY_WEEK |
|
| 868 | - || $func==SPH_GROUPBY_MONTH |
|
| 869 | - || $func==SPH_GROUPBY_YEAR |
|
| 870 | - || $func==SPH_GROUPBY_ATTR |
|
| 871 | - || $func==SPH_GROUPBY_ATTRPAIR ); |
|
| 872 | - |
|
| 873 | - $this->_groupby = $attribute; |
|
| 874 | - $this->_groupfunc = $func; |
|
| 875 | - $this->_groupsort = $groupsort; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - /// set count-distinct attribute for group-by queries |
|
| 879 | - public function SetGroupDistinct ( $attribute ) |
|
| 880 | - { |
|
| 881 | - assert ( is_string($attribute) ); |
|
| 882 | - $this->_groupdistinct = $attribute; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - /// set distributed retries count and delay |
|
| 886 | - public function SetRetries ( $count, $delay=0 ) |
|
| 887 | - { |
|
| 888 | - assert ( is_int($count) && $count>=0 ); |
|
| 889 | - assert ( is_int($delay) && $delay>=0 ); |
|
| 890 | - $this->_retrycount = $count; |
|
| 891 | - $this->_retrydelay = $delay; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /// set result set format (hash or array; hash by default) |
|
| 895 | - /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs |
|
| 896 | - public function SetArrayResult ( $arrayresult ) |
|
| 897 | - { |
|
| 898 | - assert ( is_bool($arrayresult) ); |
|
| 899 | - $this->_arrayresult = $arrayresult; |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - /// set attribute values override |
|
| 903 | - /// there can be only one override per attribute |
|
| 904 | - /// $values must be a hash that maps document IDs to attribute values |
|
| 905 | - public function SetOverride ( $attrname, $attrtype, $values ) |
|
| 906 | - { |
|
| 907 | - assert ( is_string ( $attrname ) ); |
|
| 908 | - assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) ); |
|
| 909 | - assert ( is_array ( $values ) ); |
|
| 910 | - |
|
| 911 | - $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values ); |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - /// set select-list (attributes or expressions), SQL-like syntax |
|
| 915 | - public function SetSelect ( $select ) |
|
| 916 | - { |
|
| 917 | - assert ( is_string ( $select ) ); |
|
| 918 | - $this->_select = $select; |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - ////////////////////////////////////////////////////////////////////////////// |
|
| 922 | - |
|
| 923 | - /// clear all filters (for multi-queries) |
|
| 924 | - public function ResetFilters () |
|
| 925 | - { |
|
| 926 | - $this->_filters = array(); |
|
| 927 | - $this->_anchor = array(); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /// clear groupby settings (for multi-queries) |
|
| 931 | - public function ResetGroupBy () |
|
| 932 | - { |
|
| 933 | - $this->_groupby = ""; |
|
| 934 | - $this->_groupfunc = SPH_GROUPBY_DAY; |
|
| 935 | - $this->_groupsort = "@group desc"; |
|
| 936 | - $this->_groupdistinct= ""; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - /// clear all attribute value overrides (for multi-queries) |
|
| 940 | - public function ResetOverrides () |
|
| 939 | + /// clear all attribute value overrides (for multi-queries) |
|
| 940 | + public function ResetOverrides () |
|
| 941 | 941 | { |
| 942 | - $this->_overrides = array (); |
|
| 942 | + $this->_overrides = array (); |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | - ////////////////////////////////////////////////////////////////////////////// |
|
| 946 | - |
|
| 947 | - /// connect to searchd server, run given search query through given indexes, |
|
| 948 | - /// and return the search results |
|
| 949 | - public function Query ( $query, $index="*", $comment="" ) |
|
| 950 | - { |
|
| 951 | - assert ( empty($this->_reqs) ); |
|
| 952 | - |
|
| 953 | - $this->AddQuery ( $query, $index, $comment ); |
|
| 954 | - $results = $this->RunQueries (); |
|
| 955 | - $this->_reqs = array (); // just in case it failed too early |
|
| 956 | - |
|
| 957 | - if ( !is_array($results) ) |
|
| 958 | - return false; // probably network error; error message should be already filled |
|
| 959 | - |
|
| 960 | - $this->_error = $results[0]["error"]; |
|
| 961 | - $this->_warning = $results[0]["warning"]; |
|
| 962 | - if ( $results[0]["status"]==SEARCHD_ERROR ) |
|
| 963 | - return false; |
|
| 964 | - else |
|
| 965 | - return $results[0]; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /// helper to pack floats in network byte order |
|
| 969 | - public function _PackFloat ( $f ) |
|
| 970 | - { |
|
| 971 | - $t1 = pack ( "f", $f ); // machine order |
|
| 972 | - list(,$t2) = unpack ( "L*", $t1 ); // int in machine order |
|
| 973 | - return pack ( "N", $t2 ); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - /** |
|
| 977 | - * @SuppressWarnings(unused) |
|
| 978 | - */ |
|
| 979 | - |
|
| 980 | - /// add query to multi-query batch |
|
| 981 | - /// returns index into results array from RunQueries() call |
|
| 982 | - public function AddQuery ( $query, $index="*", $comment="" ) |
|
| 983 | - { |
|
| 984 | - // mbstring workaround |
|
| 985 | - $this->_MBPush (); |
|
| 986 | - |
|
| 987 | - // build request |
|
| 988 | - $req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort ); // mode and limits |
|
| 989 | - $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; |
|
| 990 | - $req .= pack ( "N", strlen($query) ) . $query; // query itself |
|
| 991 | - $req .= pack ( "N", count($this->_weights) ); // weights |
|
| 992 | - foreach ( $this->_weights as $weight ) |
|
| 993 | - $req .= pack ( "N", (int)$weight ); |
|
| 994 | - $req .= pack ( "N", strlen($index) ) . $index; // indexes |
|
| 995 | - $req .= pack ( "N", 1 ); // id64 range marker |
|
| 996 | - $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range |
|
| 997 | - |
|
| 998 | - // filters |
|
| 999 | - $req .= pack ( "N", count($this->_filters) ); |
|
| 1000 | - foreach ( $this->_filters as $filter ) |
|
| 1001 | - { |
|
| 1002 | - $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; |
|
| 1003 | - $req .= pack ( "N", $filter["type"] ); |
|
| 1004 | - switch ( $filter["type"] ) |
|
| 1005 | - { |
|
| 1006 | - case SPH_FILTER_VALUES: |
|
| 1007 | - $req .= pack ( "N", count($filter["values"]) ); |
|
| 1008 | - foreach ( $filter["values"] as $value ) |
|
| 1009 | - $req .= sphPackI64 ( $value ); |
|
| 1010 | - break; |
|
| 1011 | - |
|
| 1012 | - case SPH_FILTER_RANGE: |
|
| 1013 | - $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); |
|
| 1014 | - break; |
|
| 1015 | - |
|
| 1016 | - case SPH_FILTER_FLOATRANGE: |
|
| 1017 | - $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); |
|
| 1018 | - break; |
|
| 1019 | - |
|
| 1020 | - default: |
|
| 1021 | - assert ( 0 && "internal error: unhandled filter type" ); |
|
| 1022 | - } |
|
| 1023 | - $req .= pack ( "N", $filter["exclude"] ); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - // group-by clause, max-matches count, group-sort clause, cutoff count |
|
| 1027 | - $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; |
|
| 1028 | - $req .= pack ( "N", $this->_maxmatches ); |
|
| 1029 | - $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; |
|
| 1030 | - $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); |
|
| 1031 | - $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; |
|
| 1032 | - |
|
| 1033 | - // anchor point |
|
| 1034 | - if ( empty($this->_anchor) ) |
|
| 1035 | - { |
|
| 1036 | - $req .= pack ( "N", 0 ); |
|
| 1037 | - } else |
|
| 1038 | - { |
|
| 1039 | - $a =& $this->_anchor; |
|
| 1040 | - $req .= pack ( "N", 1 ); |
|
| 1041 | - $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; |
|
| 1042 | - $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; |
|
| 1043 | - $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - // per-index weights |
|
| 1047 | - $req .= pack ( "N", count($this->_indexweights) ); |
|
| 1048 | - foreach ( $this->_indexweights as $idx=>$weight ) |
|
| 1049 | - $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); |
|
| 1050 | - |
|
| 1051 | - // max query time |
|
| 1052 | - $req .= pack ( "N", $this->_maxquerytime ); |
|
| 1053 | - |
|
| 1054 | - // per-field weights |
|
| 1055 | - $req .= pack ( "N", count($this->_fieldweights) ); |
|
| 1056 | - foreach ( $this->_fieldweights as $field=>$weight ) |
|
| 1057 | - $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); |
|
| 1058 | - |
|
| 1059 | - // comment |
|
| 1060 | - $req .= pack ( "N", strlen($comment) ) . $comment; |
|
| 1061 | - |
|
| 1062 | - // attribute overrides |
|
| 1063 | - $req .= pack ( "N", count($this->_overrides) ); |
|
| 1064 | - foreach ( $this->_overrides as $key => $entry ) |
|
| 1065 | - { |
|
| 1066 | - $req .= pack ( "N", strlen($entry["attr"]) ) . $entry["attr"]; |
|
| 1067 | - $req .= pack ( "NN", $entry["type"], count($entry["values"]) ); |
|
| 1068 | - foreach ( $entry["values"] as $id=>$val ) |
|
| 1069 | - { |
|
| 1070 | - assert ( is_numeric($id) ); |
|
| 1071 | - assert ( is_numeric($val) ); |
|
| 1072 | - |
|
| 1073 | - $req .= sphPackU64 ( $id ); |
|
| 1074 | - switch ( $entry["type"] ) |
|
| 1075 | - { |
|
| 1076 | - case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; |
|
| 1077 | - case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; |
|
| 1078 | - default: $req .= pack ( "N", $val ); break; |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - // select-list |
|
| 1084 | - $req .= pack ( "N", strlen($this->_select) ) . $this->_select; |
|
| 1085 | - |
|
| 1086 | - // mbstring workaround |
|
| 1087 | - $this->_MBPop (); |
|
| 1088 | - |
|
| 1089 | - // store request to requests array |
|
| 1090 | - $this->_reqs[] = $req; |
|
| 1091 | - return count($this->_reqs)-1; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - /// connect to searchd, run queries batch, and return an array of result sets |
|
| 1095 | - public function RunQueries () |
|
| 1096 | - { |
|
| 1097 | - if ( empty($this->_reqs) ) |
|
| 1098 | - { |
|
| 1099 | - $this->_error = "no queries defined, issue AddQuery() first"; |
|
| 1100 | - return false; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - // mbstring workaround |
|
| 1104 | - $this->_MBPush (); |
|
| 1105 | - |
|
| 1106 | - if (!( $fp = $this->_Connect() )) |
|
| 1107 | - { |
|
| 1108 | - $this->_MBPop (); |
|
| 1109 | - return false; |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - // send query, get response |
|
| 1113 | - $nreqs = count($this->_reqs); |
|
| 1114 | - $req = join ( "", $this->_reqs ); |
|
| 1115 | - $len = 8+strlen($req); |
|
| 1116 | - $req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header |
|
| 1117 | - |
|
| 1118 | - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
| 1119 | - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) ) |
|
| 1120 | - { |
|
| 1121 | - $this->_MBPop (); |
|
| 1122 | - return false; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - // query sent ok; we can reset reqs now |
|
| 1126 | - $this->_reqs = array (); |
|
| 1127 | - |
|
| 1128 | - // parse and return response |
|
| 1129 | - return $this->_ParseSearchResponse ( $response, $nreqs ); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - /// parse and return search query (or queries) response |
|
| 1133 | - public function _ParseSearchResponse ( $response, $nreqs ) |
|
| 1134 | - { |
|
| 1135 | - $p = 0; // current position |
|
| 1136 | - $max = strlen($response); // max position for checks, to protect against broken responses |
|
| 1137 | - |
|
| 1138 | - $results = array (); |
|
| 1139 | - for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) |
|
| 1140 | - { |
|
| 1141 | - $results[] = array(); |
|
| 1142 | - $result =& $results[$ires]; |
|
| 1143 | - |
|
| 1144 | - $result["error"] = ""; |
|
| 1145 | - $result["warning"] = ""; |
|
| 1146 | - |
|
| 1147 | - // extract status |
|
| 1148 | - list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1149 | - $result["status"] = $status; |
|
| 1150 | - if ( $status!=SEARCHD_OK ) |
|
| 1151 | - { |
|
| 1152 | - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1153 | - $message = substr ( $response, $p, $len ); $p += $len; |
|
| 1154 | - |
|
| 1155 | - if ( $status==SEARCHD_WARNING ) |
|
| 1156 | - { |
|
| 1157 | - $result["warning"] = $message; |
|
| 1158 | - } else |
|
| 1159 | - { |
|
| 1160 | - $result["error"] = $message; |
|
| 1161 | - continue; |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - // read schema |
|
| 1166 | - $fields = array (); |
|
| 1167 | - $attrs = array (); |
|
| 1168 | - |
|
| 1169 | - list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1170 | - while ( $nfields-->0 && $p<$max ) |
|
| 1171 | - { |
|
| 1172 | - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1173 | - $fields[] = substr ( $response, $p, $len ); $p += $len; |
|
| 1174 | - } |
|
| 1175 | - $result["fields"] = $fields; |
|
| 1176 | - |
|
| 1177 | - list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1178 | - while ( $nattrs-->0 && $p<$max ) |
|
| 1179 | - { |
|
| 1180 | - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1181 | - $attr = substr ( $response, $p, $len ); $p += $len; |
|
| 1182 | - list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1183 | - $attrs[$attr] = $type; |
|
| 1184 | - } |
|
| 1185 | - $result["attrs"] = $attrs; |
|
| 1186 | - |
|
| 1187 | - // read match count |
|
| 1188 | - list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1189 | - list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1190 | - |
|
| 1191 | - // read matches |
|
| 1192 | - $idx = -1; |
|
| 1193 | - while ( $count-->0 && $p<$max ) |
|
| 1194 | - { |
|
| 1195 | - // index into result array |
|
| 1196 | - $idx++; |
|
| 1197 | - |
|
| 1198 | - // parse document id and weight |
|
| 1199 | - if ( $id64 ) |
|
| 1200 | - { |
|
| 1201 | - $doc = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; |
|
| 1202 | - list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1203 | - } |
|
| 1204 | - else |
|
| 1205 | - { |
|
| 1206 | - list ( $doc, $weight ) = array_values ( unpack ( "N*N*", |
|
| 1207 | - substr ( $response, $p, 8 ) ) ); |
|
| 1208 | - $p += 8; |
|
| 1209 | - $doc = sphFixUint($doc); |
|
| 1210 | - } |
|
| 1211 | - $weight = sprintf ( "%u", $weight ); |
|
| 1212 | - |
|
| 1213 | - // create match entry |
|
| 1214 | - if ( $this->_arrayresult ) |
|
| 1215 | - $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); |
|
| 1216 | - else |
|
| 1217 | - $result["matches"][$doc]["weight"] = $weight; |
|
| 1218 | - |
|
| 1219 | - // parse and create attributes |
|
| 1220 | - $attrvals = array (); |
|
| 1221 | - foreach ( $attrs as $attr=>$type ) |
|
| 1222 | - { |
|
| 1223 | - // handle 64bit ints |
|
| 1224 | - if ( $type==SPH_ATTR_BIGINT ) |
|
| 1225 | - { |
|
| 1226 | - $attrvals[$attr] = sphUnpackI64 ( substr ( $response, $p, 8 ) ); $p += 8; |
|
| 1227 | - continue; |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - // handle floats |
|
| 1231 | - if ( $type==SPH_ATTR_FLOAT ) |
|
| 1232 | - { |
|
| 1233 | - list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1234 | - list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); |
|
| 1235 | - $attrvals[$attr] = $fval; |
|
| 1236 | - continue; |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - // handle everything else as unsigned ints |
|
| 1240 | - list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1241 | - if ( $type & SPH_ATTR_MULTI ) |
|
| 1242 | - { |
|
| 1243 | - $attrvals[$attr] = array (); |
|
| 1244 | - $nvalues = $val; |
|
| 1245 | - while ( $nvalues-->0 && $p<$max ) |
|
| 1246 | - { |
|
| 1247 | - list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1248 | - $attrvals[$attr][] = sphFixUint($val); |
|
| 1249 | - } |
|
| 1250 | - } else if ( $type==SPH_ATTR_STRING ) |
|
| 1251 | - { |
|
| 1252 | - $attrvals[$attr] = substr ( $response, $p, $val ); |
|
| 1253 | - $p += $val; |
|
| 1254 | - } else |
|
| 1255 | - { |
|
| 1256 | - $attrvals[$attr] = sphFixUint($val); |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - if ( $this->_arrayresult ) |
|
| 1261 | - $result["matches"][$idx]["attrs"] = $attrvals; |
|
| 1262 | - else |
|
| 1263 | - $result["matches"][$doc]["attrs"] = $attrvals; |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - list ( $total, $total_found, $msecs, $words ) = |
|
| 1267 | - array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); |
|
| 1268 | - $result["total"] = sprintf ( "%u", $total ); |
|
| 1269 | - $result["total_found"] = sprintf ( "%u", $total_found ); |
|
| 1270 | - $result["time"] = sprintf ( "%.3f", $msecs/1000 ); |
|
| 1271 | - $p += 16; |
|
| 1272 | - |
|
| 1273 | - while ( $words-->0 && $p<$max ) |
|
| 1274 | - { |
|
| 1275 | - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1276 | - $word = substr ( $response, $p, $len ); $p += $len; |
|
| 1277 | - list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; |
|
| 1278 | - $result["words"][$word] = array ( |
|
| 1279 | - "docs"=>sprintf ( "%u", $docs ), |
|
| 1280 | - "hits"=>sprintf ( "%u", $hits ) ); |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $this->_MBPop (); |
|
| 1285 | - return $results; |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1289 | - // excerpts generation |
|
| 1290 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1291 | - |
|
| 1292 | - /// connect to searchd server, and generate exceprts (snippets) |
|
| 1293 | - /// of given documents for given query. returns false on failure, |
|
| 1294 | - /// an array of snippets on success |
|
| 1295 | - public function BuildExcerpts ( $docs, $index, $words, $opts=array() ) |
|
| 1296 | - { |
|
| 1297 | - assert ( is_array($docs) ); |
|
| 1298 | - assert ( is_string($index) ); |
|
| 1299 | - assert ( is_string($words) ); |
|
| 1300 | - assert ( is_array($opts) ); |
|
| 1301 | - |
|
| 1302 | - $this->_MBPush (); |
|
| 1303 | - |
|
| 1304 | - if (!( $fp = $this->_Connect() )) |
|
| 1305 | - { |
|
| 1306 | - $this->_MBPop(); |
|
| 1307 | - return false; |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - ///////////////// |
|
| 1311 | - // fixup options |
|
| 1312 | - ///////////////// |
|
| 1313 | - |
|
| 1314 | - if ( !isset($opts["before_match"]) ) $opts["before_match"] = "<b>"; |
|
| 1315 | - if ( !isset($opts["after_match"]) ) $opts["after_match"] = "</b>"; |
|
| 1316 | - if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; |
|
| 1317 | - if ( !isset($opts["limit"]) ) $opts["limit"] = 256; |
|
| 1318 | - if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0; |
|
| 1319 | - if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0; |
|
| 1320 | - if ( !isset($opts["around"]) ) $opts["around"] = 5; |
|
| 1321 | - if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; |
|
| 1322 | - if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; |
|
| 1323 | - if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; |
|
| 1324 | - if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; |
|
| 1325 | - if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false; |
|
| 1326 | - if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false; |
|
| 1327 | - if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1; |
|
| 1328 | - if ( !isset($opts["load_files"]) ) $opts["load_files"] = false; |
|
| 1329 | - if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index"; |
|
| 1330 | - if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false; |
|
| 1331 | - if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; |
|
| 1332 | - if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; |
|
| 1333 | - |
|
| 1334 | - ///////////////// |
|
| 1335 | - // build request |
|
| 1336 | - ///////////////// |
|
| 1337 | - |
|
| 1338 | - // v.1.2 req |
|
| 1339 | - $flags = 1; // remove spaces |
|
| 1340 | - if ( $opts["exact_phrase"] ) $flags |= 2; |
|
| 1341 | - if ( $opts["single_passage"] ) $flags |= 4; |
|
| 1342 | - if ( $opts["use_boundaries"] ) $flags |= 8; |
|
| 1343 | - if ( $opts["weight_order"] ) $flags |= 16; |
|
| 1344 | - if ( $opts["query_mode"] ) $flags |= 32; |
|
| 1345 | - if ( $opts["force_all_words"] ) $flags |= 64; |
|
| 1346 | - if ( $opts["load_files"] ) $flags |= 128; |
|
| 1347 | - if ( $opts["allow_empty"] ) $flags |= 256; |
|
| 1348 | - if ( $opts["emit_zones"] ) $flags |= 512; |
|
| 1349 | - $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags |
|
| 1350 | - $req .= pack ( "N", strlen($index) ) . $index; // req index |
|
| 1351 | - $req .= pack ( "N", strlen($words) ) . $words; // req words |
|
| 1352 | - |
|
| 1353 | - // options |
|
| 1354 | - $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; |
|
| 1355 | - $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; |
|
| 1356 | - $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; |
|
| 1357 | - $req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] ); |
|
| 1358 | - $req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2 |
|
| 1359 | - $req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"]; |
|
| 1360 | - $req .= pack ( "N", strlen($opts["passage_boundary"]) ) . $opts["passage_boundary"]; |
|
| 1361 | - |
|
| 1362 | - // documents |
|
| 1363 | - $req .= pack ( "N", count($docs) ); |
|
| 1364 | - foreach ( $docs as $doc ) |
|
| 1365 | - { |
|
| 1366 | - assert ( is_string($doc) ); |
|
| 1367 | - $req .= pack ( "N", strlen($doc) ) . $doc; |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - //////////////////////////// |
|
| 1371 | - // send query, get response |
|
| 1372 | - //////////////////////////// |
|
| 1373 | - |
|
| 1374 | - $len = strlen($req); |
|
| 1375 | - $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header |
|
| 1376 | - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
| 1377 | - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) ) |
|
| 1378 | - { |
|
| 1379 | - $this->_MBPop (); |
|
| 1380 | - return false; |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - ////////////////// |
|
| 1384 | - // parse response |
|
| 1385 | - ////////////////// |
|
| 1386 | - |
|
| 1387 | - $pos = 0; |
|
| 1388 | - $res = array (); |
|
| 1389 | - $rlen = strlen($response); |
|
| 1390 | - for ( $i=0; $i<count($docs); $i++ ) |
|
| 1391 | - { |
|
| 1392 | - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); |
|
| 1393 | - $pos += 4; |
|
| 1394 | - |
|
| 1395 | - if ( $pos+$len > $rlen ) |
|
| 1396 | - { |
|
| 1397 | - $this->_error = "incomplete reply"; |
|
| 1398 | - $this->_MBPop (); |
|
| 1399 | - return false; |
|
| 1400 | - } |
|
| 1401 | - $res[] = $len ? substr ( $response, $pos, $len ) : ""; |
|
| 1402 | - $pos += $len; |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - $this->_MBPop (); |
|
| 1406 | - return $res; |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - |
|
| 1410 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1411 | - // keyword generation |
|
| 1412 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1413 | - |
|
| 1414 | - /// connect to searchd server, and generate keyword list for a given query |
|
| 1415 | - /// returns false on failure, |
|
| 1416 | - /// an array of words on success |
|
| 1417 | - public function BuildKeywords ( $query, $index, $hits ) |
|
| 1418 | - { |
|
| 1419 | - assert ( is_string($query) ); |
|
| 1420 | - assert ( is_string($index) ); |
|
| 1421 | - assert ( is_bool($hits) ); |
|
| 1422 | - |
|
| 1423 | - $this->_MBPush (); |
|
| 1424 | - |
|
| 1425 | - if (!( $fp = $this->_Connect() )) |
|
| 1426 | - { |
|
| 1427 | - $this->_MBPop(); |
|
| 1428 | - return false; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - ///////////////// |
|
| 1432 | - // build request |
|
| 1433 | - ///////////////// |
|
| 1434 | - |
|
| 1435 | - // v.1.0 req |
|
| 1436 | - $req = pack ( "N", strlen($query) ) . $query; // req query |
|
| 1437 | - $req .= pack ( "N", strlen($index) ) . $index; // req index |
|
| 1438 | - $req .= pack ( "N", (int)$hits ); |
|
| 1439 | - |
|
| 1440 | - //////////////////////////// |
|
| 1441 | - // send query, get response |
|
| 1442 | - //////////////////////////// |
|
| 1443 | - |
|
| 1444 | - $len = strlen($req); |
|
| 1445 | - $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header |
|
| 1446 | - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
| 1447 | - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) ) |
|
| 1448 | - { |
|
| 1449 | - $this->_MBPop (); |
|
| 1450 | - return false; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - ////////////////// |
|
| 1454 | - // parse response |
|
| 1455 | - ////////////////// |
|
| 1456 | - |
|
| 1457 | - $pos = 0; |
|
| 1458 | - $res = array (); |
|
| 1459 | - $rlen = strlen($response); |
|
| 1460 | - list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); |
|
| 1461 | - $pos += 4; |
|
| 1462 | - for ( $i=0; $i<$nwords; $i++ ) |
|
| 1463 | - { |
|
| 1464 | - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; |
|
| 1465 | - $tokenized = $len ? substr ( $response, $pos, $len ) : ""; |
|
| 1466 | - $pos += $len; |
|
| 1467 | - |
|
| 1468 | - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; |
|
| 1469 | - $normalized = $len ? substr ( $response, $pos, $len ) : ""; |
|
| 1470 | - $pos += $len; |
|
| 1471 | - |
|
| 1472 | - $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); |
|
| 1473 | - |
|
| 1474 | - if ( $hits ) |
|
| 1475 | - { |
|
| 1476 | - list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); |
|
| 1477 | - $pos += 8; |
|
| 1478 | - $res [$i]["docs"] = $ndocs; |
|
| 1479 | - $res [$i]["hits"] = $nhits; |
|
| 1480 | - } |
|
| 1481 | - |
|
| 1482 | - if ( $pos > $rlen ) |
|
| 1483 | - { |
|
| 1484 | - $this->_error = "incomplete reply"; |
|
| 1485 | - $this->_MBPop (); |
|
| 1486 | - return false; |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - $this->_MBPop (); |
|
| 1491 | - return $res; |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - public function EscapeString ( $string ) |
|
| 1495 | - { |
|
| 1496 | - $from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' ); |
|
| 1497 | - $to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' ); |
|
| 1498 | - |
|
| 1499 | - return str_replace ( $from, $to, $string ); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1503 | - // attribute updates |
|
| 1504 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1505 | - |
|
| 1506 | - /// batch update given attributes in given rows in given indexes |
|
| 1507 | - /// returns amount of updated documents (0 or more) on success, or -1 on failure |
|
| 1508 | - public function UpdateAttributes ( $index, $attrs, $values, $mva=false ) |
|
| 1509 | - { |
|
| 1510 | - // verify everything |
|
| 1511 | - assert ( is_string($index) ); |
|
| 1512 | - assert ( is_bool($mva) ); |
|
| 1513 | - |
|
| 1514 | - assert ( is_array($attrs) ); |
|
| 1515 | - foreach ( $attrs as $attr ) |
|
| 1516 | - assert ( is_string($attr) ); |
|
| 1517 | - |
|
| 1518 | - assert ( is_array($values) ); |
|
| 1519 | - foreach ( $values as $id=>$entry ) |
|
| 1520 | - { |
|
| 1521 | - assert ( is_numeric($id) ); |
|
| 1522 | - assert ( is_array($entry) ); |
|
| 1523 | - assert ( count($entry)==count($attrs) ); |
|
| 1524 | - foreach ( $entry as $v ) |
|
| 1525 | - { |
|
| 1526 | - if ( $mva ) |
|
| 1527 | - { |
|
| 1528 | - assert ( is_array($v) ); |
|
| 1529 | - foreach ( $v as $vv ) |
|
| 1530 | - assert ( is_int($vv) ); |
|
| 1531 | - } else |
|
| 1532 | - assert ( is_int($v) ); |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - // build request |
|
| 1537 | - $this->_MBPush (); |
|
| 1538 | - $req = pack ( "N", strlen($index) ) . $index; |
|
| 1539 | - |
|
| 1540 | - $req .= pack ( "N", count($attrs) ); |
|
| 1541 | - foreach ( $attrs as $attr ) |
|
| 1542 | - { |
|
| 1543 | - $req .= pack ( "N", strlen($attr) ) . $attr; |
|
| 1544 | - $req .= pack ( "N", $mva ? 1 : 0 ); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - $req .= pack ( "N", count($values) ); |
|
| 1548 | - foreach ( $values as $id=>$entry ) |
|
| 1549 | - { |
|
| 1550 | - $req .= sphPackU64 ( $id ); |
|
| 1551 | - foreach ( $entry as $v ) |
|
| 1552 | - { |
|
| 1553 | - $req .= pack ( "N", $mva ? count($v) : $v ); |
|
| 1554 | - if ( $mva ) |
|
| 1555 | - foreach ( $v as $vv ) |
|
| 1556 | - $req .= pack ( "N", $vv ); |
|
| 1557 | - } |
|
| 1558 | - } |
|
| 1559 | - |
|
| 1560 | - // connect, send query, get response |
|
| 1561 | - if (!( $fp = $this->_Connect() )) |
|
| 1562 | - { |
|
| 1563 | - $this->_MBPop (); |
|
| 1564 | - return -1; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - $len = strlen($req); |
|
| 1568 | - $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header |
|
| 1569 | - if ( !$this->_Send ( $fp, $req, $len+8 ) ) |
|
| 1570 | - { |
|
| 1571 | - $this->_MBPop (); |
|
| 1572 | - return -1; |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) |
|
| 1576 | - { |
|
| 1577 | - $this->_MBPop (); |
|
| 1578 | - return -1; |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - // parse response |
|
| 1582 | - list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); |
|
| 1583 | - $this->_MBPop (); |
|
| 1584 | - return $updated; |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1588 | - // persistent connections |
|
| 1589 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 1590 | - |
|
| 1591 | - public function Open() |
|
| 1592 | - { |
|
| 1593 | - if ( $this->_socket !== false ) |
|
| 1594 | - { |
|
| 1595 | - $this->_error = 'already connected'; |
|
| 1596 | - return false; |
|
| 1597 | - } |
|
| 1598 | - if ( !$fp = $this->_Connect() ) |
|
| 1599 | - return false; |
|
| 1600 | - |
|
| 1601 | - // command, command version = 0, body length = 4, body = 1 |
|
| 1602 | - $req = pack ( "nnNN", SEARCHD_COMMAND_PERSIST, 0, 4, 1 ); |
|
| 1603 | - if ( !$this->_Send ( $fp, $req, 12 ) ) |
|
| 1604 | - return false; |
|
| 1605 | - |
|
| 1606 | - $this->_socket = $fp; |
|
| 1607 | - return true; |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - public function Close() |
|
| 1611 | - { |
|
| 1612 | - if ( $this->_socket === false ) |
|
| 1613 | - { |
|
| 1614 | - $this->_error = 'not connected'; |
|
| 1615 | - return false; |
|
| 1616 | - } |
|
| 1617 | - |
|
| 1618 | - fclose ( $this->_socket ); |
|
| 1619 | - $this->_socket = false; |
|
| 1620 | - |
|
| 1621 | - return true; |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - ////////////////////////////////////////////////////////////////////////// |
|
| 1625 | - // status |
|
| 1626 | - ////////////////////////////////////////////////////////////////////////// |
|
| 1627 | - |
|
| 1628 | - public function Status () |
|
| 1629 | - { |
|
| 1630 | - $this->_MBPush (); |
|
| 1631 | - if (!( $fp = $this->_Connect() )) |
|
| 1632 | - { |
|
| 1633 | - $this->_MBPop(); |
|
| 1634 | - return false; |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - $req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1 ); // len=4, body=1 |
|
| 1638 | - if ( !( $this->_Send ( $fp, $req, 12 ) ) || |
|
| 1639 | - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) ) |
|
| 1640 | - { |
|
| 1641 | - $this->_MBPop (); |
|
| 1642 | - return false; |
|
| 1643 | - } |
|
| 1644 | - |
|
| 1645 | - $res = substr ( $response, 4 ); // just ignore length, error handling, etc |
|
| 1646 | - $p = 0; |
|
| 1647 | - list ( $rows, $cols ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; |
|
| 1648 | - |
|
| 1649 | - $res = array(); |
|
| 1650 | - for ( $i=0; $i<$rows; $i++ ) |
|
| 1651 | - for ( $j=0; $j<$cols; $j++ ) |
|
| 1652 | - { |
|
| 1653 | - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1654 | - $res[$i][] = substr ( $response, $p, $len ); $p += $len; |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - $this->_MBPop (); |
|
| 1658 | - return $res; |
|
| 1659 | - } |
|
| 1660 | - |
|
| 1661 | - ////////////////////////////////////////////////////////////////////////// |
|
| 1662 | - // flush |
|
| 1663 | - ////////////////////////////////////////////////////////////////////////// |
|
| 1664 | - |
|
| 1665 | - public function FlushAttributes () |
|
| 1666 | - { |
|
| 1667 | - $this->_MBPush (); |
|
| 1668 | - if (!( $fp = $this->_Connect() )) |
|
| 1669 | - { |
|
| 1670 | - $this->_MBPop(); |
|
| 1671 | - return -1; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - $req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0 |
|
| 1675 | - if ( !( $this->_Send ( $fp, $req, 8 ) ) || |
|
| 1676 | - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) ) |
|
| 1677 | - { |
|
| 1678 | - $this->_MBPop (); |
|
| 1679 | - return -1; |
|
| 1680 | - } |
|
| 1681 | - |
|
| 1682 | - $tag = -1; |
|
| 1683 | - if ( strlen($response)==4 ) |
|
| 1684 | - list(,$tag) = unpack ( "N*", $response ); |
|
| 1685 | - else |
|
| 1686 | - $this->_error = "unexpected response length"; |
|
| 1687 | - |
|
| 1688 | - $this->_MBPop (); |
|
| 1689 | - return $tag; |
|
| 1690 | - } |
|
| 945 | + ////////////////////////////////////////////////////////////////////////////// |
|
| 946 | + |
|
| 947 | + /// connect to searchd server, run given search query through given indexes, |
|
| 948 | + /// and return the search results |
|
| 949 | + public function Query ( $query, $index="*", $comment="" ) |
|
| 950 | + { |
|
| 951 | + assert ( empty($this->_reqs) ); |
|
| 952 | + |
|
| 953 | + $this->AddQuery ( $query, $index, $comment ); |
|
| 954 | + $results = $this->RunQueries (); |
|
| 955 | + $this->_reqs = array (); // just in case it failed too early |
|
| 956 | + |
|
| 957 | + if ( !is_array($results) ) |
|
| 958 | + return false; // probably network error; error message should be already filled |
|
| 959 | + |
|
| 960 | + $this->_error = $results[0]["error"]; |
|
| 961 | + $this->_warning = $results[0]["warning"]; |
|
| 962 | + if ( $results[0]["status"]==SEARCHD_ERROR ) |
|
| 963 | + return false; |
|
| 964 | + else |
|
| 965 | + return $results[0]; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /// helper to pack floats in network byte order |
|
| 969 | + public function _PackFloat ( $f ) |
|
| 970 | + { |
|
| 971 | + $t1 = pack ( "f", $f ); // machine order |
|
| 972 | + list(,$t2) = unpack ( "L*", $t1 ); // int in machine order |
|
| 973 | + return pack ( "N", $t2 ); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + /** |
|
| 977 | + * @SuppressWarnings(unused) |
|
| 978 | + */ |
|
| 979 | + |
|
| 980 | + /// add query to multi-query batch |
|
| 981 | + /// returns index into results array from RunQueries() call |
|
| 982 | + public function AddQuery ( $query, $index="*", $comment="" ) |
|
| 983 | + { |
|
| 984 | + // mbstring workaround |
|
| 985 | + $this->_MBPush (); |
|
| 986 | + |
|
| 987 | + // build request |
|
| 988 | + $req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort ); // mode and limits |
|
| 989 | + $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; |
|
| 990 | + $req .= pack ( "N", strlen($query) ) . $query; // query itself |
|
| 991 | + $req .= pack ( "N", count($this->_weights) ); // weights |
|
| 992 | + foreach ( $this->_weights as $weight ) |
|
| 993 | + $req .= pack ( "N", (int)$weight ); |
|
| 994 | + $req .= pack ( "N", strlen($index) ) . $index; // indexes |
|
| 995 | + $req .= pack ( "N", 1 ); // id64 range marker |
|
| 996 | + $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range |
|
| 997 | + |
|
| 998 | + // filters |
|
| 999 | + $req .= pack ( "N", count($this->_filters) ); |
|
| 1000 | + foreach ( $this->_filters as $filter ) |
|
| 1001 | + { |
|
| 1002 | + $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; |
|
| 1003 | + $req .= pack ( "N", $filter["type"] ); |
|
| 1004 | + switch ( $filter["type"] ) |
|
| 1005 | + { |
|
| 1006 | + case SPH_FILTER_VALUES: |
|
| 1007 | + $req .= pack ( "N", count($filter["values"]) ); |
|
| 1008 | + foreach ( $filter["values"] as $value ) |
|
| 1009 | + $req .= sphPackI64 ( $value ); |
|
| 1010 | + break; |
|
| 1011 | + |
|
| 1012 | + case SPH_FILTER_RANGE: |
|
| 1013 | + $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); |
|
| 1014 | + break; |
|
| 1015 | + |
|
| 1016 | + case SPH_FILTER_FLOATRANGE: |
|
| 1017 | + $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); |
|
| 1018 | + break; |
|
| 1019 | + |
|
| 1020 | + default: |
|
| 1021 | + assert ( 0 && "internal error: unhandled filter type" ); |
|
| 1022 | + } |
|
| 1023 | + $req .= pack ( "N", $filter["exclude"] ); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + // group-by clause, max-matches count, group-sort clause, cutoff count |
|
| 1027 | + $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; |
|
| 1028 | + $req .= pack ( "N", $this->_maxmatches ); |
|
| 1029 | + $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; |
|
| 1030 | + $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); |
|
| 1031 | + $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; |
|
| 1032 | + |
|
| 1033 | + // anchor point |
|
| 1034 | + if ( empty($this->_anchor) ) |
|
| 1035 | + { |
|
| 1036 | + $req .= pack ( "N", 0 ); |
|
| 1037 | + } else |
|
| 1038 | + { |
|
| 1039 | + $a =& $this->_anchor; |
|
| 1040 | + $req .= pack ( "N", 1 ); |
|
| 1041 | + $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; |
|
| 1042 | + $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; |
|
| 1043 | + $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + // per-index weights |
|
| 1047 | + $req .= pack ( "N", count($this->_indexweights) ); |
|
| 1048 | + foreach ( $this->_indexweights as $idx=>$weight ) |
|
| 1049 | + $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); |
|
| 1050 | + |
|
| 1051 | + // max query time |
|
| 1052 | + $req .= pack ( "N", $this->_maxquerytime ); |
|
| 1053 | + |
|
| 1054 | + // per-field weights |
|
| 1055 | + $req .= pack ( "N", count($this->_fieldweights) ); |
|
| 1056 | + foreach ( $this->_fieldweights as $field=>$weight ) |
|
| 1057 | + $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); |
|
| 1058 | + |
|
| 1059 | + // comment |
|
| 1060 | + $req .= pack ( "N", strlen($comment) ) . $comment; |
|
| 1061 | + |
|
| 1062 | + // attribute overrides |
|
| 1063 | + $req .= pack ( "N", count($this->_overrides) ); |
|
| 1064 | + foreach ( $this->_overrides as $key => $entry ) |
|
| 1065 | + { |
|
| 1066 | + $req .= pack ( "N", strlen($entry["attr"]) ) . $entry["attr"]; |
|
| 1067 | + $req .= pack ( "NN", $entry["type"], count($entry["values"]) ); |
|
| 1068 | + foreach ( $entry["values"] as $id=>$val ) |
|
| 1069 | + { |
|
| 1070 | + assert ( is_numeric($id) ); |
|
| 1071 | + assert ( is_numeric($val) ); |
|
| 1072 | + |
|
| 1073 | + $req .= sphPackU64 ( $id ); |
|
| 1074 | + switch ( $entry["type"] ) |
|
| 1075 | + { |
|
| 1076 | + case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; |
|
| 1077 | + case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; |
|
| 1078 | + default: $req .= pack ( "N", $val ); break; |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + // select-list |
|
| 1084 | + $req .= pack ( "N", strlen($this->_select) ) . $this->_select; |
|
| 1085 | + |
|
| 1086 | + // mbstring workaround |
|
| 1087 | + $this->_MBPop (); |
|
| 1088 | + |
|
| 1089 | + // store request to requests array |
|
| 1090 | + $this->_reqs[] = $req; |
|
| 1091 | + return count($this->_reqs)-1; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + /// connect to searchd, run queries batch, and return an array of result sets |
|
| 1095 | + public function RunQueries () |
|
| 1096 | + { |
|
| 1097 | + if ( empty($this->_reqs) ) |
|
| 1098 | + { |
|
| 1099 | + $this->_error = "no queries defined, issue AddQuery() first"; |
|
| 1100 | + return false; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + // mbstring workaround |
|
| 1104 | + $this->_MBPush (); |
|
| 1105 | + |
|
| 1106 | + if (!( $fp = $this->_Connect() )) |
|
| 1107 | + { |
|
| 1108 | + $this->_MBPop (); |
|
| 1109 | + return false; |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + // send query, get response |
|
| 1113 | + $nreqs = count($this->_reqs); |
|
| 1114 | + $req = join ( "", $this->_reqs ); |
|
| 1115 | + $len = 8+strlen($req); |
|
| 1116 | + $req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header |
|
| 1117 | + |
|
| 1118 | + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
| 1119 | + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) ) |
|
| 1120 | + { |
|
| 1121 | + $this->_MBPop (); |
|
| 1122 | + return false; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + // query sent ok; we can reset reqs now |
|
| 1126 | + $this->_reqs = array (); |
|
| 1127 | + |
|
| 1128 | + // parse and return response |
|
| 1129 | + return $this->_ParseSearchResponse ( $response, $nreqs ); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + /// parse and return search query (or queries) response |
|
| 1133 | + public function _ParseSearchResponse ( $response, $nreqs ) |
|
| 1134 | + { |
|
| 1135 | + $p = 0; // current position |
|
| 1136 | + $max = strlen($response); // max position for checks, to protect against broken responses |
|
| 1137 | + |
|
| 1138 | + $results = array (); |
|
| 1139 | + for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) |
|
| 1140 | + { |
|
| 1141 | + $results[] = array(); |
|
| 1142 | + $result =& $results[$ires]; |
|
| 1143 | + |
|
| 1144 | + $result["error"] = ""; |
|
| 1145 | + $result["warning"] = ""; |
|
| 1146 | + |
|
| 1147 | + // extract status |
|
| 1148 | + list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1149 | + $result["status"] = $status; |
|
| 1150 | + if ( $status!=SEARCHD_OK ) |
|
| 1151 | + { |
|
| 1152 | + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1153 | + $message = substr ( $response, $p, $len ); $p += $len; |
|
| 1154 | + |
|
| 1155 | + if ( $status==SEARCHD_WARNING ) |
|
| 1156 | + { |
|
| 1157 | + $result["warning"] = $message; |
|
| 1158 | + } else |
|
| 1159 | + { |
|
| 1160 | + $result["error"] = $message; |
|
| 1161 | + continue; |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + // read schema |
|
| 1166 | + $fields = array (); |
|
| 1167 | + $attrs = array (); |
|
| 1168 | + |
|
| 1169 | + list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1170 | + while ( $nfields-->0 && $p<$max ) |
|
| 1171 | + { |
|
| 1172 | + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1173 | + $fields[] = substr ( $response, $p, $len ); $p += $len; |
|
| 1174 | + } |
|
| 1175 | + $result["fields"] = $fields; |
|
| 1176 | + |
|
| 1177 | + list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1178 | + while ( $nattrs-->0 && $p<$max ) |
|
| 1179 | + { |
|
| 1180 | + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1181 | + $attr = substr ( $response, $p, $len ); $p += $len; |
|
| 1182 | + list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1183 | + $attrs[$attr] = $type; |
|
| 1184 | + } |
|
| 1185 | + $result["attrs"] = $attrs; |
|
| 1186 | + |
|
| 1187 | + // read match count |
|
| 1188 | + list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1189 | + list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1190 | + |
|
| 1191 | + // read matches |
|
| 1192 | + $idx = -1; |
|
| 1193 | + while ( $count-->0 && $p<$max ) |
|
| 1194 | + { |
|
| 1195 | + // index into result array |
|
| 1196 | + $idx++; |
|
| 1197 | + |
|
| 1198 | + // parse document id and weight |
|
| 1199 | + if ( $id64 ) |
|
| 1200 | + { |
|
| 1201 | + $doc = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; |
|
| 1202 | + list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1203 | + } |
|
| 1204 | + else |
|
| 1205 | + { |
|
| 1206 | + list ( $doc, $weight ) = array_values ( unpack ( "N*N*", |
|
| 1207 | + substr ( $response, $p, 8 ) ) ); |
|
| 1208 | + $p += 8; |
|
| 1209 | + $doc = sphFixUint($doc); |
|
| 1210 | + } |
|
| 1211 | + $weight = sprintf ( "%u", $weight ); |
|
| 1212 | + |
|
| 1213 | + // create match entry |
|
| 1214 | + if ( $this->_arrayresult ) |
|
| 1215 | + $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); |
|
| 1216 | + else |
|
| 1217 | + $result["matches"][$doc]["weight"] = $weight; |
|
| 1218 | + |
|
| 1219 | + // parse and create attributes |
|
| 1220 | + $attrvals = array (); |
|
| 1221 | + foreach ( $attrs as $attr=>$type ) |
|
| 1222 | + { |
|
| 1223 | + // handle 64bit ints |
|
| 1224 | + if ( $type==SPH_ATTR_BIGINT ) |
|
| 1225 | + { |
|
| 1226 | + $attrvals[$attr] = sphUnpackI64 ( substr ( $response, $p, 8 ) ); $p += 8; |
|
| 1227 | + continue; |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + // handle floats |
|
| 1231 | + if ( $type==SPH_ATTR_FLOAT ) |
|
| 1232 | + { |
|
| 1233 | + list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1234 | + list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); |
|
| 1235 | + $attrvals[$attr] = $fval; |
|
| 1236 | + continue; |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + // handle everything else as unsigned ints |
|
| 1240 | + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1241 | + if ( $type & SPH_ATTR_MULTI ) |
|
| 1242 | + { |
|
| 1243 | + $attrvals[$attr] = array (); |
|
| 1244 | + $nvalues = $val; |
|
| 1245 | + while ( $nvalues-->0 && $p<$max ) |
|
| 1246 | + { |
|
| 1247 | + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1248 | + $attrvals[$attr][] = sphFixUint($val); |
|
| 1249 | + } |
|
| 1250 | + } else if ( $type==SPH_ATTR_STRING ) |
|
| 1251 | + { |
|
| 1252 | + $attrvals[$attr] = substr ( $response, $p, $val ); |
|
| 1253 | + $p += $val; |
|
| 1254 | + } else |
|
| 1255 | + { |
|
| 1256 | + $attrvals[$attr] = sphFixUint($val); |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + |
|
| 1260 | + if ( $this->_arrayresult ) |
|
| 1261 | + $result["matches"][$idx]["attrs"] = $attrvals; |
|
| 1262 | + else |
|
| 1263 | + $result["matches"][$doc]["attrs"] = $attrvals; |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + list ( $total, $total_found, $msecs, $words ) = |
|
| 1267 | + array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); |
|
| 1268 | + $result["total"] = sprintf ( "%u", $total ); |
|
| 1269 | + $result["total_found"] = sprintf ( "%u", $total_found ); |
|
| 1270 | + $result["time"] = sprintf ( "%.3f", $msecs/1000 ); |
|
| 1271 | + $p += 16; |
|
| 1272 | + |
|
| 1273 | + while ( $words-->0 && $p<$max ) |
|
| 1274 | + { |
|
| 1275 | + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1276 | + $word = substr ( $response, $p, $len ); $p += $len; |
|
| 1277 | + list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; |
|
| 1278 | + $result["words"][$word] = array ( |
|
| 1279 | + "docs"=>sprintf ( "%u", $docs ), |
|
| 1280 | + "hits"=>sprintf ( "%u", $hits ) ); |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $this->_MBPop (); |
|
| 1285 | + return $results; |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1289 | + // excerpts generation |
|
| 1290 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1291 | + |
|
| 1292 | + /// connect to searchd server, and generate exceprts (snippets) |
|
| 1293 | + /// of given documents for given query. returns false on failure, |
|
| 1294 | + /// an array of snippets on success |
|
| 1295 | + public function BuildExcerpts ( $docs, $index, $words, $opts=array() ) |
|
| 1296 | + { |
|
| 1297 | + assert ( is_array($docs) ); |
|
| 1298 | + assert ( is_string($index) ); |
|
| 1299 | + assert ( is_string($words) ); |
|
| 1300 | + assert ( is_array($opts) ); |
|
| 1301 | + |
|
| 1302 | + $this->_MBPush (); |
|
| 1303 | + |
|
| 1304 | + if (!( $fp = $this->_Connect() )) |
|
| 1305 | + { |
|
| 1306 | + $this->_MBPop(); |
|
| 1307 | + return false; |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + ///////////////// |
|
| 1311 | + // fixup options |
|
| 1312 | + ///////////////// |
|
| 1313 | + |
|
| 1314 | + if ( !isset($opts["before_match"]) ) $opts["before_match"] = "<b>"; |
|
| 1315 | + if ( !isset($opts["after_match"]) ) $opts["after_match"] = "</b>"; |
|
| 1316 | + if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; |
|
| 1317 | + if ( !isset($opts["limit"]) ) $opts["limit"] = 256; |
|
| 1318 | + if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0; |
|
| 1319 | + if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0; |
|
| 1320 | + if ( !isset($opts["around"]) ) $opts["around"] = 5; |
|
| 1321 | + if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; |
|
| 1322 | + if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; |
|
| 1323 | + if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; |
|
| 1324 | + if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; |
|
| 1325 | + if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false; |
|
| 1326 | + if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false; |
|
| 1327 | + if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1; |
|
| 1328 | + if ( !isset($opts["load_files"]) ) $opts["load_files"] = false; |
|
| 1329 | + if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index"; |
|
| 1330 | + if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false; |
|
| 1331 | + if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; |
|
| 1332 | + if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; |
|
| 1333 | + |
|
| 1334 | + ///////////////// |
|
| 1335 | + // build request |
|
| 1336 | + ///////////////// |
|
| 1337 | + |
|
| 1338 | + // v.1.2 req |
|
| 1339 | + $flags = 1; // remove spaces |
|
| 1340 | + if ( $opts["exact_phrase"] ) $flags |= 2; |
|
| 1341 | + if ( $opts["single_passage"] ) $flags |= 4; |
|
| 1342 | + if ( $opts["use_boundaries"] ) $flags |= 8; |
|
| 1343 | + if ( $opts["weight_order"] ) $flags |= 16; |
|
| 1344 | + if ( $opts["query_mode"] ) $flags |= 32; |
|
| 1345 | + if ( $opts["force_all_words"] ) $flags |= 64; |
|
| 1346 | + if ( $opts["load_files"] ) $flags |= 128; |
|
| 1347 | + if ( $opts["allow_empty"] ) $flags |= 256; |
|
| 1348 | + if ( $opts["emit_zones"] ) $flags |= 512; |
|
| 1349 | + $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags |
|
| 1350 | + $req .= pack ( "N", strlen($index) ) . $index; // req index |
|
| 1351 | + $req .= pack ( "N", strlen($words) ) . $words; // req words |
|
| 1352 | + |
|
| 1353 | + // options |
|
| 1354 | + $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; |
|
| 1355 | + $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; |
|
| 1356 | + $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; |
|
| 1357 | + $req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] ); |
|
| 1358 | + $req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2 |
|
| 1359 | + $req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"]; |
|
| 1360 | + $req .= pack ( "N", strlen($opts["passage_boundary"]) ) . $opts["passage_boundary"]; |
|
| 1361 | + |
|
| 1362 | + // documents |
|
| 1363 | + $req .= pack ( "N", count($docs) ); |
|
| 1364 | + foreach ( $docs as $doc ) |
|
| 1365 | + { |
|
| 1366 | + assert ( is_string($doc) ); |
|
| 1367 | + $req .= pack ( "N", strlen($doc) ) . $doc; |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + //////////////////////////// |
|
| 1371 | + // send query, get response |
|
| 1372 | + //////////////////////////// |
|
| 1373 | + |
|
| 1374 | + $len = strlen($req); |
|
| 1375 | + $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header |
|
| 1376 | + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
| 1377 | + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) ) |
|
| 1378 | + { |
|
| 1379 | + $this->_MBPop (); |
|
| 1380 | + return false; |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + ////////////////// |
|
| 1384 | + // parse response |
|
| 1385 | + ////////////////// |
|
| 1386 | + |
|
| 1387 | + $pos = 0; |
|
| 1388 | + $res = array (); |
|
| 1389 | + $rlen = strlen($response); |
|
| 1390 | + for ( $i=0; $i<count($docs); $i++ ) |
|
| 1391 | + { |
|
| 1392 | + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); |
|
| 1393 | + $pos += 4; |
|
| 1394 | + |
|
| 1395 | + if ( $pos+$len > $rlen ) |
|
| 1396 | + { |
|
| 1397 | + $this->_error = "incomplete reply"; |
|
| 1398 | + $this->_MBPop (); |
|
| 1399 | + return false; |
|
| 1400 | + } |
|
| 1401 | + $res[] = $len ? substr ( $response, $pos, $len ) : ""; |
|
| 1402 | + $pos += $len; |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + $this->_MBPop (); |
|
| 1406 | + return $res; |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + |
|
| 1410 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1411 | + // keyword generation |
|
| 1412 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1413 | + |
|
| 1414 | + /// connect to searchd server, and generate keyword list for a given query |
|
| 1415 | + /// returns false on failure, |
|
| 1416 | + /// an array of words on success |
|
| 1417 | + public function BuildKeywords ( $query, $index, $hits ) |
|
| 1418 | + { |
|
| 1419 | + assert ( is_string($query) ); |
|
| 1420 | + assert ( is_string($index) ); |
|
| 1421 | + assert ( is_bool($hits) ); |
|
| 1422 | + |
|
| 1423 | + $this->_MBPush (); |
|
| 1424 | + |
|
| 1425 | + if (!( $fp = $this->_Connect() )) |
|
| 1426 | + { |
|
| 1427 | + $this->_MBPop(); |
|
| 1428 | + return false; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + ///////////////// |
|
| 1432 | + // build request |
|
| 1433 | + ///////////////// |
|
| 1434 | + |
|
| 1435 | + // v.1.0 req |
|
| 1436 | + $req = pack ( "N", strlen($query) ) . $query; // req query |
|
| 1437 | + $req .= pack ( "N", strlen($index) ) . $index; // req index |
|
| 1438 | + $req .= pack ( "N", (int)$hits ); |
|
| 1439 | + |
|
| 1440 | + //////////////////////////// |
|
| 1441 | + // send query, get response |
|
| 1442 | + //////////////////////////// |
|
| 1443 | + |
|
| 1444 | + $len = strlen($req); |
|
| 1445 | + $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header |
|
| 1446 | + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
| 1447 | + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) ) |
|
| 1448 | + { |
|
| 1449 | + $this->_MBPop (); |
|
| 1450 | + return false; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + ////////////////// |
|
| 1454 | + // parse response |
|
| 1455 | + ////////////////// |
|
| 1456 | + |
|
| 1457 | + $pos = 0; |
|
| 1458 | + $res = array (); |
|
| 1459 | + $rlen = strlen($response); |
|
| 1460 | + list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); |
|
| 1461 | + $pos += 4; |
|
| 1462 | + for ( $i=0; $i<$nwords; $i++ ) |
|
| 1463 | + { |
|
| 1464 | + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; |
|
| 1465 | + $tokenized = $len ? substr ( $response, $pos, $len ) : ""; |
|
| 1466 | + $pos += $len; |
|
| 1467 | + |
|
| 1468 | + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; |
|
| 1469 | + $normalized = $len ? substr ( $response, $pos, $len ) : ""; |
|
| 1470 | + $pos += $len; |
|
| 1471 | + |
|
| 1472 | + $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); |
|
| 1473 | + |
|
| 1474 | + if ( $hits ) |
|
| 1475 | + { |
|
| 1476 | + list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); |
|
| 1477 | + $pos += 8; |
|
| 1478 | + $res [$i]["docs"] = $ndocs; |
|
| 1479 | + $res [$i]["hits"] = $nhits; |
|
| 1480 | + } |
|
| 1481 | + |
|
| 1482 | + if ( $pos > $rlen ) |
|
| 1483 | + { |
|
| 1484 | + $this->_error = "incomplete reply"; |
|
| 1485 | + $this->_MBPop (); |
|
| 1486 | + return false; |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + $this->_MBPop (); |
|
| 1491 | + return $res; |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + public function EscapeString ( $string ) |
|
| 1495 | + { |
|
| 1496 | + $from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' ); |
|
| 1497 | + $to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' ); |
|
| 1498 | + |
|
| 1499 | + return str_replace ( $from, $to, $string ); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1503 | + // attribute updates |
|
| 1504 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1505 | + |
|
| 1506 | + /// batch update given attributes in given rows in given indexes |
|
| 1507 | + /// returns amount of updated documents (0 or more) on success, or -1 on failure |
|
| 1508 | + public function UpdateAttributes ( $index, $attrs, $values, $mva=false ) |
|
| 1509 | + { |
|
| 1510 | + // verify everything |
|
| 1511 | + assert ( is_string($index) ); |
|
| 1512 | + assert ( is_bool($mva) ); |
|
| 1513 | + |
|
| 1514 | + assert ( is_array($attrs) ); |
|
| 1515 | + foreach ( $attrs as $attr ) |
|
| 1516 | + assert ( is_string($attr) ); |
|
| 1517 | + |
|
| 1518 | + assert ( is_array($values) ); |
|
| 1519 | + foreach ( $values as $id=>$entry ) |
|
| 1520 | + { |
|
| 1521 | + assert ( is_numeric($id) ); |
|
| 1522 | + assert ( is_array($entry) ); |
|
| 1523 | + assert ( count($entry)==count($attrs) ); |
|
| 1524 | + foreach ( $entry as $v ) |
|
| 1525 | + { |
|
| 1526 | + if ( $mva ) |
|
| 1527 | + { |
|
| 1528 | + assert ( is_array($v) ); |
|
| 1529 | + foreach ( $v as $vv ) |
|
| 1530 | + assert ( is_int($vv) ); |
|
| 1531 | + } else |
|
| 1532 | + assert ( is_int($v) ); |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + // build request |
|
| 1537 | + $this->_MBPush (); |
|
| 1538 | + $req = pack ( "N", strlen($index) ) . $index; |
|
| 1539 | + |
|
| 1540 | + $req .= pack ( "N", count($attrs) ); |
|
| 1541 | + foreach ( $attrs as $attr ) |
|
| 1542 | + { |
|
| 1543 | + $req .= pack ( "N", strlen($attr) ) . $attr; |
|
| 1544 | + $req .= pack ( "N", $mva ? 1 : 0 ); |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + $req .= pack ( "N", count($values) ); |
|
| 1548 | + foreach ( $values as $id=>$entry ) |
|
| 1549 | + { |
|
| 1550 | + $req .= sphPackU64 ( $id ); |
|
| 1551 | + foreach ( $entry as $v ) |
|
| 1552 | + { |
|
| 1553 | + $req .= pack ( "N", $mva ? count($v) : $v ); |
|
| 1554 | + if ( $mva ) |
|
| 1555 | + foreach ( $v as $vv ) |
|
| 1556 | + $req .= pack ( "N", $vv ); |
|
| 1557 | + } |
|
| 1558 | + } |
|
| 1559 | + |
|
| 1560 | + // connect, send query, get response |
|
| 1561 | + if (!( $fp = $this->_Connect() )) |
|
| 1562 | + { |
|
| 1563 | + $this->_MBPop (); |
|
| 1564 | + return -1; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + $len = strlen($req); |
|
| 1568 | + $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header |
|
| 1569 | + if ( !$this->_Send ( $fp, $req, $len+8 ) ) |
|
| 1570 | + { |
|
| 1571 | + $this->_MBPop (); |
|
| 1572 | + return -1; |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) |
|
| 1576 | + { |
|
| 1577 | + $this->_MBPop (); |
|
| 1578 | + return -1; |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + // parse response |
|
| 1582 | + list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); |
|
| 1583 | + $this->_MBPop (); |
|
| 1584 | + return $updated; |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1588 | + // persistent connections |
|
| 1589 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 1590 | + |
|
| 1591 | + public function Open() |
|
| 1592 | + { |
|
| 1593 | + if ( $this->_socket !== false ) |
|
| 1594 | + { |
|
| 1595 | + $this->_error = 'already connected'; |
|
| 1596 | + return false; |
|
| 1597 | + } |
|
| 1598 | + if ( !$fp = $this->_Connect() ) |
|
| 1599 | + return false; |
|
| 1600 | + |
|
| 1601 | + // command, command version = 0, body length = 4, body = 1 |
|
| 1602 | + $req = pack ( "nnNN", SEARCHD_COMMAND_PERSIST, 0, 4, 1 ); |
|
| 1603 | + if ( !$this->_Send ( $fp, $req, 12 ) ) |
|
| 1604 | + return false; |
|
| 1605 | + |
|
| 1606 | + $this->_socket = $fp; |
|
| 1607 | + return true; |
|
| 1608 | + } |
|
| 1609 | + |
|
| 1610 | + public function Close() |
|
| 1611 | + { |
|
| 1612 | + if ( $this->_socket === false ) |
|
| 1613 | + { |
|
| 1614 | + $this->_error = 'not connected'; |
|
| 1615 | + return false; |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + fclose ( $this->_socket ); |
|
| 1619 | + $this->_socket = false; |
|
| 1620 | + |
|
| 1621 | + return true; |
|
| 1622 | + } |
|
| 1623 | + |
|
| 1624 | + ////////////////////////////////////////////////////////////////////////// |
|
| 1625 | + // status |
|
| 1626 | + ////////////////////////////////////////////////////////////////////////// |
|
| 1627 | + |
|
| 1628 | + public function Status () |
|
| 1629 | + { |
|
| 1630 | + $this->_MBPush (); |
|
| 1631 | + if (!( $fp = $this->_Connect() )) |
|
| 1632 | + { |
|
| 1633 | + $this->_MBPop(); |
|
| 1634 | + return false; |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + $req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1 ); // len=4, body=1 |
|
| 1638 | + if ( !( $this->_Send ( $fp, $req, 12 ) ) || |
|
| 1639 | + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) ) |
|
| 1640 | + { |
|
| 1641 | + $this->_MBPop (); |
|
| 1642 | + return false; |
|
| 1643 | + } |
|
| 1644 | + |
|
| 1645 | + $res = substr ( $response, 4 ); // just ignore length, error handling, etc |
|
| 1646 | + $p = 0; |
|
| 1647 | + list ( $rows, $cols ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; |
|
| 1648 | + |
|
| 1649 | + $res = array(); |
|
| 1650 | + for ( $i=0; $i<$rows; $i++ ) |
|
| 1651 | + for ( $j=0; $j<$cols; $j++ ) |
|
| 1652 | + { |
|
| 1653 | + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
| 1654 | + $res[$i][] = substr ( $response, $p, $len ); $p += $len; |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + $this->_MBPop (); |
|
| 1658 | + return $res; |
|
| 1659 | + } |
|
| 1660 | + |
|
| 1661 | + ////////////////////////////////////////////////////////////////////////// |
|
| 1662 | + // flush |
|
| 1663 | + ////////////////////////////////////////////////////////////////////////// |
|
| 1664 | + |
|
| 1665 | + public function FlushAttributes () |
|
| 1666 | + { |
|
| 1667 | + $this->_MBPush (); |
|
| 1668 | + if (!( $fp = $this->_Connect() )) |
|
| 1669 | + { |
|
| 1670 | + $this->_MBPop(); |
|
| 1671 | + return -1; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + $req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0 |
|
| 1675 | + if ( !( $this->_Send ( $fp, $req, 8 ) ) || |
|
| 1676 | + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) ) |
|
| 1677 | + { |
|
| 1678 | + $this->_MBPop (); |
|
| 1679 | + return -1; |
|
| 1680 | + } |
|
| 1681 | + |
|
| 1682 | + $tag = -1; |
|
| 1683 | + if ( strlen($response)==4 ) |
|
| 1684 | + list(,$tag) = unpack ( "N*", $response ); |
|
| 1685 | + else |
|
| 1686 | + $this->_error = "unexpected response length"; |
|
| 1687 | + |
|
| 1688 | + $this->_MBPop (); |
|
| 1689 | + return $tag; |
|
| 1690 | + } |
|
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | // |
@@ -32,10 +32,10 @@ |
||
| 32 | 32 | public function __get($name) |
| 33 | 33 | { |
| 34 | 34 | switch ($name) { |
| 35 | - case 'length': |
|
| 36 | - return $this->length; |
|
| 37 | - default: |
|
| 38 | - trigger_error(sprintf('Undefined property: %s::%s', static::class, $name)); |
|
| 35 | + case 'length': |
|
| 36 | + return $this->length; |
|
| 37 | + default: |
|
| 38 | + trigger_error(sprintf('Undefined property: %s::%s', static::class, $name)); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -121,36 +121,36 @@ |
||
| 121 | 121 | $contentScore = 0; |
| 122 | 122 | |
| 123 | 123 | switch ($this->nodeName) { |
| 124 | - case 'div': |
|
| 125 | - $contentScore += 5; |
|
| 126 | - break; |
|
| 127 | - |
|
| 128 | - case 'pre': |
|
| 129 | - case 'td': |
|
| 130 | - case 'blockquote': |
|
| 131 | - $contentScore += 3; |
|
| 132 | - break; |
|
| 133 | - |
|
| 134 | - case 'address': |
|
| 135 | - case 'ol': |
|
| 136 | - case 'ul': |
|
| 137 | - case 'dl': |
|
| 138 | - case 'dd': |
|
| 139 | - case 'dt': |
|
| 140 | - case 'li': |
|
| 141 | - case 'form': |
|
| 142 | - $contentScore -= 3; |
|
| 143 | - break; |
|
| 144 | - |
|
| 145 | - case 'h1': |
|
| 146 | - case 'h2': |
|
| 147 | - case 'h3': |
|
| 148 | - case 'h4': |
|
| 149 | - case 'h5': |
|
| 150 | - case 'h6': |
|
| 151 | - case 'th': |
|
| 152 | - $contentScore -= 5; |
|
| 153 | - break; |
|
| 124 | + case 'div': |
|
| 125 | + $contentScore += 5; |
|
| 126 | + break; |
|
| 127 | + |
|
| 128 | + case 'pre': |
|
| 129 | + case 'td': |
|
| 130 | + case 'blockquote': |
|
| 131 | + $contentScore += 3; |
|
| 132 | + break; |
|
| 133 | + |
|
| 134 | + case 'address': |
|
| 135 | + case 'ol': |
|
| 136 | + case 'ul': |
|
| 137 | + case 'dl': |
|
| 138 | + case 'dd': |
|
| 139 | + case 'dt': |
|
| 140 | + case 'li': |
|
| 141 | + case 'form': |
|
| 142 | + $contentScore -= 3; |
|
| 143 | + break; |
|
| 144 | + |
|
| 145 | + case 'h1': |
|
| 146 | + case 'h2': |
|
| 147 | + case 'h3': |
|
| 148 | + case 'h4': |
|
| 149 | + case 'h5': |
|
| 150 | + case 'h6': |
|
| 151 | + case 'th': |
|
| 152 | + $contentScore -= 5; |
|
| 153 | + break; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $this->contentScore = $contentScore + ($weightClasses ? $this->getClassWeight() : 0); |
@@ -24,14 +24,14 @@ |
||
| 24 | 24 | $er = error_reporting(E_ALL); |
| 25 | 25 | |
| 26 | 26 | switch (DB_TYPE) { |
| 27 | - case "mysql": |
|
| 28 | - $this->adapter = new Db_Mysqli(); |
|
| 29 | - break; |
|
| 30 | - case "pgsql": |
|
| 31 | - $this->adapter = new Db_Pgsql(); |
|
| 32 | - break; |
|
| 33 | - default: |
|
| 34 | - die("Unknown DB_TYPE: " . DB_TYPE); |
|
| 27 | + case "mysql": |
|
| 28 | + $this->adapter = new Db_Mysqli(); |
|
| 29 | + break; |
|
| 30 | + case "pgsql": |
|
| 31 | + $this->adapter = new Db_Pgsql(); |
|
| 32 | + break; |
|
| 33 | + default: |
|
| 34 | + die("Unknown DB_TYPE: " . DB_TYPE); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | if (!$this->adapter) { |
@@ -2,115 +2,115 @@ |
||
| 2 | 2 | class Db |
| 3 | 3 | { |
| 4 | 4 | |
| 5 | - /* @var Db $instance */ |
|
| 6 | - private static $instance; |
|
| 5 | + /* @var Db $instance */ |
|
| 6 | + private static $instance; |
|
| 7 | 7 | |
| 8 | - /* @var IDb $adapter */ |
|
| 9 | - private $adapter; |
|
| 8 | + /* @var IDb $adapter */ |
|
| 9 | + private $adapter; |
|
| 10 | 10 | |
| 11 | - private $link; |
|
| 11 | + private $link; |
|
| 12 | 12 | |
| 13 | - /* @var PDO $pdo */ |
|
| 14 | - private $pdo; |
|
| 13 | + /* @var PDO $pdo */ |
|
| 14 | + private $pdo; |
|
| 15 | 15 | |
| 16 | - private function __clone() { |
|
| 17 | - // |
|
| 18 | - } |
|
| 16 | + private function __clone() { |
|
| 17 | + // |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - private function legacy_connect() { |
|
| 20 | + private function legacy_connect() { |
|
| 21 | 21 | |
| 22 | - user_error("Legacy connect requested to " . DB_TYPE, E_USER_NOTICE); |
|
| 22 | + user_error("Legacy connect requested to " . DB_TYPE, E_USER_NOTICE); |
|
| 23 | 23 | |
| 24 | - $er = error_reporting(E_ALL); |
|
| 24 | + $er = error_reporting(E_ALL); |
|
| 25 | 25 | |
| 26 | - switch (DB_TYPE) { |
|
| 27 | - case "mysql": |
|
| 28 | - $this->adapter = new Db_Mysqli(); |
|
| 29 | - break; |
|
| 30 | - case "pgsql": |
|
| 31 | - $this->adapter = new Db_Pgsql(); |
|
| 32 | - break; |
|
| 33 | - default: |
|
| 34 | - die("Unknown DB_TYPE: " . DB_TYPE); |
|
| 35 | - } |
|
| 26 | + switch (DB_TYPE) { |
|
| 27 | + case "mysql": |
|
| 28 | + $this->adapter = new Db_Mysqli(); |
|
| 29 | + break; |
|
| 30 | + case "pgsql": |
|
| 31 | + $this->adapter = new Db_Pgsql(); |
|
| 32 | + break; |
|
| 33 | + default: |
|
| 34 | + die("Unknown DB_TYPE: " . DB_TYPE); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if (!$this->adapter) { |
|
| 38 | - print("Error initializing database adapter for " . DB_TYPE); |
|
| 39 | - exit(100); |
|
| 40 | - } |
|
| 37 | + if (!$this->adapter) { |
|
| 38 | + print("Error initializing database adapter for " . DB_TYPE); |
|
| 39 | + exit(100); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
| 42 | + $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
| 43 | 43 | |
| 44 | - if (!$this->link) { |
|
| 45 | - print("Error connecting through adapter: " . $this->adapter->last_error()); |
|
| 46 | - exit(101); |
|
| 47 | - } |
|
| 44 | + if (!$this->link) { |
|
| 45 | + print("Error connecting through adapter: " . $this->adapter->last_error()); |
|
| 46 | + exit(101); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - error_reporting($er); |
|
| 50 | - } |
|
| 49 | + error_reporting($er); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // this really shouldn't be used unless a separate PDO connection is needed |
|
| 53 | - // normal usage is Db::pdo()->prepare(...) etc |
|
| 54 | - public function pdo_connect() { |
|
| 52 | + // this really shouldn't be used unless a separate PDO connection is needed |
|
| 53 | + // normal usage is Db::pdo()->prepare(...) etc |
|
| 54 | + public function pdo_connect() { |
|
| 55 | 55 | |
| 56 | - $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; |
|
| 57 | - $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; |
|
| 56 | + $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; |
|
| 57 | + $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; |
|
| 58 | 58 | |
| 59 | - try { |
|
| 60 | - $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, |
|
| 61 | - DB_USER, |
|
| 62 | - DB_PASS); |
|
| 63 | - } catch (Exception $e) { |
|
| 64 | - print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; |
|
| 65 | - exit(101); |
|
| 66 | - } |
|
| 59 | + try { |
|
| 60 | + $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, |
|
| 61 | + DB_USER, |
|
| 62 | + DB_PASS); |
|
| 63 | + } catch (Exception $e) { |
|
| 64 | + print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; |
|
| 65 | + exit(101); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 68 | + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 69 | 69 | |
| 70 | - if (DB_TYPE == "pgsql") { |
|
| 70 | + if (DB_TYPE == "pgsql") { |
|
| 71 | 71 | |
| 72 | - $pdo->query("set client_encoding = 'UTF-8'"); |
|
| 73 | - $pdo->query("set datestyle = 'ISO, european'"); |
|
| 74 | - $pdo->query("set TIME ZONE 0"); |
|
| 75 | - $pdo->query("set cpu_tuple_cost = 0.5"); |
|
| 72 | + $pdo->query("set client_encoding = 'UTF-8'"); |
|
| 73 | + $pdo->query("set datestyle = 'ISO, european'"); |
|
| 74 | + $pdo->query("set TIME ZONE 0"); |
|
| 75 | + $pdo->query("set cpu_tuple_cost = 0.5"); |
|
| 76 | 76 | |
| 77 | - } else if (DB_TYPE == "mysql") { |
|
| 78 | - $pdo->query("SET time_zone = '+0:0'"); |
|
| 77 | + } else if (DB_TYPE == "mysql") { |
|
| 78 | + $pdo->query("SET time_zone = '+0:0'"); |
|
| 79 | 79 | |
| 80 | - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
| 81 | - $pdo->query("SET NAMES " . MYSQL_CHARSET); |
|
| 82 | - } |
|
| 83 | - } |
|
| 80 | + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
| 81 | + $pdo->query("SET NAMES " . MYSQL_CHARSET); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return $pdo; |
|
| 86 | - } |
|
| 85 | + return $pdo; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public static function instance() { |
|
| 89 | - if (self::$instance == null) |
|
| 90 | - self::$instance = new self(); |
|
| 88 | + public static function instance() { |
|
| 89 | + if (self::$instance == null) |
|
| 90 | + self::$instance = new self(); |
|
| 91 | 91 | |
| 92 | - return self::$instance; |
|
| 93 | - } |
|
| 92 | + return self::$instance; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public static function get() { |
|
| 96 | - if (self::$instance == null) |
|
| 97 | - self::$instance = new self(); |
|
| 95 | + public static function get() { |
|
| 96 | + if (self::$instance == null) |
|
| 97 | + self::$instance = new self(); |
|
| 98 | 98 | |
| 99 | - if (!self::$instance->adapter) { |
|
| 100 | - self::$instance->legacy_connect(); |
|
| 101 | - } |
|
| 99 | + if (!self::$instance->adapter) { |
|
| 100 | + self::$instance->legacy_connect(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return self::$instance->adapter; |
|
| 104 | - } |
|
| 103 | + return self::$instance->adapter; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public static function pdo() { |
|
| 107 | - if (self::$instance == null) |
|
| 108 | - self::$instance = new self(); |
|
| 106 | + public static function pdo() { |
|
| 107 | + if (self::$instance == null) |
|
| 108 | + self::$instance = new self(); |
|
| 109 | 109 | |
| 110 | - if (!self::$instance->pdo) { |
|
| 111 | - self::$instance->pdo = self::$instance->pdo_connect(); |
|
| 112 | - } |
|
| 110 | + if (!self::$instance->pdo) { |
|
| 111 | + self::$instance->pdo = self::$instance->pdo_connect(); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return self::$instance->pdo; |
|
| 115 | - } |
|
| 114 | + return self::$instance->pdo; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -126,14 +126,14 @@ |
||
| 126 | 126 | $tmp = ''; |
| 127 | 127 | foreach (str_split($keys[$i]) as $c) { |
| 128 | 128 | switch ($c) { |
| 129 | - case '*': |
|
| 130 | - $tmp .= __('Shift') . '+'; |
|
| 131 | - break; |
|
| 132 | - case '^': |
|
| 133 | - $tmp .= __('Ctrl') . '+'; |
|
| 134 | - break; |
|
| 135 | - default: |
|
| 136 | - $tmp .= $c; |
|
| 129 | + case '*': |
|
| 130 | + $tmp .= __('Shift') . '+'; |
|
| 131 | + break; |
|
| 132 | + case '^': |
|
| 133 | + $tmp .= __('Ctrl') . '+'; |
|
| 134 | + break; |
|
| 135 | + default: |
|
| 136 | + $tmp .= $c; |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | $keys[$i] = $tmp; |
@@ -1,97 +1,97 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Backend extends Handler { |
| 3 | - public function loading() { |
|
| 4 | - header("Content-type: text/html"); |
|
| 5 | - print __("Loading, please wait...") . " " . |
|
| 6 | - "<img src='images/indicator_tiny.gif'>"; |
|
| 7 | - } |
|
| 8 | - |
|
| 9 | - public function digestTest() { |
|
| 10 | - if (isset($_SESSION['uid'])) { |
|
| 11 | - header("Content-type: text/html"); |
|
| 12 | - |
|
| 13 | - $rv = Digest::prepare_headlines_digest($_SESSION['uid'], 1, 1000); |
|
| 14 | - |
|
| 15 | - print "<h1>HTML</h1>"; |
|
| 16 | - print $rv[0]; |
|
| 17 | - print "<h1>Plain text</h1>"; |
|
| 18 | - print "<pre>".$rv[3]."</pre>"; |
|
| 19 | - } else { |
|
| 20 | - print error_json(6); |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function help() { |
|
| 25 | - $topic = clean_filename($_REQUEST["topic"]); // only one for now |
|
| 26 | - |
|
| 27 | - if ($topic == "main") { |
|
| 28 | - $info = get_hotkeys_info(); |
|
| 29 | - $imap = get_hotkeys_map(); |
|
| 30 | - $omap = array(); |
|
| 31 | - |
|
| 32 | - foreach ($imap[1] as $sequence => $action) { |
|
| 33 | - if (!isset($omap[$action])) $omap[$action] = array(); |
|
| 34 | - |
|
| 35 | - array_push($omap[$action], $sequence); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>"; |
|
| 39 | - |
|
| 40 | - $cur_section = ""; |
|
| 41 | - foreach ($info as $section => $hotkeys) { |
|
| 42 | - |
|
| 43 | - if ($cur_section) print "<li> </li>"; |
|
| 44 | - print "<li><h3>" . $section . "</h3></li>"; |
|
| 45 | - $cur_section = $section; |
|
| 46 | - |
|
| 47 | - foreach ($hotkeys as $action => $description) { |
|
| 48 | - |
|
| 49 | - if (is_array($omap[$action])) { |
|
| 50 | - foreach ($omap[$action] as $sequence) { |
|
| 51 | - if (strpos($sequence, "|") !== false) { |
|
| 52 | - $sequence = substr($sequence, |
|
| 53 | - strpos($sequence, "|")+1, |
|
| 54 | - strlen($sequence)); |
|
| 55 | - } else { |
|
| 56 | - $keys = explode(" ", $sequence); |
|
| 57 | - |
|
| 58 | - for ($i = 0; $i < count($keys); $i++) { |
|
| 59 | - if (strlen($keys[$i]) > 1) { |
|
| 60 | - $tmp = ''; |
|
| 61 | - foreach (str_split($keys[$i]) as $c) { |
|
| 62 | - switch ($c) { |
|
| 63 | - case '*': |
|
| 64 | - $tmp .= __('Shift') . '+'; |
|
| 65 | - break; |
|
| 66 | - case '^': |
|
| 67 | - $tmp .= __('Ctrl') . '+'; |
|
| 68 | - break; |
|
| 69 | - default: |
|
| 70 | - $tmp .= $c; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - $keys[$i] = $tmp; |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $sequence = join(" ", $keys); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - print "<li>"; |
|
| 80 | - print "<div class='hk'><code>$sequence</code></div>"; |
|
| 81 | - print "<div class='desc'>$description</div>"; |
|
| 82 | - print "</li>"; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - print "</ul>"; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - print "<footer class='text-center'>"; |
|
| 92 | - print "<button dojoType='dijit.form.Button' |
|
| 3 | + public function loading() { |
|
| 4 | + header("Content-type: text/html"); |
|
| 5 | + print __("Loading, please wait...") . " " . |
|
| 6 | + "<img src='images/indicator_tiny.gif'>"; |
|
| 7 | + } |
|
| 8 | + |
|
| 9 | + public function digestTest() { |
|
| 10 | + if (isset($_SESSION['uid'])) { |
|
| 11 | + header("Content-type: text/html"); |
|
| 12 | + |
|
| 13 | + $rv = Digest::prepare_headlines_digest($_SESSION['uid'], 1, 1000); |
|
| 14 | + |
|
| 15 | + print "<h1>HTML</h1>"; |
|
| 16 | + print $rv[0]; |
|
| 17 | + print "<h1>Plain text</h1>"; |
|
| 18 | + print "<pre>".$rv[3]."</pre>"; |
|
| 19 | + } else { |
|
| 20 | + print error_json(6); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function help() { |
|
| 25 | + $topic = clean_filename($_REQUEST["topic"]); // only one for now |
|
| 26 | + |
|
| 27 | + if ($topic == "main") { |
|
| 28 | + $info = get_hotkeys_info(); |
|
| 29 | + $imap = get_hotkeys_map(); |
|
| 30 | + $omap = array(); |
|
| 31 | + |
|
| 32 | + foreach ($imap[1] as $sequence => $action) { |
|
| 33 | + if (!isset($omap[$action])) $omap[$action] = array(); |
|
| 34 | + |
|
| 35 | + array_push($omap[$action], $sequence); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>"; |
|
| 39 | + |
|
| 40 | + $cur_section = ""; |
|
| 41 | + foreach ($info as $section => $hotkeys) { |
|
| 42 | + |
|
| 43 | + if ($cur_section) print "<li> </li>"; |
|
| 44 | + print "<li><h3>" . $section . "</h3></li>"; |
|
| 45 | + $cur_section = $section; |
|
| 46 | + |
|
| 47 | + foreach ($hotkeys as $action => $description) { |
|
| 48 | + |
|
| 49 | + if (is_array($omap[$action])) { |
|
| 50 | + foreach ($omap[$action] as $sequence) { |
|
| 51 | + if (strpos($sequence, "|") !== false) { |
|
| 52 | + $sequence = substr($sequence, |
|
| 53 | + strpos($sequence, "|")+1, |
|
| 54 | + strlen($sequence)); |
|
| 55 | + } else { |
|
| 56 | + $keys = explode(" ", $sequence); |
|
| 57 | + |
|
| 58 | + for ($i = 0; $i < count($keys); $i++) { |
|
| 59 | + if (strlen($keys[$i]) > 1) { |
|
| 60 | + $tmp = ''; |
|
| 61 | + foreach (str_split($keys[$i]) as $c) { |
|
| 62 | + switch ($c) { |
|
| 63 | + case '*': |
|
| 64 | + $tmp .= __('Shift') . '+'; |
|
| 65 | + break; |
|
| 66 | + case '^': |
|
| 67 | + $tmp .= __('Ctrl') . '+'; |
|
| 68 | + break; |
|
| 69 | + default: |
|
| 70 | + $tmp .= $c; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + $keys[$i] = $tmp; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $sequence = join(" ", $keys); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + print "<li>"; |
|
| 80 | + print "<div class='hk'><code>$sequence</code></div>"; |
|
| 81 | + print "<div class='desc'>$description</div>"; |
|
| 82 | + print "</li>"; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + print "</ul>"; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + print "<footer class='text-center'>"; |
|
| 92 | + print "<button dojoType='dijit.form.Button' |
|
| 93 | 93 | onclick=\"return dijit.byId('helpDlg').hide()\">".__('Close this window')."</button>"; |
| 94 | - print "</footer>"; |
|
| 94 | + print "</footer>"; |
|
| 95 | 95 | |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -170,22 +170,22 @@ |
||
| 170 | 170 | $value = $_POST[$pref_name]; |
| 171 | 171 | |
| 172 | 172 | switch ($pref_name) { |
| 173 | - case 'DIGEST_PREFERRED_TIME': |
|
| 174 | - if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
| 173 | + case 'DIGEST_PREFERRED_TIME': |
|
| 174 | + if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
| 175 | 175 | |
| 176 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
| 176 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
| 177 | 177 | last_digest_sent = NULL WHERE id = ?"); |
| 178 | - $sth->execute([$_SESSION['uid']]); |
|
| 178 | + $sth->execute([$_SESSION['uid']]); |
|
| 179 | 179 | |
| 180 | - } |
|
| 181 | - break; |
|
| 182 | - case 'USER_LANGUAGE': |
|
| 183 | - if (!$need_reload) $need_reload = $_SESSION["language"] != $value; |
|
| 184 | - break; |
|
| 185 | - |
|
| 186 | - case 'USER_CSS_THEME': |
|
| 187 | - if (!$need_reload) $need_reload = get_pref($pref_name) != $value; |
|
| 188 | - break; |
|
| 180 | + } |
|
| 181 | + break; |
|
| 182 | + case 'USER_LANGUAGE': |
|
| 183 | + if (!$need_reload) $need_reload = $_SESSION["language"] != $value; |
|
| 184 | + break; |
|
| 185 | + |
|
| 186 | + case 'USER_CSS_THEME': |
|
| 187 | + if (!$need_reload) $need_reload = get_pref($pref_name) != $value; |
|
| 188 | + break; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | set_pref($pref_name, $value); |
@@ -2,278 +2,278 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class Pref_Prefs extends Handler_Protected { |
| 4 | 4 | |
| 5 | - private $pref_help = []; |
|
| 6 | - private $pref_item_map = []; |
|
| 7 | - private $pref_blacklist = []; |
|
| 8 | - private $profile_blacklist = []; |
|
| 9 | - |
|
| 10 | - public function csrf_ignore($method) { |
|
| 11 | - $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles"); |
|
| 12 | - |
|
| 13 | - return array_search($method, $csrf_ignored) !== false; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - public function __construct($args) { |
|
| 17 | - parent::__construct($args); |
|
| 18 | - |
|
| 19 | - $this->pref_item_map = [ |
|
| 20 | - __('General') => [ |
|
| 21 | - 'USER_LANGUAGE', |
|
| 22 | - 'USER_TIMEZONE', |
|
| 23 | - 'BLOCK_SEPARATOR', |
|
| 24 | - 'USER_CSS_THEME', |
|
| 25 | - 'BLOCK_SEPARATOR', |
|
| 26 | - 'ENABLE_API_ACCESS', |
|
| 27 | - ], |
|
| 28 | - __('Feeds') => [ |
|
| 29 | - 'DEFAULT_UPDATE_INTERVAL', |
|
| 30 | - 'FRESH_ARTICLE_MAX_AGE', |
|
| 31 | - 'DEFAULT_SEARCH_LANGUAGE', |
|
| 32 | - 'BLOCK_SEPARATOR', |
|
| 33 | - 'ENABLE_FEED_CATS', |
|
| 34 | - 'BLOCK_SEPARATOR', |
|
| 35 | - 'CONFIRM_FEED_CATCHUP', |
|
| 36 | - 'ON_CATCHUP_SHOW_NEXT_FEED', |
|
| 37 | - 'BLOCK_SEPARATOR', |
|
| 38 | - 'HIDE_READ_FEEDS', |
|
| 39 | - 'HIDE_READ_SHOWS_SPECIAL', |
|
| 40 | - ], |
|
| 41 | - __('Articles') => [ |
|
| 42 | - 'PURGE_OLD_DAYS', |
|
| 43 | - 'PURGE_UNREAD_ARTICLES', |
|
| 44 | - 'BLOCK_SEPARATOR', |
|
| 45 | - 'COMBINED_DISPLAY_MODE', |
|
| 46 | - 'CDM_EXPANDED', |
|
| 47 | - 'BLOCK_SEPARATOR', |
|
| 48 | - 'CDM_AUTO_CATCHUP', |
|
| 49 | - 'VFEED_GROUP_BY_FEED', |
|
| 50 | - 'BLOCK_SEPARATOR', |
|
| 51 | - 'SHOW_CONTENT_PREVIEW', |
|
| 52 | - 'STRIP_IMAGES', |
|
| 53 | - ], |
|
| 54 | - __('Digest') => [ |
|
| 55 | - 'DIGEST_ENABLE', |
|
| 56 | - 'DIGEST_CATCHUP', |
|
| 57 | - 'DIGEST_PREFERRED_TIME', |
|
| 58 | - ], |
|
| 59 | - __('Advanced') => [ |
|
| 60 | - 'BLACKLISTED_TAGS', |
|
| 61 | - 'BLOCK_SEPARATOR', |
|
| 62 | - 'LONG_DATE_FORMAT', |
|
| 63 | - 'SHORT_DATE_FORMAT', |
|
| 64 | - 'BLOCK_SEPARATOR', |
|
| 65 | - 'SSL_CERT_SERIAL', |
|
| 66 | - ] |
|
| 67 | - ]; |
|
| 68 | - |
|
| 69 | - $this->pref_help = [ |
|
| 70 | - "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""), |
|
| 71 | - "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("Never apply these tags automatically (comma-separated list).")), |
|
| 72 | - "DEFAULT_SEARCH_LANGUAGE" => array(__("Default language"), __("Used for full-text search")), |
|
| 73 | - "CDM_AUTO_CATCHUP" => array(__("Mark read on scroll"), __("Mark articles as read as you scroll past them")), |
|
| 74 | - "CDM_EXPANDED" => array(__("Always expand articles")), |
|
| 75 | - "COMBINED_DISPLAY_MODE" => array(__("Combined mode"), __("Show flat list of articles instead of separate panels")), |
|
| 76 | - "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feeds as read")), |
|
| 77 | - "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once")), |
|
| 78 | - "DEFAULT_UPDATE_INTERVAL" => array(__("Default update interval")), |
|
| 79 | - "DIGEST_CATCHUP" => array(__("Mark sent articles as read")), |
|
| 80 | - "DIGEST_ENABLE" => array(__("Enable digest"), __("Send daily digest of new (and unread) headlines to your e-mail address")), |
|
| 81 | - "DIGEST_PREFERRED_TIME" => array(__("Try to send around this time"), __("Time in UTC")), |
|
| 82 | - "ENABLE_API_ACCESS" => array(__("Enable API"), __("Allows accessing this account through the API")), |
|
| 83 | - "ENABLE_FEED_CATS" => array(__("Enable categories")), |
|
| 84 | - "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""), |
|
| 85 | - "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles"), "<strong>" . __("hours") . "</strong>"), |
|
| 86 | - "HIDE_READ_FEEDS" => array(__("Hide read feeds")), |
|
| 87 | - "HIDE_READ_SHOWS_SPECIAL" => array(__("Always show special feeds"), __("While hiding read feeds")), |
|
| 88 | - "LONG_DATE_FORMAT" => array(__("Long date format"), __("Syntax is identical to PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), |
|
| 89 | - "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("Automatically show next feed"), __("After marking one as read")), |
|
| 90 | - "PURGE_OLD_DAYS" => array(__("Purge articles older than"), __("<strong>days</strong> (0 disables)")), |
|
| 91 | - "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles")), |
|
| 92 | - "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)")), |
|
| 93 | - "SHORT_DATE_FORMAT" => array(__("Short date format")), |
|
| 94 | - "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines")), |
|
| 95 | - "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")), |
|
| 96 | - "SSL_CERT_SERIAL" => array(__("SSL client certificate")), |
|
| 97 | - "STRIP_IMAGES" => array(__("Do not embed media")), |
|
| 98 | - "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")), |
|
| 99 | - "USER_STYLESHEET" => array(__("Customize stylesheet")), |
|
| 100 | - "USER_TIMEZONE" => array(__("Time zone")), |
|
| 101 | - "VFEED_GROUP_BY_FEED" => array(__("Group by feed"), __("Group multiple-feed output by originating feed")), |
|
| 102 | - "USER_LANGUAGE" => array(__("Language")), |
|
| 103 | - "USER_CSS_THEME" => array(__("Theme")) |
|
| 104 | - ]; |
|
| 105 | - |
|
| 106 | - $this->pref_blacklist = ["ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES", |
|
| 107 | - "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT", |
|
| 108 | - "FEEDS_SORT_BY_UNREAD", "USER_STYLESHEET"]; |
|
| 109 | - |
|
| 110 | - /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */ |
|
| 111 | - |
|
| 112 | - $this->profile_blacklist = ["ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", |
|
| 113 | - "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", |
|
| 114 | - "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", |
|
| 115 | - "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", |
|
| 116 | - "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"]; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function changepassword() { |
|
| 120 | - |
|
| 121 | - if (defined('_TTRSS_DEMO_INSTANCE')) { |
|
| 122 | - print "ERROR: ".format_error("Disabled in demo version."); |
|
| 123 | - return; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $old_pw = clean($_POST["old_password"]); |
|
| 127 | - $new_pw = clean($_POST["new_password"]); |
|
| 128 | - $con_pw = clean($_POST["confirm_password"]); |
|
| 129 | - |
|
| 130 | - if ($old_pw == $new_pw) { |
|
| 131 | - print "ERROR: ".format_error("New password must be different from the old one."); |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - if ($old_pw == "") { |
|
| 136 | - print "ERROR: ".format_error("Old password cannot be blank."); |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if ($new_pw == "") { |
|
| 141 | - print "ERROR: ".format_error("New password cannot be blank."); |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if ($new_pw != $con_pw) { |
|
| 146 | - print "ERROR: ".format_error("Entered passwords do not match."); |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 151 | - |
|
| 152 | - if (method_exists($authenticator, "change_password")) { |
|
| 153 | - print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw)); |
|
| 154 | - } else { |
|
| 155 | - print "ERROR: ".format_error("Function not supported by authentication module."); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - public function saveconfig() { |
|
| 160 | - $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); |
|
| 161 | - |
|
| 162 | - foreach ($boolean_prefs as $pref) { |
|
| 163 | - if (!isset($_POST[$pref])) $_POST[$pref] = 'false'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $need_reload = false; |
|
| 167 | - |
|
| 168 | - foreach (array_keys($_POST) as $pref_name) { |
|
| 169 | - |
|
| 170 | - $value = $_POST[$pref_name]; |
|
| 171 | - |
|
| 172 | - switch ($pref_name) { |
|
| 173 | - case 'DIGEST_PREFERRED_TIME': |
|
| 174 | - if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
| 175 | - |
|
| 176 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
| 5 | + private $pref_help = []; |
|
| 6 | + private $pref_item_map = []; |
|
| 7 | + private $pref_blacklist = []; |
|
| 8 | + private $profile_blacklist = []; |
|
| 9 | + |
|
| 10 | + public function csrf_ignore($method) { |
|
| 11 | + $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles"); |
|
| 12 | + |
|
| 13 | + return array_search($method, $csrf_ignored) !== false; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + public function __construct($args) { |
|
| 17 | + parent::__construct($args); |
|
| 18 | + |
|
| 19 | + $this->pref_item_map = [ |
|
| 20 | + __('General') => [ |
|
| 21 | + 'USER_LANGUAGE', |
|
| 22 | + 'USER_TIMEZONE', |
|
| 23 | + 'BLOCK_SEPARATOR', |
|
| 24 | + 'USER_CSS_THEME', |
|
| 25 | + 'BLOCK_SEPARATOR', |
|
| 26 | + 'ENABLE_API_ACCESS', |
|
| 27 | + ], |
|
| 28 | + __('Feeds') => [ |
|
| 29 | + 'DEFAULT_UPDATE_INTERVAL', |
|
| 30 | + 'FRESH_ARTICLE_MAX_AGE', |
|
| 31 | + 'DEFAULT_SEARCH_LANGUAGE', |
|
| 32 | + 'BLOCK_SEPARATOR', |
|
| 33 | + 'ENABLE_FEED_CATS', |
|
| 34 | + 'BLOCK_SEPARATOR', |
|
| 35 | + 'CONFIRM_FEED_CATCHUP', |
|
| 36 | + 'ON_CATCHUP_SHOW_NEXT_FEED', |
|
| 37 | + 'BLOCK_SEPARATOR', |
|
| 38 | + 'HIDE_READ_FEEDS', |
|
| 39 | + 'HIDE_READ_SHOWS_SPECIAL', |
|
| 40 | + ], |
|
| 41 | + __('Articles') => [ |
|
| 42 | + 'PURGE_OLD_DAYS', |
|
| 43 | + 'PURGE_UNREAD_ARTICLES', |
|
| 44 | + 'BLOCK_SEPARATOR', |
|
| 45 | + 'COMBINED_DISPLAY_MODE', |
|
| 46 | + 'CDM_EXPANDED', |
|
| 47 | + 'BLOCK_SEPARATOR', |
|
| 48 | + 'CDM_AUTO_CATCHUP', |
|
| 49 | + 'VFEED_GROUP_BY_FEED', |
|
| 50 | + 'BLOCK_SEPARATOR', |
|
| 51 | + 'SHOW_CONTENT_PREVIEW', |
|
| 52 | + 'STRIP_IMAGES', |
|
| 53 | + ], |
|
| 54 | + __('Digest') => [ |
|
| 55 | + 'DIGEST_ENABLE', |
|
| 56 | + 'DIGEST_CATCHUP', |
|
| 57 | + 'DIGEST_PREFERRED_TIME', |
|
| 58 | + ], |
|
| 59 | + __('Advanced') => [ |
|
| 60 | + 'BLACKLISTED_TAGS', |
|
| 61 | + 'BLOCK_SEPARATOR', |
|
| 62 | + 'LONG_DATE_FORMAT', |
|
| 63 | + 'SHORT_DATE_FORMAT', |
|
| 64 | + 'BLOCK_SEPARATOR', |
|
| 65 | + 'SSL_CERT_SERIAL', |
|
| 66 | + ] |
|
| 67 | + ]; |
|
| 68 | + |
|
| 69 | + $this->pref_help = [ |
|
| 70 | + "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""), |
|
| 71 | + "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("Never apply these tags automatically (comma-separated list).")), |
|
| 72 | + "DEFAULT_SEARCH_LANGUAGE" => array(__("Default language"), __("Used for full-text search")), |
|
| 73 | + "CDM_AUTO_CATCHUP" => array(__("Mark read on scroll"), __("Mark articles as read as you scroll past them")), |
|
| 74 | + "CDM_EXPANDED" => array(__("Always expand articles")), |
|
| 75 | + "COMBINED_DISPLAY_MODE" => array(__("Combined mode"), __("Show flat list of articles instead of separate panels")), |
|
| 76 | + "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feeds as read")), |
|
| 77 | + "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once")), |
|
| 78 | + "DEFAULT_UPDATE_INTERVAL" => array(__("Default update interval")), |
|
| 79 | + "DIGEST_CATCHUP" => array(__("Mark sent articles as read")), |
|
| 80 | + "DIGEST_ENABLE" => array(__("Enable digest"), __("Send daily digest of new (and unread) headlines to your e-mail address")), |
|
| 81 | + "DIGEST_PREFERRED_TIME" => array(__("Try to send around this time"), __("Time in UTC")), |
|
| 82 | + "ENABLE_API_ACCESS" => array(__("Enable API"), __("Allows accessing this account through the API")), |
|
| 83 | + "ENABLE_FEED_CATS" => array(__("Enable categories")), |
|
| 84 | + "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""), |
|
| 85 | + "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles"), "<strong>" . __("hours") . "</strong>"), |
|
| 86 | + "HIDE_READ_FEEDS" => array(__("Hide read feeds")), |
|
| 87 | + "HIDE_READ_SHOWS_SPECIAL" => array(__("Always show special feeds"), __("While hiding read feeds")), |
|
| 88 | + "LONG_DATE_FORMAT" => array(__("Long date format"), __("Syntax is identical to PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), |
|
| 89 | + "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("Automatically show next feed"), __("After marking one as read")), |
|
| 90 | + "PURGE_OLD_DAYS" => array(__("Purge articles older than"), __("<strong>days</strong> (0 disables)")), |
|
| 91 | + "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles")), |
|
| 92 | + "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)")), |
|
| 93 | + "SHORT_DATE_FORMAT" => array(__("Short date format")), |
|
| 94 | + "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines")), |
|
| 95 | + "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")), |
|
| 96 | + "SSL_CERT_SERIAL" => array(__("SSL client certificate")), |
|
| 97 | + "STRIP_IMAGES" => array(__("Do not embed media")), |
|
| 98 | + "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")), |
|
| 99 | + "USER_STYLESHEET" => array(__("Customize stylesheet")), |
|
| 100 | + "USER_TIMEZONE" => array(__("Time zone")), |
|
| 101 | + "VFEED_GROUP_BY_FEED" => array(__("Group by feed"), __("Group multiple-feed output by originating feed")), |
|
| 102 | + "USER_LANGUAGE" => array(__("Language")), |
|
| 103 | + "USER_CSS_THEME" => array(__("Theme")) |
|
| 104 | + ]; |
|
| 105 | + |
|
| 106 | + $this->pref_blacklist = ["ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES", |
|
| 107 | + "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT", |
|
| 108 | + "FEEDS_SORT_BY_UNREAD", "USER_STYLESHEET"]; |
|
| 109 | + |
|
| 110 | + /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */ |
|
| 111 | + |
|
| 112 | + $this->profile_blacklist = ["ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", |
|
| 113 | + "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", |
|
| 114 | + "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", |
|
| 115 | + "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", |
|
| 116 | + "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"]; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function changepassword() { |
|
| 120 | + |
|
| 121 | + if (defined('_TTRSS_DEMO_INSTANCE')) { |
|
| 122 | + print "ERROR: ".format_error("Disabled in demo version."); |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $old_pw = clean($_POST["old_password"]); |
|
| 127 | + $new_pw = clean($_POST["new_password"]); |
|
| 128 | + $con_pw = clean($_POST["confirm_password"]); |
|
| 129 | + |
|
| 130 | + if ($old_pw == $new_pw) { |
|
| 131 | + print "ERROR: ".format_error("New password must be different from the old one."); |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + if ($old_pw == "") { |
|
| 136 | + print "ERROR: ".format_error("Old password cannot be blank."); |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if ($new_pw == "") { |
|
| 141 | + print "ERROR: ".format_error("New password cannot be blank."); |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if ($new_pw != $con_pw) { |
|
| 146 | + print "ERROR: ".format_error("Entered passwords do not match."); |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 151 | + |
|
| 152 | + if (method_exists($authenticator, "change_password")) { |
|
| 153 | + print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw)); |
|
| 154 | + } else { |
|
| 155 | + print "ERROR: ".format_error("Function not supported by authentication module."); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + public function saveconfig() { |
|
| 160 | + $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); |
|
| 161 | + |
|
| 162 | + foreach ($boolean_prefs as $pref) { |
|
| 163 | + if (!isset($_POST[$pref])) $_POST[$pref] = 'false'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $need_reload = false; |
|
| 167 | + |
|
| 168 | + foreach (array_keys($_POST) as $pref_name) { |
|
| 169 | + |
|
| 170 | + $value = $_POST[$pref_name]; |
|
| 171 | + |
|
| 172 | + switch ($pref_name) { |
|
| 173 | + case 'DIGEST_PREFERRED_TIME': |
|
| 174 | + if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
| 175 | + |
|
| 176 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
| 177 | 177 | last_digest_sent = NULL WHERE id = ?"); |
| 178 | - $sth->execute([$_SESSION['uid']]); |
|
| 178 | + $sth->execute([$_SESSION['uid']]); |
|
| 179 | 179 | |
| 180 | - } |
|
| 181 | - break; |
|
| 182 | - case 'USER_LANGUAGE': |
|
| 183 | - if (!$need_reload) $need_reload = $_SESSION["language"] != $value; |
|
| 184 | - break; |
|
| 185 | - |
|
| 186 | - case 'USER_CSS_THEME': |
|
| 187 | - if (!$need_reload) $need_reload = get_pref($pref_name) != $value; |
|
| 188 | - break; |
|
| 189 | - } |
|
| 180 | + } |
|
| 181 | + break; |
|
| 182 | + case 'USER_LANGUAGE': |
|
| 183 | + if (!$need_reload) $need_reload = $_SESSION["language"] != $value; |
|
| 184 | + break; |
|
| 190 | 185 | |
| 191 | - set_pref($pref_name, $value); |
|
| 192 | - } |
|
| 186 | + case 'USER_CSS_THEME': |
|
| 187 | + if (!$need_reload) $need_reload = get_pref($pref_name) != $value; |
|
| 188 | + break; |
|
| 189 | + } |
|
| 193 | 190 | |
| 194 | - if ($need_reload) { |
|
| 195 | - print "PREFS_NEED_RELOAD"; |
|
| 196 | - } else { |
|
| 197 | - print __("The configuration was saved."); |
|
| 198 | - } |
|
| 199 | - } |
|
| 191 | + set_pref($pref_name, $value); |
|
| 192 | + } |
|
| 200 | 193 | |
| 201 | - public function changeemail() { |
|
| 194 | + if ($need_reload) { |
|
| 195 | + print "PREFS_NEED_RELOAD"; |
|
| 196 | + } else { |
|
| 197 | + print __("The configuration was saved."); |
|
| 198 | + } |
|
| 199 | + } |
|
| 202 | 200 | |
| 203 | - $email = clean($_POST["email"]); |
|
| 204 | - $full_name = clean($_POST["full_name"]); |
|
| 205 | - $active_uid = $_SESSION["uid"]; |
|
| 201 | + public function changeemail() { |
|
| 206 | 202 | |
| 207 | - $sth = $this->pdo->prepare("SELECT email, login, full_name FROM ttrss_users WHERE id = ?"); |
|
| 208 | - $sth->execute([$active_uid]); |
|
| 203 | + $email = clean($_POST["email"]); |
|
| 204 | + $full_name = clean($_POST["full_name"]); |
|
| 205 | + $active_uid = $_SESSION["uid"]; |
|
| 209 | 206 | |
| 210 | - if ($row = $sth->fetch()) { |
|
| 211 | - $old_email = $row["email"]; |
|
| 207 | + $sth = $this->pdo->prepare("SELECT email, login, full_name FROM ttrss_users WHERE id = ?"); |
|
| 208 | + $sth->execute([$active_uid]); |
|
| 212 | 209 | |
| 213 | - if ($old_email != $email) { |
|
| 214 | - $mailer = new Mailer(); |
|
| 210 | + if ($row = $sth->fetch()) { |
|
| 211 | + $old_email = $row["email"]; |
|
| 215 | 212 | |
| 216 | - require_once "lib/MiniTemplator.class.php"; |
|
| 213 | + if ($old_email != $email) { |
|
| 214 | + $mailer = new Mailer(); |
|
| 217 | 215 | |
| 218 | - $tpl = new MiniTemplator; |
|
| 216 | + require_once "lib/MiniTemplator.class.php"; |
|
| 219 | 217 | |
| 220 | - $tpl->readTemplateFromFile("templates/mail_change_template.txt"); |
|
| 218 | + $tpl = new MiniTemplator; |
|
| 221 | 219 | |
| 222 | - $tpl->setVariable('LOGIN', $row["login"]); |
|
| 223 | - $tpl->setVariable('NEWMAIL', $email); |
|
| 224 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
| 220 | + $tpl->readTemplateFromFile("templates/mail_change_template.txt"); |
|
| 225 | 221 | |
| 226 | - $tpl->addBlock('message'); |
|
| 222 | + $tpl->setVariable('LOGIN', $row["login"]); |
|
| 223 | + $tpl->setVariable('NEWMAIL', $email); |
|
| 224 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
| 227 | 225 | |
| 228 | - $tpl->generateOutputToString($message); |
|
| 226 | + $tpl->addBlock('message'); |
|
| 229 | 227 | |
| 230 | - $mailer->mail(["to_name" => $row["login"], |
|
| 231 | - "to_address" => $row["email"], |
|
| 232 | - "subject" => "[tt-rss] Mail address change notification", |
|
| 233 | - "message" => $message]); |
|
| 228 | + $tpl->generateOutputToString($message); |
|
| 234 | 229 | |
| 235 | - } |
|
| 236 | - } |
|
| 230 | + $mailer->mail(["to_name" => $row["login"], |
|
| 231 | + "to_address" => $row["email"], |
|
| 232 | + "subject" => "[tt-rss] Mail address change notification", |
|
| 233 | + "message" => $message]); |
|
| 234 | + |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?, |
|
| 238 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?, |
|
| 239 | 239 | full_name = ? WHERE id = ?"); |
| 240 | - $sth->execute([$email, $full_name, $active_uid]); |
|
| 240 | + $sth->execute([$email, $full_name, $active_uid]); |
|
| 241 | 241 | |
| 242 | - print __("Your personal data has been saved."); |
|
| 242 | + print __("Your personal data has been saved."); |
|
| 243 | 243 | |
| 244 | - return; |
|
| 245 | - } |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - public function resetconfig() { |
|
| 247 | + public function resetconfig() { |
|
| 248 | 248 | |
| 249 | - $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
|
| 249 | + $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
|
| 250 | 250 | |
| 251 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs |
|
| 251 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs |
|
| 252 | 252 | WHERE (profile = :profile OR (:profile IS NULL AND profile IS NULL)) |
| 253 | 253 | AND owner_uid = :uid"); |
| 254 | - $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); |
|
| 254 | + $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); |
|
| 255 | 255 | |
| 256 | - initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
|
| 256 | + initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
|
| 257 | 257 | |
| 258 | - echo __("Your preferences are now set to default values."); |
|
| 259 | - } |
|
| 258 | + echo __("Your preferences are now set to default values."); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - public function index() { |
|
| 261 | + public function index() { |
|
| 262 | 262 | |
| 263 | - global $access_level_names; |
|
| 263 | + global $access_level_names; |
|
| 264 | 264 | |
| 265 | - $_SESSION["prefs_op_result"] = ""; |
|
| 265 | + $_SESSION["prefs_op_result"] = ""; |
|
| 266 | 266 | |
| 267 | - print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
| 268 | - print "<div dojoType='dijit.layout.AccordionPane' |
|
| 267 | + print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
| 268 | + print "<div dojoType='dijit.layout.AccordionPane' |
|
| 269 | 269 | title=\"<i class='material-icons'>person</i> ".__('Personal data / Authentication')."\">"; |
| 270 | 270 | |
| 271 | - print "<div dojoType='dijit.layout.TabContainer'>"; |
|
| 272 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Personal data')."\">"; |
|
| 271 | + print "<div dojoType='dijit.layout.TabContainer'>"; |
|
| 272 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Personal data')."\">"; |
|
| 273 | 273 | |
| 274 | - print "<form dojoType='dijit.form.Form' id='changeUserdataForm'>"; |
|
| 274 | + print "<form dojoType='dijit.form.Form' id='changeUserdataForm'>"; |
|
| 275 | 275 | |
| 276 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 276 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 277 | 277 | evt.preventDefault(); |
| 278 | 278 | if (this.validate()) { |
| 279 | 279 | Notify.progress('Saving data...', true); |
@@ -287,61 +287,61 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | </script>"; |
| 289 | 289 | |
| 290 | - $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, |
|
| 290 | + $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, |
|
| 291 | 291 | access_level FROM ttrss_users |
| 292 | 292 | WHERE id = ?"); |
| 293 | - $sth->execute([$_SESSION["uid"]]); |
|
| 294 | - $row = $sth->fetch(); |
|
| 295 | - |
|
| 296 | - $email = htmlspecialchars($row["email"]); |
|
| 297 | - $full_name = htmlspecialchars($row["full_name"]); |
|
| 298 | - $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
| 299 | - |
|
| 300 | - print "<fieldset>"; |
|
| 301 | - print "<label>".__('Full name:')."</label>"; |
|
| 302 | - print "<input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value='$full_name'>"; |
|
| 303 | - print "</fieldset>"; |
|
| 304 | - |
|
| 305 | - print "<fieldset>"; |
|
| 306 | - print "<label>".__('E-mail:')."</label>"; |
|
| 307 | - print "<input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value='$email'>"; |
|
| 308 | - print "</fieldset>"; |
|
| 309 | - |
|
| 310 | - if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
|
| 311 | - |
|
| 312 | - $access_level = $row["access_level"]; |
|
| 313 | - print "<fieldset>"; |
|
| 314 | - print "<label>".__('Access level:')."</label>"; |
|
| 315 | - print $access_level_names[$access_level]; |
|
| 316 | - print "</fieldset>"; |
|
| 317 | - } |
|
| 293 | + $sth->execute([$_SESSION["uid"]]); |
|
| 294 | + $row = $sth->fetch(); |
|
| 318 | 295 | |
| 319 | - print_hidden("op", "pref-prefs"); |
|
| 320 | - print_hidden("method", "changeemail"); |
|
| 296 | + $email = htmlspecialchars($row["email"]); |
|
| 297 | + $full_name = htmlspecialchars($row["full_name"]); |
|
| 298 | + $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
| 321 | 299 | |
| 322 | - print "<hr/>"; |
|
| 300 | + print "<fieldset>"; |
|
| 301 | + print "<label>".__('Full name:')."</label>"; |
|
| 302 | + print "<input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value='$full_name'>"; |
|
| 303 | + print "</fieldset>"; |
|
| 323 | 304 | |
| 324 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
| 325 | - __("Save data")."</button>"; |
|
| 305 | + print "<fieldset>"; |
|
| 306 | + print "<label>".__('E-mail:')."</label>"; |
|
| 307 | + print "<input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value='$email'>"; |
|
| 308 | + print "</fieldset>"; |
|
| 326 | 309 | |
| 327 | - print "</form>"; |
|
| 310 | + if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
|
| 328 | 311 | |
| 329 | - print "</div>"; # content pane |
|
| 330 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Password')."\">"; |
|
| 312 | + $access_level = $row["access_level"]; |
|
| 313 | + print "<fieldset>"; |
|
| 314 | + print "<label>".__('Access level:')."</label>"; |
|
| 315 | + print $access_level_names[$access_level]; |
|
| 316 | + print "</fieldset>"; |
|
| 317 | + } |
|
| 331 | 318 | |
| 332 | - if ($_SESSION["auth_module"]) { |
|
| 333 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 334 | - } else { |
|
| 335 | - $authenticator = false; |
|
| 336 | - } |
|
| 319 | + print_hidden("op", "pref-prefs"); |
|
| 320 | + print_hidden("method", "changeemail"); |
|
| 337 | 321 | |
| 338 | - if ($authenticator && method_exists($authenticator, "change_password")) { |
|
| 322 | + print "<hr/>"; |
|
| 339 | 323 | |
| 340 | - print "<div style='display : none' id='pwd_change_infobox'></div>"; |
|
| 324 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
| 325 | + __("Save data")."</button>"; |
|
| 341 | 326 | |
| 342 | - print "<form dojoType='dijit.form.Form'>"; |
|
| 327 | + print "</form>"; |
|
| 343 | 328 | |
| 344 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 329 | + print "</div>"; # content pane |
|
| 330 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Password')."\">"; |
|
| 331 | + |
|
| 332 | + if ($_SESSION["auth_module"]) { |
|
| 333 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 334 | + } else { |
|
| 335 | + $authenticator = false; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ($authenticator && method_exists($authenticator, "change_password")) { |
|
| 339 | + |
|
| 340 | + print "<div style='display : none' id='pwd_change_infobox'></div>"; |
|
| 341 | + |
|
| 342 | + print "<form dojoType='dijit.form.Form'>"; |
|
| 343 | + |
|
| 344 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 345 | 345 | evt.preventDefault(); |
| 346 | 346 | if (this.validate()) { |
| 347 | 347 | Notify.progress('Changing password...', true); |
@@ -370,71 +370,71 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | </script>"; |
| 372 | 372 | |
| 373 | - if ($otp_enabled) { |
|
| 374 | - print_notice(__("Changing your current password will disable OTP.")); |
|
| 375 | - } |
|
| 373 | + if ($otp_enabled) { |
|
| 374 | + print_notice(__("Changing your current password will disable OTP.")); |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | - print "<fieldset>"; |
|
| 378 | - print "<label>".__("Old password:")."</label>"; |
|
| 379 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>"; |
|
| 380 | - print "</fieldset>"; |
|
| 377 | + print "<fieldset>"; |
|
| 378 | + print "<label>".__("Old password:")."</label>"; |
|
| 379 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>"; |
|
| 380 | + print "</fieldset>"; |
|
| 381 | 381 | |
| 382 | - print "<fieldset>"; |
|
| 383 | - print "<label>".__("New password:")."</label>"; |
|
| 384 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='new_password'>"; |
|
| 385 | - print "</fieldset>"; |
|
| 382 | + print "<fieldset>"; |
|
| 383 | + print "<label>".__("New password:")."</label>"; |
|
| 384 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='new_password'>"; |
|
| 385 | + print "</fieldset>"; |
|
| 386 | 386 | |
| 387 | - print "<fieldset>"; |
|
| 388 | - print "<label>".__("Confirm password:")."</label>"; |
|
| 389 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='confirm_password'>"; |
|
| 390 | - print "</fieldset>"; |
|
| 387 | + print "<fieldset>"; |
|
| 388 | + print "<label>".__("Confirm password:")."</label>"; |
|
| 389 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='confirm_password'>"; |
|
| 390 | + print "</fieldset>"; |
|
| 391 | 391 | |
| 392 | - print_hidden("op", "pref-prefs"); |
|
| 393 | - print_hidden("method", "changepassword"); |
|
| 392 | + print_hidden("op", "pref-prefs"); |
|
| 393 | + print_hidden("method", "changepassword"); |
|
| 394 | 394 | |
| 395 | - print "<hr/>"; |
|
| 395 | + print "<hr/>"; |
|
| 396 | 396 | |
| 397 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
| 398 | - __("Change password")."</button>"; |
|
| 397 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
| 398 | + __("Change password")."</button>"; |
|
| 399 | 399 | |
| 400 | - print "</form>"; |
|
| 400 | + print "</form>"; |
|
| 401 | 401 | |
| 402 | - print "</div>"; # content pane |
|
| 402 | + print "</div>"; # content pane |
|
| 403 | 403 | |
| 404 | - if ($_SESSION["auth_module"] == "auth_internal") { |
|
| 404 | + if ($_SESSION["auth_module"] == "auth_internal") { |
|
| 405 | 405 | |
| 406 | - print "<div dojoType='dijit.layout.ContentPane' title=\"" . __('App passwords') . "\">"; |
|
| 406 | + print "<div dojoType='dijit.layout.ContentPane' title=\"" . __('App passwords') . "\">"; |
|
| 407 | 407 | |
| 408 | - print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); |
|
| 408 | + print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); |
|
| 409 | 409 | |
| 410 | - print "<div id='app_passwords_holder'>"; |
|
| 411 | - $this->appPasswordList(); |
|
| 412 | - print "</div>"; |
|
| 410 | + print "<div id='app_passwords_holder'>"; |
|
| 411 | + $this->appPasswordList(); |
|
| 412 | + print "</div>"; |
|
| 413 | 413 | |
| 414 | - print "<hr>"; |
|
| 414 | + print "<hr>"; |
|
| 415 | 415 | |
| 416 | - print "<button style='float : left' class='alt-primary' dojoType='dijit.form.Button' |
|
| 416 | + print "<button style='float : left' class='alt-primary' dojoType='dijit.form.Button' |
|
| 417 | 417 | onclick=\"Helpers.AppPasswords.generate()\">" . |
| 418 | - __('Generate new password') . "</button> "; |
|
| 418 | + __('Generate new password') . "</button> "; |
|
| 419 | 419 | |
| 420 | - print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button' |
|
| 420 | + print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button' |
|
| 421 | 421 | onclick=\"Helpers.AppPasswords.removeSelected()\">" . |
| 422 | - __('Remove selected passwords') . "</button>"; |
|
| 422 | + __('Remove selected passwords') . "</button>"; |
|
| 423 | 423 | |
| 424 | - print "</div>"; # content pane |
|
| 425 | - } |
|
| 424 | + print "</div>"; # content pane |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('One time passwords / Authenticator')."\">"; |
|
| 427 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('One time passwords / Authenticator')."\">"; |
|
| 428 | 428 | |
| 429 | - if ($_SESSION["auth_module"] == "auth_internal") { |
|
| 429 | + if ($_SESSION["auth_module"] == "auth_internal") { |
|
| 430 | 430 | |
| 431 | - if ($otp_enabled) { |
|
| 431 | + if ($otp_enabled) { |
|
| 432 | 432 | |
| 433 | - print_warning("One time passwords are currently enabled. Enter your current password below to disable."); |
|
| 433 | + print_warning("One time passwords are currently enabled. Enter your current password below to disable."); |
|
| 434 | 434 | |
| 435 | - print "<form dojoType='dijit.form.Form'>"; |
|
| 435 | + print "<form dojoType='dijit.form.Form'>"; |
|
| 436 | 436 | |
| 437 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 437 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 438 | 438 | evt.preventDefault(); |
| 439 | 439 | if (this.validate()) { |
| 440 | 440 | Notify.progress('Disabling OTP', true); |
@@ -453,49 +453,49 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | </script>"; |
| 455 | 455 | |
| 456 | - print "<fieldset>"; |
|
| 457 | - print "<label>".__("Your password:")."</label>"; |
|
| 458 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>"; |
|
| 459 | - print "</fieldset>"; |
|
| 456 | + print "<fieldset>"; |
|
| 457 | + print "<label>".__("Your password:")."</label>"; |
|
| 458 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>"; |
|
| 459 | + print "</fieldset>"; |
|
| 460 | 460 | |
| 461 | - print_hidden("op", "pref-prefs"); |
|
| 462 | - print_hidden("method", "otpdisable"); |
|
| 461 | + print_hidden("op", "pref-prefs"); |
|
| 462 | + print_hidden("method", "otpdisable"); |
|
| 463 | 463 | |
| 464 | - print "<hr/>"; |
|
| 464 | + print "<hr/>"; |
|
| 465 | 465 | |
| 466 | - print "<button dojoType='dijit.form.Button' type='submit'>". |
|
| 467 | - __("Disable OTP")."</button>"; |
|
| 466 | + print "<button dojoType='dijit.form.Button' type='submit'>". |
|
| 467 | + __("Disable OTP")."</button>"; |
|
| 468 | 468 | |
| 469 | - print "</form>"; |
|
| 469 | + print "</form>"; |
|
| 470 | 470 | |
| 471 | - } else { |
|
| 471 | + } else { |
|
| 472 | 472 | |
| 473 | - print_warning("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."); |
|
| 474 | - print_notice("You will need to generate app passwords for the API clients if you enable OTP."); |
|
| 473 | + print_warning("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."); |
|
| 474 | + print_notice("You will need to generate app passwords for the API clients if you enable OTP."); |
|
| 475 | 475 | |
| 476 | - if (function_exists("imagecreatefromstring")) { |
|
| 477 | - print "<h3>" . __("Scan the following code by the Authenticator application or copy the key manually") . "</h3>"; |
|
| 476 | + if (function_exists("imagecreatefromstring")) { |
|
| 477 | + print "<h3>" . __("Scan the following code by the Authenticator application or copy the key manually") . "</h3>"; |
|
| 478 | 478 | |
| 479 | - $csrf_token = $_SESSION["csrf_token"]; |
|
| 480 | - print "<img alt='otp qr-code' src='backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token'>"; |
|
| 481 | - } else { |
|
| 482 | - print_error("PHP GD functions are required to generate QR codes."); |
|
| 483 | - print "<h3>" . __("Use the following OTP key with a compatible Authenticator application") . "</h3>"; |
|
| 484 | - } |
|
| 479 | + $csrf_token = $_SESSION["csrf_token"]; |
|
| 480 | + print "<img alt='otp qr-code' src='backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token'>"; |
|
| 481 | + } else { |
|
| 482 | + print_error("PHP GD functions are required to generate QR codes."); |
|
| 483 | + print "<h3>" . __("Use the following OTP key with a compatible Authenticator application") . "</h3>"; |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - print "<form dojoType='dijit.form.Form' id='changeOtpForm'>"; |
|
| 486 | + print "<form dojoType='dijit.form.Form' id='changeOtpForm'>"; |
|
| 487 | 487 | |
| 488 | - $otp_secret = $this->otpsecret(); |
|
| 488 | + $otp_secret = $this->otpsecret(); |
|
| 489 | 489 | |
| 490 | - print "<fieldset>"; |
|
| 491 | - print "<label>".__("OTP Key:")."</label>"; |
|
| 492 | - print "<input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value='$otp_secret' size='32'>"; |
|
| 493 | - print "</fieldset>"; |
|
| 490 | + print "<fieldset>"; |
|
| 491 | + print "<label>".__("OTP Key:")."</label>"; |
|
| 492 | + print "<input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value='$otp_secret' size='32'>"; |
|
| 493 | + print "</fieldset>"; |
|
| 494 | 494 | |
| 495 | - print_hidden("op", "pref-prefs"); |
|
| 496 | - print_hidden("method", "otpenable"); |
|
| 495 | + print_hidden("op", "pref-prefs"); |
|
| 496 | + print_hidden("method", "otpenable"); |
|
| 497 | 497 | |
| 498 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 498 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 499 | 499 | evt.preventDefault(); |
| 500 | 500 | if (this.validate()) { |
| 501 | 501 | Notify.progress('Saving data...', true); |
@@ -514,43 +514,43 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | </script>"; |
| 516 | 516 | |
| 517 | - print "<fieldset>"; |
|
| 518 | - print "<label>".__("Your password:")."</label>"; |
|
| 519 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' |
|
| 517 | + print "<fieldset>"; |
|
| 518 | + print "<label>".__("Your password:")."</label>"; |
|
| 519 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' |
|
| 520 | 520 | name='password'>"; |
| 521 | - print "</fieldset>"; |
|
| 521 | + print "</fieldset>"; |
|
| 522 | 522 | |
| 523 | - print "<fieldset>"; |
|
| 524 | - print "<label>".__("One time password:")."</label>"; |
|
| 525 | - print "<input dojoType='dijit.form.ValidationTextBox' autocomplete='off' |
|
| 523 | + print "<fieldset>"; |
|
| 524 | + print "<label>".__("One time password:")."</label>"; |
|
| 525 | + print "<input dojoType='dijit.form.ValidationTextBox' autocomplete='off' |
|
| 526 | 526 | required='1' name='otp'>"; |
| 527 | - print "</fieldset>"; |
|
| 527 | + print "</fieldset>"; |
|
| 528 | 528 | |
| 529 | - print "<hr/>"; |
|
| 530 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
| 531 | - __("Enable OTP")."</button>"; |
|
| 529 | + print "<hr/>"; |
|
| 530 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
| 531 | + __("Enable OTP")."</button>"; |
|
| 532 | 532 | |
| 533 | - print "</form>"; |
|
| 533 | + print "</form>"; |
|
| 534 | 534 | |
| 535 | - } |
|
| 536 | - } |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - print "</div>"; # content pane |
|
| 539 | - print "</div>"; # tab container |
|
| 538 | + print "</div>"; # content pane |
|
| 539 | + print "</div>"; # tab container |
|
| 540 | 540 | |
| 541 | - } |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 544 | - "hook_prefs_tab_section", "prefPrefsAuth"); |
|
| 543 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 544 | + "hook_prefs_tab_section", "prefPrefsAuth"); |
|
| 545 | 545 | |
| 546 | - print "</div>"; #pane |
|
| 546 | + print "</div>"; #pane |
|
| 547 | 547 | |
| 548 | - print "<div dojoType='dijit.layout.AccordionPane' selected='true' |
|
| 548 | + print "<div dojoType='dijit.layout.AccordionPane' selected='true' |
|
| 549 | 549 | title=\"<i class='material-icons'>settings</i> ".__('Preferences')."\">"; |
| 550 | 550 | |
| 551 | - print "<form dojoType='dijit.form.Form' id='changeSettingsForm'>"; |
|
| 551 | + print "<form dojoType='dijit.form.Form' id='changeSettingsForm'>"; |
|
| 552 | 552 | |
| 553 | - print "<script type='dojo/method' event='onSubmit' args='evt, quit'> |
|
| 553 | + print "<script type='dojo/method' event='onSubmit' args='evt, quit'> |
|
| 554 | 554 | if (evt) evt.preventDefault(); |
| 555 | 555 | if (this.validate()) { |
| 556 | 556 | console.log(dojo.objectToQuery(this.getValues())); |
@@ -572,23 +572,23 @@ discard block |
||
| 572 | 572 | } |
| 573 | 573 | </script>"; |
| 574 | 574 | |
| 575 | - print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
| 575 | + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
| 576 | 576 | |
| 577 | - print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
| 577 | + print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
| 578 | 578 | |
| 579 | - $profile = $_SESSION["profile"]; |
|
| 579 | + $profile = $_SESSION["profile"]; |
|
| 580 | 580 | |
| 581 | - if ($profile) { |
|
| 582 | - print_notice(__("Some preferences are only available in default profile.")); |
|
| 581 | + if ($profile) { |
|
| 582 | + print_notice(__("Some preferences are only available in default profile.")); |
|
| 583 | 583 | |
| 584 | - initialize_user_prefs($_SESSION["uid"], $profile); |
|
| 585 | - } else { |
|
| 586 | - initialize_user_prefs($_SESSION["uid"]); |
|
| 587 | - } |
|
| 584 | + initialize_user_prefs($_SESSION["uid"], $profile); |
|
| 585 | + } else { |
|
| 586 | + initialize_user_prefs($_SESSION["uid"]); |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - $prefs_available = []; |
|
| 589 | + $prefs_available = []; |
|
| 590 | 590 | |
| 591 | - $sth = $this->pdo->prepare("SELECT DISTINCT |
|
| 591 | + $sth = $this->pdo->prepare("SELECT DISTINCT |
|
| 592 | 592 | ttrss_user_prefs.pref_name,value,type_name, |
| 593 | 593 | ttrss_prefs_sections.order_id, |
| 594 | 594 | def_value,section_id |
@@ -599,230 +599,230 @@ discard block |
||
| 599 | 599 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
| 600 | 600 | owner_uid = :uid |
| 601 | 601 | ORDER BY ttrss_prefs_sections.order_id,pref_name"); |
| 602 | - $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $profile]); |
|
| 602 | + $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $profile]); |
|
| 603 | 603 | |
| 604 | - $listed_boolean_prefs = []; |
|
| 604 | + $listed_boolean_prefs = []; |
|
| 605 | 605 | |
| 606 | - while ($line = $sth->fetch()) { |
|
| 606 | + while ($line = $sth->fetch()) { |
|
| 607 | 607 | |
| 608 | - if (in_array($line["pref_name"], $this->pref_blacklist)) { |
|
| 609 | - continue; |
|
| 610 | - } |
|
| 608 | + if (in_array($line["pref_name"], $this->pref_blacklist)) { |
|
| 609 | + continue; |
|
| 610 | + } |
|
| 611 | 611 | |
| 612 | - if ($profile && in_array($line["pref_name"], $this->profile_blacklist)) { |
|
| 613 | - continue; |
|
| 614 | - } |
|
| 612 | + if ($profile && in_array($line["pref_name"], $this->profile_blacklist)) { |
|
| 613 | + continue; |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | - $pref_name = $line["pref_name"]; |
|
| 617 | - $short_desc = $this->getShortDesc($pref_name); |
|
| 616 | + $pref_name = $line["pref_name"]; |
|
| 617 | + $short_desc = $this->getShortDesc($pref_name); |
|
| 618 | 618 | |
| 619 | - if (!$short_desc) |
|
| 620 | - continue; |
|
| 619 | + if (!$short_desc) |
|
| 620 | + continue; |
|
| 621 | 621 | |
| 622 | - $prefs_available[$pref_name] = [ |
|
| 623 | - 'type_name' => $line["type_name"], |
|
| 624 | - 'value' => $line['value'], |
|
| 625 | - 'help_text' => $this->getHelpText($pref_name), |
|
| 626 | - 'short_desc' => $short_desc |
|
| 627 | - ]; |
|
| 628 | - } |
|
| 622 | + $prefs_available[$pref_name] = [ |
|
| 623 | + 'type_name' => $line["type_name"], |
|
| 624 | + 'value' => $line['value'], |
|
| 625 | + 'help_text' => $this->getHelpText($pref_name), |
|
| 626 | + 'short_desc' => $short_desc |
|
| 627 | + ]; |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | - foreach (array_keys($this->pref_item_map) as $section) { |
|
| 630 | + foreach (array_keys($this->pref_item_map) as $section) { |
|
| 631 | 631 | |
| 632 | - print "<h2>$section</h2>"; |
|
| 632 | + print "<h2>$section</h2>"; |
|
| 633 | 633 | |
| 634 | - foreach ($this->pref_item_map[$section] as $pref_name) { |
|
| 634 | + foreach ($this->pref_item_map[$section] as $pref_name) { |
|
| 635 | 635 | |
| 636 | - if ($pref_name == 'BLOCK_SEPARATOR' && !$profile) { |
|
| 637 | - print "<hr/>"; |
|
| 638 | - continue; |
|
| 639 | - } |
|
| 636 | + if ($pref_name == 'BLOCK_SEPARATOR' && !$profile) { |
|
| 637 | + print "<hr/>"; |
|
| 638 | + continue; |
|
| 639 | + } |
|
| 640 | 640 | |
| 641 | - if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") { |
|
| 642 | - continue; |
|
| 643 | - } |
|
| 641 | + if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") { |
|
| 642 | + continue; |
|
| 643 | + } |
|
| 644 | 644 | |
| 645 | - if ($item = $prefs_available[$pref_name]) { |
|
| 645 | + if ($item = $prefs_available[$pref_name]) { |
|
| 646 | 646 | |
| 647 | - print "<fieldset class='prefs'>"; |
|
| 647 | + print "<fieldset class='prefs'>"; |
|
| 648 | 648 | |
| 649 | - print "<label for='CB_$pref_name'>"; |
|
| 650 | - print $item['short_desc'] . ":"; |
|
| 651 | - print "</label>"; |
|
| 649 | + print "<label for='CB_$pref_name'>"; |
|
| 650 | + print $item['short_desc'] . ":"; |
|
| 651 | + print "</label>"; |
|
| 652 | 652 | |
| 653 | - $value = $item['value']; |
|
| 654 | - $type_name = $item['type_name']; |
|
| 653 | + $value = $item['value']; |
|
| 654 | + $type_name = $item['type_name']; |
|
| 655 | 655 | |
| 656 | - if ($pref_name == "USER_LANGUAGE") { |
|
| 657 | - print_select_hash($pref_name, $value, get_translations(), |
|
| 658 | - "style='width : 220px; margin : 0px' dojoType='fox.form.Select'"); |
|
| 656 | + if ($pref_name == "USER_LANGUAGE") { |
|
| 657 | + print_select_hash($pref_name, $value, get_translations(), |
|
| 658 | + "style='width : 220px; margin : 0px' dojoType='fox.form.Select'"); |
|
| 659 | 659 | |
| 660 | - } else if ($pref_name == "USER_TIMEZONE") { |
|
| 660 | + } else if ($pref_name == "USER_TIMEZONE") { |
|
| 661 | 661 | |
| 662 | - $timezones = explode("\n", file_get_contents("lib/timezones.txt")); |
|
| 662 | + $timezones = explode("\n", file_get_contents("lib/timezones.txt")); |
|
| 663 | 663 | |
| 664 | - print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); |
|
| 665 | - } else if ($pref_name == "USER_CSS_THEME") { |
|
| 664 | + print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); |
|
| 665 | + } else if ($pref_name == "USER_CSS_THEME") { |
|
| 666 | 666 | |
| 667 | - $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css")); |
|
| 668 | - $themes = array_map("basename", $themes); |
|
| 669 | - $themes = array_filter($themes, "theme_exists"); |
|
| 670 | - asort($themes); |
|
| 667 | + $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css")); |
|
| 668 | + $themes = array_map("basename", $themes); |
|
| 669 | + $themes = array_filter($themes, "theme_exists"); |
|
| 670 | + asort($themes); |
|
| 671 | 671 | |
| 672 | - if (!theme_exists($value)) $value = "default.php"; |
|
| 672 | + if (!theme_exists($value)) $value = "default.php"; |
|
| 673 | 673 | |
| 674 | - print "<select name='$pref_name' id='$pref_name' dojoType='fox.form.Select'>"; |
|
| 674 | + print "<select name='$pref_name' id='$pref_name' dojoType='fox.form.Select'>"; |
|
| 675 | 675 | |
| 676 | - $issel = $value == "default.php" ? "selected='selected'" : ""; |
|
| 677 | - print "<option $issel value='default.php'>".__("default")."</option>"; |
|
| 676 | + $issel = $value == "default.php" ? "selected='selected'" : ""; |
|
| 677 | + print "<option $issel value='default.php'>".__("default")."</option>"; |
|
| 678 | 678 | |
| 679 | - foreach ($themes as $theme) { |
|
| 680 | - $issel = $value == $theme ? "selected='selected'" : ""; |
|
| 681 | - print "<option $issel value='$theme'>$theme</option>"; |
|
| 682 | - } |
|
| 679 | + foreach ($themes as $theme) { |
|
| 680 | + $issel = $value == $theme ? "selected='selected'" : ""; |
|
| 681 | + print "<option $issel value='$theme'>$theme</option>"; |
|
| 682 | + } |
|
| 683 | 683 | |
| 684 | - print "</select>"; |
|
| 684 | + print "</select>"; |
|
| 685 | 685 | |
| 686 | - print " <button dojoType=\"dijit.form.Button\" class='alt-info' |
|
| 686 | + print " <button dojoType=\"dijit.form.Button\" class='alt-info' |
|
| 687 | 687 | onclick=\"Helpers.customizeCSS()\">" . __('Customize') . "</button>"; |
| 688 | 688 | |
| 689 | - print " <button dojoType='dijit.form.Button' onclick='window.open(\"https://tt-rss.org/wiki/Themes\")'> |
|
| 689 | + print " <button dojoType='dijit.form.Button' onclick='window.open(\"https://tt-rss.org/wiki/Themes\")'> |
|
| 690 | 690 | <i class='material-icons'>open_in_new</i> ".__("More themes...")."</button>"; |
| 691 | 691 | |
| 692 | - } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
|
| 692 | + } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
|
| 693 | 693 | |
| 694 | - global $update_intervals_nodefault; |
|
| 694 | + global $update_intervals_nodefault; |
|
| 695 | 695 | |
| 696 | - print_select_hash($pref_name, $value, $update_intervals_nodefault, |
|
| 697 | - 'dojoType="fox.form.Select"'); |
|
| 698 | - } else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") { |
|
| 696 | + print_select_hash($pref_name, $value, $update_intervals_nodefault, |
|
| 697 | + 'dojoType="fox.form.Select"'); |
|
| 698 | + } else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") { |
|
| 699 | 699 | |
| 700 | - print_select($pref_name, $value, Pref_Feeds::get_ts_languages(), |
|
| 701 | - 'dojoType="fox.form.Select"'); |
|
| 700 | + print_select($pref_name, $value, Pref_Feeds::get_ts_languages(), |
|
| 701 | + 'dojoType="fox.form.Select"'); |
|
| 702 | 702 | |
| 703 | - } else if ($type_name == "bool") { |
|
| 703 | + } else if ($type_name == "bool") { |
|
| 704 | 704 | |
| 705 | - array_push($listed_boolean_prefs, $pref_name); |
|
| 705 | + array_push($listed_boolean_prefs, $pref_name); |
|
| 706 | 706 | |
| 707 | - $checked = ($value == "true") ? "checked=\"checked\"" : ""; |
|
| 707 | + $checked = ($value == "true") ? "checked=\"checked\"" : ""; |
|
| 708 | 708 | |
| 709 | - if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { |
|
| 710 | - $disabled = "disabled=\"1\""; |
|
| 711 | - $checked = "checked=\"checked\""; |
|
| 712 | - } else { |
|
| 713 | - $disabled = ""; |
|
| 714 | - } |
|
| 709 | + if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { |
|
| 710 | + $disabled = "disabled=\"1\""; |
|
| 711 | + $checked = "checked=\"checked\""; |
|
| 712 | + } else { |
|
| 713 | + $disabled = ""; |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | - print "<input type='checkbox' name='$pref_name' $checked $disabled |
|
| 716 | + print "<input type='checkbox' name='$pref_name' $checked $disabled |
|
| 717 | 717 | dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>"; |
| 718 | 718 | |
| 719 | - } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
|
| 720 | - 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
|
| 719 | + } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
|
| 720 | + 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
|
| 721 | 721 | |
| 722 | - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
| 722 | + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
| 723 | 723 | |
| 724 | - if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { |
|
| 725 | - $disabled = "disabled='1'"; |
|
| 726 | - $value = FORCE_ARTICLE_PURGE; |
|
| 727 | - } else { |
|
| 728 | - $disabled = ""; |
|
| 729 | - } |
|
| 724 | + if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { |
|
| 725 | + $disabled = "disabled='1'"; |
|
| 726 | + $value = FORCE_ARTICLE_PURGE; |
|
| 727 | + } else { |
|
| 728 | + $disabled = ""; |
|
| 729 | + } |
|
| 730 | 730 | |
| 731 | - if ($type_name == 'integer') |
|
| 732 | - print "<input dojoType=\"dijit.form.NumberSpinner\" |
|
| 731 | + if ($type_name == 'integer') |
|
| 732 | + print "<input dojoType=\"dijit.form.NumberSpinner\" |
|
| 733 | 733 | required='1' $disabled |
| 734 | 734 | name=\"$pref_name\" value=\"$value\">"; |
| 735 | - else |
|
| 736 | - print "<input dojoType=\"dijit.form.TextBox\" |
|
| 735 | + else |
|
| 736 | + print "<input dojoType=\"dijit.form.TextBox\" |
|
| 737 | 737 | required='1' $regexp $disabled |
| 738 | 738 | name=\"$pref_name\" value=\"$value\">"; |
| 739 | 739 | |
| 740 | - } else if ($pref_name == "SSL_CERT_SERIAL") { |
|
| 740 | + } else if ($pref_name == "SSL_CERT_SERIAL") { |
|
| 741 | 741 | |
| 742 | - print "<input dojoType='dijit.form.ValidationTextBox' |
|
| 742 | + print "<input dojoType='dijit.form.ValidationTextBox' |
|
| 743 | 743 | id='SSL_CERT_SERIAL' readonly='1' |
| 744 | 744 | name=\"$pref_name\" value=\"$value\">"; |
| 745 | 745 | |
| 746 | - $cert_serial = htmlspecialchars(get_ssl_certificate_id()); |
|
| 747 | - $has_serial = ($cert_serial) ? "false" : "true"; |
|
| 746 | + $cert_serial = htmlspecialchars(get_ssl_certificate_id()); |
|
| 747 | + $has_serial = ($cert_serial) ? "false" : "true"; |
|
| 748 | 748 | |
| 749 | - print "<button dojoType='dijit.form.Button' disabled='$has_serial' |
|
| 749 | + print "<button dojoType='dijit.form.Button' disabled='$has_serial' |
|
| 750 | 750 | onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')\">" . |
| 751 | - __('Register') . "</button>"; |
|
| 751 | + __('Register') . "</button>"; |
|
| 752 | 752 | |
| 753 | - print "<button dojoType='dijit.form.Button' class='alt-danger' |
|
| 753 | + print "<button dojoType='dijit.form.Button' class='alt-danger' |
|
| 754 | 754 | onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '')\">" . |
| 755 | - __('Clear') . "</button>"; |
|
| 755 | + __('Clear') . "</button>"; |
|
| 756 | 756 | |
| 757 | - print "<button dojoType='dijit.form.Button' class='alt-info' |
|
| 757 | + print "<button dojoType='dijit.form.Button' class='alt-info' |
|
| 758 | 758 | onclick='window.open(\"https://tt-rss.org/wiki/SSL%20Certificate%20Authentication\")'> |
| 759 | 759 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
| 760 | 760 | |
| 761 | - } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
|
| 762 | - print "<input dojoType=\"dijit.form.ValidationTextBox\" |
|
| 761 | + } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
|
| 762 | + print "<input dojoType=\"dijit.form.ValidationTextBox\" |
|
| 763 | 763 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
| 764 | 764 | name=\"$pref_name\" value=\"$value\">"; |
| 765 | 765 | |
| 766 | - $item['help_text'] .= ". " . T_sprintf("Current server time: %s", date("H:i")); |
|
| 767 | - } else { |
|
| 768 | - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
| 766 | + $item['help_text'] .= ". " . T_sprintf("Current server time: %s", date("H:i")); |
|
| 767 | + } else { |
|
| 768 | + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
| 769 | 769 | |
| 770 | - print "<input dojoType=\"dijit.form.ValidationTextBox\" $regexp name=\"$pref_name\" value=\"$value\">"; |
|
| 771 | - } |
|
| 770 | + print "<input dojoType=\"dijit.form.ValidationTextBox\" $regexp name=\"$pref_name\" value=\"$value\">"; |
|
| 771 | + } |
|
| 772 | 772 | |
| 773 | - if ($item['help_text']) |
|
| 774 | - print "<div class='help-text text-muted'><label for='CB_$pref_name'>".$item['help_text']."</label></div>"; |
|
| 773 | + if ($item['help_text']) |
|
| 774 | + print "<div class='help-text text-muted'><label for='CB_$pref_name'>".$item['help_text']."</label></div>"; |
|
| 775 | 775 | |
| 776 | - print "</fieldset>"; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 776 | + print "</fieldset>"; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
|
| 781 | + $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
|
| 782 | 782 | |
| 783 | - print_hidden("boolean_prefs", "$listed_boolean_prefs"); |
|
| 783 | + print_hidden("boolean_prefs", "$listed_boolean_prefs"); |
|
| 784 | 784 | |
| 785 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 786 | - "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
|
| 785 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 786 | + "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
|
| 787 | 787 | |
| 788 | - print '</div>'; # inside pane |
|
| 789 | - print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
| 788 | + print '</div>'; # inside pane |
|
| 789 | + print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
| 790 | 790 | |
| 791 | - print_hidden("op", "pref-prefs"); |
|
| 792 | - print_hidden("method", "saveconfig"); |
|
| 791 | + print_hidden("op", "pref-prefs"); |
|
| 792 | + print_hidden("method", "saveconfig"); |
|
| 793 | 793 | |
| 794 | - print "<div dojoType=\"fox.form.ComboButton\" type=\"submit\" class=\"alt-primary\"> |
|
| 794 | + print "<div dojoType=\"fox.form.ComboButton\" type=\"submit\" class=\"alt-primary\"> |
|
| 795 | 795 | <span>".__('Save configuration')."</span> |
| 796 | 796 | <div dojoType=\"dijit.DropDownMenu\"> |
| 797 | 797 | <div dojoType=\"dijit.MenuItem\" |
| 798 | 798 | onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">". |
| 799 | - __("Save and exit preferences")."</div> |
|
| 799 | + __("Save and exit preferences")."</div> |
|
| 800 | 800 | </div> |
| 801 | 801 | </div>"; |
| 802 | 802 | |
| 803 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return Helpers.editProfiles()\">". |
|
| 804 | - __('Manage profiles')."</button> "; |
|
| 803 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return Helpers.editProfiles()\">". |
|
| 804 | + __('Manage profiles')."</button> "; |
|
| 805 | 805 | |
| 806 | - print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return Helpers.confirmReset()\">". |
|
| 807 | - __('Reset to defaults')."</button>"; |
|
| 806 | + print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return Helpers.confirmReset()\">". |
|
| 807 | + __('Reset to defaults')."</button>"; |
|
| 808 | 808 | |
| 809 | - print " "; |
|
| 809 | + print " "; |
|
| 810 | 810 | |
| 811 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 812 | - "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
|
| 811 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 812 | + "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
|
| 813 | 813 | |
| 814 | - print "</form>"; |
|
| 815 | - print '</div>'; # inner pane |
|
| 816 | - print '</div>'; # border container |
|
| 814 | + print "</form>"; |
|
| 815 | + print '</div>'; # inner pane |
|
| 816 | + print '</div>'; # border container |
|
| 817 | 817 | |
| 818 | - print "</div>"; #pane |
|
| 818 | + print "</div>"; #pane |
|
| 819 | 819 | |
| 820 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
| 820 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
| 821 | 821 | title=\"<i class='material-icons'>extension</i> ".__('Plugins')."\">"; |
| 822 | 822 | |
| 823 | - print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; |
|
| 823 | + print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; |
|
| 824 | 824 | |
| 825 | - print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
|
| 825 | + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
|
| 826 | 826 | evt.preventDefault(); |
| 827 | 827 | if (this.validate()) { |
| 828 | 828 | Notify.progress('Saving data...', true); |
@@ -839,383 +839,383 @@ discard block |
||
| 839 | 839 | } |
| 840 | 840 | </script>"; |
| 841 | 841 | |
| 842 | - print_hidden("op", "pref-prefs"); |
|
| 843 | - print_hidden("method", "setplugins"); |
|
| 842 | + print_hidden("op", "pref-prefs"); |
|
| 843 | + print_hidden("method", "setplugins"); |
|
| 844 | 844 | |
| 845 | - print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
| 846 | - print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
| 845 | + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
| 846 | + print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
| 847 | 847 | |
| 848 | - if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { |
|
| 849 | - print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); |
|
| 850 | - } |
|
| 848 | + if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { |
|
| 849 | + print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - $feed_handler_whitelist = [ "Af_Comics" ]; |
|
| 852 | + $feed_handler_whitelist = [ "Af_Comics" ]; |
|
| 853 | 853 | |
| 854 | - $feed_handlers = array_merge( |
|
| 855 | - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), |
|
| 856 | - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), |
|
| 857 | - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); |
|
| 854 | + $feed_handlers = array_merge( |
|
| 855 | + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), |
|
| 856 | + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), |
|
| 857 | + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); |
|
| 858 | 858 | |
| 859 | - $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { |
|
| 860 | - return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); |
|
| 859 | + $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { |
|
| 860 | + return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); |
|
| 861 | 861 | |
| 862 | - if (count($feed_handlers) > 0) { |
|
| 863 | - print_error( |
|
| 864 | - T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" , |
|
| 865 | - implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) |
|
| 866 | - ) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" |
|
| 867 | - ); |
|
| 868 | - } |
|
| 862 | + if (count($feed_handlers) > 0) { |
|
| 863 | + print_error( |
|
| 864 | + T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" , |
|
| 865 | + implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) |
|
| 866 | + ) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" |
|
| 867 | + ); |
|
| 868 | + } |
|
| 869 | 869 | |
| 870 | - print "<h2>".__("System plugins")."</h2>"; |
|
| 871 | - print_notice("System plugins are enabled in <strong>config.php</strong> for all users."); |
|
| 870 | + print "<h2>".__("System plugins")."</h2>"; |
|
| 871 | + print_notice("System plugins are enabled in <strong>config.php</strong> for all users."); |
|
| 872 | 872 | |
| 873 | - $system_enabled = array_map("trim", explode(",", PLUGINS)); |
|
| 874 | - $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); |
|
| 873 | + $system_enabled = array_map("trim", explode(",", PLUGINS)); |
|
| 874 | + $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); |
|
| 875 | 875 | |
| 876 | - $tmppluginhost = new PluginHost(); |
|
| 877 | - $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); |
|
| 878 | - $tmppluginhost->load_data(); |
|
| 876 | + $tmppluginhost = new PluginHost(); |
|
| 877 | + $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); |
|
| 878 | + $tmppluginhost->load_data(); |
|
| 879 | 879 | |
| 880 | - foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
| 881 | - $about = $plugin->about(); |
|
| 880 | + foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
| 881 | + $about = $plugin->about(); |
|
| 882 | 882 | |
| 883 | - if ($about[3]) { |
|
| 884 | - if (in_array($name, $system_enabled)) { |
|
| 885 | - $checked = "checked='1'"; |
|
| 886 | - } else { |
|
| 887 | - $checked = ""; |
|
| 888 | - } |
|
| 883 | + if ($about[3]) { |
|
| 884 | + if (in_array($name, $system_enabled)) { |
|
| 885 | + $checked = "checked='1'"; |
|
| 886 | + } else { |
|
| 887 | + $checked = ""; |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - print "<fieldset class='prefs plugin'> |
|
| 890 | + print "<fieldset class='prefs plugin'> |
|
| 891 | 891 | <label>$name:</label> |
| 892 | 892 | <label class='checkbox description text-muted' id='PLABEL-$name'> |
| 893 | 893 | <input disabled='1' |
| 894 | 894 | dojoType='dijit.form.CheckBox' $checked type='checkbox'> |
| 895 | 895 | ".htmlspecialchars($about[1]). "</label>"; |
| 896 | 896 | |
| 897 | - if (@$about[4]) { |
|
| 898 | - print "<button dojoType='dijit.form.Button' class='alt-info' |
|
| 897 | + if (@$about[4]) { |
|
| 898 | + print "<button dojoType='dijit.form.Button' class='alt-info' |
|
| 899 | 899 | onclick='window.open(\"".htmlspecialchars($about[4])."\")'> |
| 900 | 900 | <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>"; |
| 901 | - } |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | - print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
| 904 | - htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
| 905 | - "</div>"; |
|
| 903 | + print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
| 904 | + htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
| 905 | + "</div>"; |
|
| 906 | 906 | |
| 907 | - print "</fieldset>"; |
|
| 907 | + print "</fieldset>"; |
|
| 908 | 908 | |
| 909 | - } |
|
| 910 | - } |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - print "<h2>".__("User plugins")."</h2>"; |
|
| 912 | + print "<h2>".__("User plugins")."</h2>"; |
|
| 913 | 913 | |
| 914 | - foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
| 915 | - $about = $plugin->about(); |
|
| 914 | + foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
| 915 | + $about = $plugin->about(); |
|
| 916 | 916 | |
| 917 | - if (!$about[3]) { |
|
| 917 | + if (!$about[3]) { |
|
| 918 | 918 | |
| 919 | - $checked = ""; |
|
| 920 | - $disabled = ""; |
|
| 919 | + $checked = ""; |
|
| 920 | + $disabled = ""; |
|
| 921 | 921 | |
| 922 | - if (in_array($name, $system_enabled)) { |
|
| 923 | - $checked = "checked='1'"; |
|
| 924 | - $disabled = "disabled='1'"; |
|
| 925 | - } else if (in_array($name, $user_enabled)) { |
|
| 926 | - $checked = "checked='1'"; |
|
| 927 | - } |
|
| 922 | + if (in_array($name, $system_enabled)) { |
|
| 923 | + $checked = "checked='1'"; |
|
| 924 | + $disabled = "disabled='1'"; |
|
| 925 | + } else if (in_array($name, $user_enabled)) { |
|
| 926 | + $checked = "checked='1'"; |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | - print "<fieldset class='prefs plugin'> |
|
| 929 | + print "<fieldset class='prefs plugin'> |
|
| 930 | 930 | <label>$name:</label> |
| 931 | 931 | <label class='checkbox description text-muted' id='PLABEL-$name'> |
| 932 | 932 | <input name='plugins[]' value='$name' dojoType='dijit.form.CheckBox' $checked $disabled type='checkbox'> |
| 933 | 933 | ".htmlspecialchars($about[1])."</label>"; |
| 934 | 934 | |
| 935 | - if (count($tmppluginhost->get_all($plugin)) > 0) { |
|
| 936 | - if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
|
| 937 | - print " <button dojoType='dijit.form.Button' |
|
| 935 | + if (count($tmppluginhost->get_all($plugin)) > 0) { |
|
| 936 | + if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
|
| 937 | + print " <button dojoType='dijit.form.Button' |
|
| 938 | 938 | onclick=\"Helpers.clearPluginData('$name')\"> |
| 939 | 939 | <i class='material-icons'>clear</i> ".__("Clear data")."</button>"; |
| 940 | - } |
|
| 941 | - } |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | - if (@$about[4]) { |
|
| 944 | - print " <button dojoType='dijit.form.Button' class='alt-info' |
|
| 943 | + if (@$about[4]) { |
|
| 944 | + print " <button dojoType='dijit.form.Button' class='alt-info' |
|
| 945 | 945 | onclick='window.open(\"".htmlspecialchars($about[4])."\")'> |
| 946 | 946 | <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>"; |
| 947 | - } |
|
| 947 | + } |
|
| 948 | 948 | |
| 949 | - print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
| 950 | - htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
| 951 | - "</div>"; |
|
| 949 | + print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
| 950 | + htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
| 951 | + "</div>"; |
|
| 952 | 952 | |
| 953 | - print "</fieldset>"; |
|
| 954 | - } |
|
| 955 | - } |
|
| 953 | + print "</fieldset>"; |
|
| 954 | + } |
|
| 955 | + } |
|
| 956 | 956 | |
| 957 | - print "</div>"; #content-pane |
|
| 958 | - print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
| 957 | + print "</div>"; #content-pane |
|
| 958 | + print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
| 959 | 959 | |
| 960 | - print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/Plugins\")'> |
|
| 960 | + print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/Plugins\")'> |
|
| 961 | 961 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
| 962 | 962 | |
| 963 | - print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>". |
|
| 964 | - __("Enable selected plugins")."</button>"; |
|
| 965 | - print "</div>"; #pane |
|
| 963 | + print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>". |
|
| 964 | + __("Enable selected plugins")."</button>"; |
|
| 965 | + print "</div>"; #pane |
|
| 966 | 966 | |
| 967 | - print "</div>"; #pane |
|
| 968 | - print "</div>"; #border-container |
|
| 967 | + print "</div>"; #pane |
|
| 968 | + print "</div>"; #border-container |
|
| 969 | 969 | |
| 970 | - print "</form>"; |
|
| 970 | + print "</form>"; |
|
| 971 | 971 | |
| 972 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
| 973 | - "hook_prefs_tab", "prefPrefs"); |
|
| 972 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
| 973 | + "hook_prefs_tab", "prefPrefs"); |
|
| 974 | 974 | |
| 975 | - print "</div>"; #container |
|
| 975 | + print "</div>"; #container |
|
| 976 | 976 | |
| 977 | - } |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - public function toggleAdvanced() { |
|
| 980 | - $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; |
|
| 981 | - } |
|
| 979 | + public function toggleAdvanced() { |
|
| 980 | + $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; |
|
| 981 | + } |
|
| 982 | 982 | |
| 983 | - public function otpsecret() { |
|
| 984 | - $sth = $this->pdo->prepare("SELECT salt, otp_enabled |
|
| 983 | + public function otpsecret() { |
|
| 984 | + $sth = $this->pdo->prepare("SELECT salt, otp_enabled |
|
| 985 | 985 | FROM ttrss_users |
| 986 | 986 | WHERE id = ?"); |
| 987 | - $sth->execute([$_SESSION['uid']]); |
|
| 987 | + $sth->execute([$_SESSION['uid']]); |
|
| 988 | 988 | |
| 989 | - if ($row = $sth->fetch()) { |
|
| 990 | - $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
| 989 | + if ($row = $sth->fetch()) { |
|
| 990 | + $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
| 991 | 991 | |
| 992 | - if (!$otp_enabled) { |
|
| 993 | - $base32 = new \OTPHP\Base32(); |
|
| 994 | - $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
| 992 | + if (!$otp_enabled) { |
|
| 993 | + $base32 = new \OTPHP\Base32(); |
|
| 994 | + $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
| 995 | 995 | |
| 996 | - return $secret; |
|
| 997 | - } |
|
| 998 | - } |
|
| 996 | + return $secret; |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | 999 | |
| 1000 | - return false; |
|
| 1001 | - } |
|
| 1000 | + return false; |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | - public function otpqrcode() { |
|
| 1004 | - require_once "lib/phpqrcode/phpqrcode.php"; |
|
| 1003 | + public function otpqrcode() { |
|
| 1004 | + require_once "lib/phpqrcode/phpqrcode.php"; |
|
| 1005 | 1005 | |
| 1006 | - $sth = $this->pdo->prepare("SELECT login |
|
| 1006 | + $sth = $this->pdo->prepare("SELECT login |
|
| 1007 | 1007 | FROM ttrss_users |
| 1008 | 1008 | WHERE id = ?"); |
| 1009 | - $sth->execute([$_SESSION['uid']]); |
|
| 1009 | + $sth->execute([$_SESSION['uid']]); |
|
| 1010 | 1010 | |
| 1011 | - if ($row = $sth->fetch()) { |
|
| 1012 | - $secret = $this->otpsecret(); |
|
| 1013 | - $login = $row['login']; |
|
| 1011 | + if ($row = $sth->fetch()) { |
|
| 1012 | + $secret = $this->otpsecret(); |
|
| 1013 | + $login = $row['login']; |
|
| 1014 | 1014 | |
| 1015 | - if ($secret) { |
|
| 1016 | - QRcode::png("otpauth://totp/".urlencode($login). |
|
| 1017 | - "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS")); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1015 | + if ($secret) { |
|
| 1016 | + QRcode::png("otpauth://totp/".urlencode($login). |
|
| 1017 | + "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS")); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | 1021 | |
| 1022 | - public function otpenable() { |
|
| 1022 | + public function otpenable() { |
|
| 1023 | 1023 | |
| 1024 | - $password = clean($_REQUEST["password"]); |
|
| 1025 | - $otp = clean($_REQUEST["otp"]); |
|
| 1024 | + $password = clean($_REQUEST["password"]); |
|
| 1025 | + $otp = clean($_REQUEST["otp"]); |
|
| 1026 | 1026 | |
| 1027 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 1027 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 1028 | 1028 | |
| 1029 | - if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
| 1029 | + if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
| 1030 | 1030 | |
| 1031 | - $secret = $this->otpsecret(); |
|
| 1031 | + $secret = $this->otpsecret(); |
|
| 1032 | 1032 | |
| 1033 | - if ($secret) { |
|
| 1034 | - $topt = new \OTPHP\TOTP($secret); |
|
| 1035 | - $otp_check = $topt->now(); |
|
| 1033 | + if ($secret) { |
|
| 1034 | + $topt = new \OTPHP\TOTP($secret); |
|
| 1035 | + $otp_check = $topt->now(); |
|
| 1036 | 1036 | |
| 1037 | - if ($otp == $otp_check) { |
|
| 1038 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = true WHERE id = ?"); |
|
| 1037 | + if ($otp == $otp_check) { |
|
| 1038 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = true WHERE id = ?"); |
|
| 1039 | 1039 | |
| 1040 | - $sth->execute([$_SESSION['uid']]); |
|
| 1040 | + $sth->execute([$_SESSION['uid']]); |
|
| 1041 | 1041 | |
| 1042 | - print "OK"; |
|
| 1043 | - } else { |
|
| 1044 | - print "ERROR:".__("Incorrect one time password"); |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1042 | + print "OK"; |
|
| 1043 | + } else { |
|
| 1044 | + print "ERROR:".__("Incorrect one time password"); |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | - } else { |
|
| 1049 | - print "ERROR:".__("Incorrect password"); |
|
| 1050 | - } |
|
| 1048 | + } else { |
|
| 1049 | + print "ERROR:".__("Incorrect password"); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - } |
|
| 1052 | + } |
|
| 1053 | 1053 | |
| 1054 | - public static function isdefaultpassword() { |
|
| 1055 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 1054 | + public static function isdefaultpassword() { |
|
| 1055 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 1056 | 1056 | |
| 1057 | - if ($authenticator && |
|
| 1057 | + if ($authenticator && |
|
| 1058 | 1058 | method_exists($authenticator, "check_password") && |
| 1059 | 1059 | $authenticator->check_password($_SESSION["uid"], "password")) { |
| 1060 | 1060 | |
| 1061 | - return true; |
|
| 1062 | - } |
|
| 1061 | + return true; |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - return false; |
|
| 1065 | - } |
|
| 1064 | + return false; |
|
| 1065 | + } |
|
| 1066 | 1066 | |
| 1067 | - public function otpdisable() { |
|
| 1068 | - $password = clean($_REQUEST["password"]); |
|
| 1067 | + public function otpdisable() { |
|
| 1068 | + $password = clean($_REQUEST["password"]); |
|
| 1069 | 1069 | |
| 1070 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 1070 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
| 1071 | 1071 | |
| 1072 | - if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
| 1072 | + if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
| 1073 | 1073 | |
| 1074 | - $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
| 1075 | - $sth->execute([$_SESSION['uid']]); |
|
| 1074 | + $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
| 1075 | + $sth->execute([$_SESSION['uid']]); |
|
| 1076 | 1076 | |
| 1077 | - if ($row = $sth->fetch()) { |
|
| 1078 | - $mailer = new Mailer(); |
|
| 1077 | + if ($row = $sth->fetch()) { |
|
| 1078 | + $mailer = new Mailer(); |
|
| 1079 | 1079 | |
| 1080 | - require_once "lib/MiniTemplator.class.php"; |
|
| 1080 | + require_once "lib/MiniTemplator.class.php"; |
|
| 1081 | 1081 | |
| 1082 | - $tpl = new MiniTemplator; |
|
| 1082 | + $tpl = new MiniTemplator; |
|
| 1083 | 1083 | |
| 1084 | - $tpl->readTemplateFromFile("templates/otp_disabled_template.txt"); |
|
| 1084 | + $tpl->readTemplateFromFile("templates/otp_disabled_template.txt"); |
|
| 1085 | 1085 | |
| 1086 | - $tpl->setVariable('LOGIN', $row["login"]); |
|
| 1087 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
| 1086 | + $tpl->setVariable('LOGIN', $row["login"]); |
|
| 1087 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
| 1088 | 1088 | |
| 1089 | - $tpl->addBlock('message'); |
|
| 1089 | + $tpl->addBlock('message'); |
|
| 1090 | 1090 | |
| 1091 | - $tpl->generateOutputToString($message); |
|
| 1091 | + $tpl->generateOutputToString($message); |
|
| 1092 | 1092 | |
| 1093 | - $mailer->mail(["to_name" => $row["login"], |
|
| 1094 | - "to_address" => $row["email"], |
|
| 1095 | - "subject" => "[tt-rss] OTP change notification", |
|
| 1096 | - "message" => $message]); |
|
| 1097 | - } |
|
| 1093 | + $mailer->mail(["to_name" => $row["login"], |
|
| 1094 | + "to_address" => $row["email"], |
|
| 1095 | + "subject" => "[tt-rss] OTP change notification", |
|
| 1096 | + "message" => $message]); |
|
| 1097 | + } |
|
| 1098 | 1098 | |
| 1099 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE |
|
| 1099 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE |
|
| 1100 | 1100 | id = ?"); |
| 1101 | - $sth->execute([$_SESSION['uid']]); |
|
| 1101 | + $sth->execute([$_SESSION['uid']]); |
|
| 1102 | 1102 | |
| 1103 | - print "OK"; |
|
| 1104 | - } else { |
|
| 1105 | - print "ERROR: ".__("Incorrect password"); |
|
| 1106 | - } |
|
| 1103 | + print "OK"; |
|
| 1104 | + } else { |
|
| 1105 | + print "ERROR: ".__("Incorrect password"); |
|
| 1106 | + } |
|
| 1107 | 1107 | |
| 1108 | - } |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - public function setplugins() { |
|
| 1111 | - if (is_array(clean($_REQUEST["plugins"]))) |
|
| 1112 | - $plugins = join(",", clean($_REQUEST["plugins"])); |
|
| 1113 | - else |
|
| 1114 | - $plugins = ""; |
|
| 1110 | + public function setplugins() { |
|
| 1111 | + if (is_array(clean($_REQUEST["plugins"]))) |
|
| 1112 | + $plugins = join(",", clean($_REQUEST["plugins"])); |
|
| 1113 | + else |
|
| 1114 | + $plugins = ""; |
|
| 1115 | 1115 | |
| 1116 | - set_pref("_ENABLED_PLUGINS", $plugins); |
|
| 1117 | - } |
|
| 1116 | + set_pref("_ENABLED_PLUGINS", $plugins); |
|
| 1117 | + } |
|
| 1118 | 1118 | |
| 1119 | - public function clearplugindata() { |
|
| 1120 | - $name = clean($_REQUEST["name"]); |
|
| 1119 | + public function clearplugindata() { |
|
| 1120 | + $name = clean($_REQUEST["name"]); |
|
| 1121 | 1121 | |
| 1122 | - PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name)); |
|
| 1123 | - } |
|
| 1122 | + PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name)); |
|
| 1123 | + } |
|
| 1124 | 1124 | |
| 1125 | - public function customizeCSS() { |
|
| 1126 | - $value = get_pref("USER_STYLESHEET"); |
|
| 1127 | - $value = str_replace("<br/>", "\n", $value); |
|
| 1125 | + public function customizeCSS() { |
|
| 1126 | + $value = get_pref("USER_STYLESHEET"); |
|
| 1127 | + $value = str_replace("<br/>", "\n", $value); |
|
| 1128 | 1128 | |
| 1129 | - print_notice(__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")); |
|
| 1129 | + print_notice(__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")); |
|
| 1130 | 1130 | |
| 1131 | - print_hidden("op", "rpc"); |
|
| 1132 | - print_hidden("method", "setpref"); |
|
| 1133 | - print_hidden("key", "USER_STYLESHEET"); |
|
| 1131 | + print_hidden("op", "rpc"); |
|
| 1132 | + print_hidden("method", "setpref"); |
|
| 1133 | + print_hidden("key", "USER_STYLESHEET"); |
|
| 1134 | 1134 | |
| 1135 | - print "<div id='css_edit_apply_msg' style='display : none'>"; |
|
| 1136 | - print_warning(__("User CSS has been applied, you might need to reload the page to see all changes.")); |
|
| 1137 | - print "</div>"; |
|
| 1135 | + print "<div id='css_edit_apply_msg' style='display : none'>"; |
|
| 1136 | + print_warning(__("User CSS has been applied, you might need to reload the page to see all changes.")); |
|
| 1137 | + print "</div>"; |
|
| 1138 | 1138 | |
| 1139 | - print "<textarea class='panel user-css-editor' dojoType='dijit.form.SimpleTextarea' |
|
| 1139 | + print "<textarea class='panel user-css-editor' dojoType='dijit.form.SimpleTextarea' |
|
| 1140 | 1140 | style='font-size : 12px;' name='value'>$value</textarea>"; |
| 1141 | 1141 | |
| 1142 | - print "<footer>"; |
|
| 1143 | - print "<button dojoType='dijit.form.Button' class='alt-success' |
|
| 1142 | + print "<footer>"; |
|
| 1143 | + print "<button dojoType='dijit.form.Button' class='alt-success' |
|
| 1144 | 1144 | onclick=\"dijit.byId('cssEditDlg').apply()\">".__('Apply')."</button> "; |
| 1145 | - print "<button dojoType='dijit.form.Button' class='alt-primary' |
|
| 1145 | + print "<button dojoType='dijit.form.Button' class='alt-primary' |
|
| 1146 | 1146 | onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save and reload')."</button> "; |
| 1147 | - print "<button dojoType='dijit.form.Button' |
|
| 1147 | + print "<button dojoType='dijit.form.Button' |
|
| 1148 | 1148 | onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>"; |
| 1149 | - print "</footer>"; |
|
| 1149 | + print "</footer>"; |
|
| 1150 | 1150 | |
| 1151 | - } |
|
| 1151 | + } |
|
| 1152 | 1152 | |
| 1153 | - public function editPrefProfiles() { |
|
| 1154 | - print "<div dojoType='fox.Toolbar'>"; |
|
| 1153 | + public function editPrefProfiles() { |
|
| 1154 | + print "<div dojoType='fox.Toolbar'>"; |
|
| 1155 | 1155 | |
| 1156 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
| 1157 | - "<span>" . __('Select')."</span>"; |
|
| 1158 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
| 1159 | - print "<div onclick=\"Tables.select('pref-profiles-list', true)\" |
|
| 1156 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
| 1157 | + "<span>" . __('Select')."</span>"; |
|
| 1158 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
| 1159 | + print "<div onclick=\"Tables.select('pref-profiles-list', true)\" |
|
| 1160 | 1160 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
| 1161 | - print "<div onclick=\"Tables.select('pref-profiles-list', false)\" |
|
| 1161 | + print "<div onclick=\"Tables.select('pref-profiles-list', false)\" |
|
| 1162 | 1162 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
| 1163 | - print "</div></div>"; |
|
| 1163 | + print "</div></div>"; |
|
| 1164 | 1164 | |
| 1165 | - print "<div style='float : right'>"; |
|
| 1165 | + print "<div style='float : right'>"; |
|
| 1166 | 1166 | |
| 1167 | - print "<input name='newprofile' dojoType='dijit.form.ValidationTextBox' |
|
| 1167 | + print "<input name='newprofile' dojoType='dijit.form.ValidationTextBox' |
|
| 1168 | 1168 | required='1'> |
| 1169 | 1169 | <button dojoType='dijit.form.Button' |
| 1170 | 1170 | onclick=\"dijit.byId('profileEditDlg').addProfile()\">". |
| 1171 | - __('Create profile')."</button></div>"; |
|
| 1171 | + __('Create profile')."</button></div>"; |
|
| 1172 | 1172 | |
| 1173 | - print "</div>"; |
|
| 1173 | + print "</div>"; |
|
| 1174 | 1174 | |
| 1175 | - $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles |
|
| 1175 | + $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles |
|
| 1176 | 1176 | WHERE owner_uid = ? ORDER BY title"); |
| 1177 | - $sth->execute([$_SESSION['uid']]); |
|
| 1177 | + $sth->execute([$_SESSION['uid']]); |
|
| 1178 | 1178 | |
| 1179 | - print "<div class='panel panel-scrollable'>"; |
|
| 1179 | + print "<div class='panel panel-scrollable'>"; |
|
| 1180 | 1180 | |
| 1181 | - print "<form id='profile_edit_form' onsubmit='return false'>"; |
|
| 1181 | + print "<form id='profile_edit_form' onsubmit='return false'>"; |
|
| 1182 | 1182 | |
| 1183 | - print "<table width='100%' id='pref-profiles-list'>"; |
|
| 1183 | + print "<table width='100%' id='pref-profiles-list'>"; |
|
| 1184 | 1184 | |
| 1185 | - print "<tr>"; # data-row-id='0' <-- no point, shouldn't be removed |
|
| 1185 | + print "<tr>"; # data-row-id='0' <-- no point, shouldn't be removed |
|
| 1186 | 1186 | |
| 1187 | - print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
| 1187 | + print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
| 1188 | 1188 | |
| 1189 | - if (!$_SESSION["profile"]) { |
|
| 1190 | - $is_active = __("(active)"); |
|
| 1191 | - } else { |
|
| 1192 | - $is_active = ""; |
|
| 1193 | - } |
|
| 1189 | + if (!$_SESSION["profile"]) { |
|
| 1190 | + $is_active = __("(active)"); |
|
| 1191 | + } else { |
|
| 1192 | + $is_active = ""; |
|
| 1193 | + } |
|
| 1194 | 1194 | |
| 1195 | - print "<td width='100%'><span>" . __("Default profile") . " $is_active</span></td>"; |
|
| 1195 | + print "<td width='100%'><span>" . __("Default profile") . " $is_active</span></td>"; |
|
| 1196 | 1196 | |
| 1197 | - print "</tr>"; |
|
| 1197 | + print "</tr>"; |
|
| 1198 | 1198 | |
| 1199 | - while ($line = $sth->fetch()) { |
|
| 1199 | + while ($line = $sth->fetch()) { |
|
| 1200 | 1200 | |
| 1201 | - $profile_id = $line["id"]; |
|
| 1201 | + $profile_id = $line["id"]; |
|
| 1202 | 1202 | |
| 1203 | - print "<tr data-row-id='$profile_id'>"; |
|
| 1203 | + print "<tr data-row-id='$profile_id'>"; |
|
| 1204 | 1204 | |
| 1205 | - $edit_title = htmlspecialchars($line["title"]); |
|
| 1205 | + $edit_title = htmlspecialchars($line["title"]); |
|
| 1206 | 1206 | |
| 1207 | - print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
| 1207 | + print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
| 1208 | 1208 | |
| 1209 | - if ($_SESSION["profile"] == $line["id"]) { |
|
| 1210 | - $is_active = __("(active)"); |
|
| 1211 | - } else { |
|
| 1212 | - $is_active = ""; |
|
| 1213 | - } |
|
| 1209 | + if ($_SESSION["profile"] == $line["id"]) { |
|
| 1210 | + $is_active = __("(active)"); |
|
| 1211 | + } else { |
|
| 1212 | + $is_active = ""; |
|
| 1213 | + } |
|
| 1214 | 1214 | |
| 1215 | - print "<td><span dojoType='dijit.InlineEditBox' |
|
| 1215 | + print "<td><span dojoType='dijit.InlineEditBox' |
|
| 1216 | 1216 | width='300px' autoSave='false' |
| 1217 | 1217 | profile-id='$profile_id'>" . $edit_title . |
| 1218 | - "<script type='dojo/method' event='onChange' args='item'> |
|
| 1218 | + "<script type='dojo/method' event='onChange' args='item'> |
|
| 1219 | 1219 | var elem = this; |
| 1220 | 1220 | dojo.xhrPost({ |
| 1221 | 1221 | url: 'backend.php', |
@@ -1229,118 +1229,118 @@ discard block |
||
| 1229 | 1229 | </script> |
| 1230 | 1230 | </span> $is_active</td>"; |
| 1231 | 1231 | |
| 1232 | - print "</tr>"; |
|
| 1233 | - } |
|
| 1232 | + print "</tr>"; |
|
| 1233 | + } |
|
| 1234 | 1234 | |
| 1235 | - print "</table>"; |
|
| 1236 | - print "</form>"; |
|
| 1237 | - print "</div>"; |
|
| 1235 | + print "</table>"; |
|
| 1236 | + print "</form>"; |
|
| 1237 | + print "</div>"; |
|
| 1238 | 1238 | |
| 1239 | - print "<footer> |
|
| 1239 | + print "<footer> |
|
| 1240 | 1240 | <button style='float : left' class='alt-danger' dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">". |
| 1241 | - __('Remove selected profiles')."</button> |
|
| 1241 | + __('Remove selected profiles')."</button> |
|
| 1242 | 1242 | <button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"dijit.byId('profileEditDlg').activateProfile()\">". |
| 1243 | - __('Activate profile')."</button> |
|
| 1243 | + __('Activate profile')."</button> |
|
| 1244 | 1244 | <button dojoType='dijit.form.Button' onclick=\"dijit.byId('profileEditDlg').hide()\">". |
| 1245 | - __('Cancel')."</button>"; |
|
| 1246 | - print "</footer>"; |
|
| 1247 | - |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - private function getShortDesc($pref_name) { |
|
| 1251 | - if (isset($this->pref_help[$pref_name])) { |
|
| 1252 | - return $this->pref_help[$pref_name][0]; |
|
| 1253 | - } |
|
| 1254 | - return ""; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - private function getHelpText($pref_name) { |
|
| 1258 | - if (isset($this->pref_help[$pref_name])) { |
|
| 1259 | - return $this->pref_help[$pref_name][1]; |
|
| 1260 | - } |
|
| 1261 | - return ""; |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - private function appPasswordList() { |
|
| 1265 | - print "<div dojoType='fox.Toolbar'>"; |
|
| 1266 | - print "<div dojoType='fox.form.DropDownButton'>" . |
|
| 1267 | - "<span>" . __('Select') . "</span>"; |
|
| 1268 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
| 1269 | - print "<div onclick=\"Tables.select('app-password-list', true)\" |
|
| 1245 | + __('Cancel')."</button>"; |
|
| 1246 | + print "</footer>"; |
|
| 1247 | + |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + private function getShortDesc($pref_name) { |
|
| 1251 | + if (isset($this->pref_help[$pref_name])) { |
|
| 1252 | + return $this->pref_help[$pref_name][0]; |
|
| 1253 | + } |
|
| 1254 | + return ""; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + private function getHelpText($pref_name) { |
|
| 1258 | + if (isset($this->pref_help[$pref_name])) { |
|
| 1259 | + return $this->pref_help[$pref_name][1]; |
|
| 1260 | + } |
|
| 1261 | + return ""; |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + private function appPasswordList() { |
|
| 1265 | + print "<div dojoType='fox.Toolbar'>"; |
|
| 1266 | + print "<div dojoType='fox.form.DropDownButton'>" . |
|
| 1267 | + "<span>" . __('Select') . "</span>"; |
|
| 1268 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
| 1269 | + print "<div onclick=\"Tables.select('app-password-list', true)\" |
|
| 1270 | 1270 | dojoType=\"dijit.MenuItem\">" . __('All') . "</div>"; |
| 1271 | - print "<div onclick=\"Tables.select('app-password-list', false)\" |
|
| 1271 | + print "<div onclick=\"Tables.select('app-password-list', false)\" |
|
| 1272 | 1272 | dojoType=\"dijit.MenuItem\">" . __('None') . "</div>"; |
| 1273 | - print "</div></div>"; |
|
| 1274 | - print "</div>"; #toolbar |
|
| 1275 | - |
|
| 1276 | - print "<div class='panel panel-scrollable'>"; |
|
| 1277 | - print "<table width='100%' id='app-password-list'>"; |
|
| 1278 | - print "<tr>"; |
|
| 1279 | - print "<th width='2%'></th>"; |
|
| 1280 | - print "<th align='left'>".__("Description")."</th>"; |
|
| 1281 | - print "<th align='right'>".__("Created")."</th>"; |
|
| 1282 | - print "<th align='right'>".__("Last used")."</th>"; |
|
| 1283 | - print "</tr>"; |
|
| 1284 | - |
|
| 1285 | - $sth = $this->pdo->prepare("SELECT id, title, created, last_used |
|
| 1273 | + print "</div></div>"; |
|
| 1274 | + print "</div>"; #toolbar |
|
| 1275 | + |
|
| 1276 | + print "<div class='panel panel-scrollable'>"; |
|
| 1277 | + print "<table width='100%' id='app-password-list'>"; |
|
| 1278 | + print "<tr>"; |
|
| 1279 | + print "<th width='2%'></th>"; |
|
| 1280 | + print "<th align='left'>".__("Description")."</th>"; |
|
| 1281 | + print "<th align='right'>".__("Created")."</th>"; |
|
| 1282 | + print "<th align='right'>".__("Last used")."</th>"; |
|
| 1283 | + print "</tr>"; |
|
| 1284 | + |
|
| 1285 | + $sth = $this->pdo->prepare("SELECT id, title, created, last_used |
|
| 1286 | 1286 | FROM ttrss_app_passwords WHERE owner_uid = ?"); |
| 1287 | - $sth->execute([$_SESSION['uid']]); |
|
| 1287 | + $sth->execute([$_SESSION['uid']]); |
|
| 1288 | 1288 | |
| 1289 | - while ($row = $sth->fetch()) { |
|
| 1289 | + while ($row = $sth->fetch()) { |
|
| 1290 | 1290 | |
| 1291 | - $row_id = $row["id"]; |
|
| 1291 | + $row_id = $row["id"]; |
|
| 1292 | 1292 | |
| 1293 | - print "<tr data-row-id='$row_id'>"; |
|
| 1293 | + print "<tr data-row-id='$row_id'>"; |
|
| 1294 | 1294 | |
| 1295 | - print "<td align='center'> |
|
| 1295 | + print "<td align='center'> |
|
| 1296 | 1296 | <input onclick='Tables.onRowChecked(this)' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
| 1297 | - print "<td>" . htmlspecialchars($row["title"]) . "</td>"; |
|
| 1297 | + print "<td>" . htmlspecialchars($row["title"]) . "</td>"; |
|
| 1298 | 1298 | |
| 1299 | - print "<td align='right' class='text-muted'>"; |
|
| 1300 | - print make_local_datetime($row['created'], false); |
|
| 1301 | - print "</td>"; |
|
| 1299 | + print "<td align='right' class='text-muted'>"; |
|
| 1300 | + print make_local_datetime($row['created'], false); |
|
| 1301 | + print "</td>"; |
|
| 1302 | 1302 | |
| 1303 | - print "<td align='right' class='text-muted'>"; |
|
| 1304 | - print make_local_datetime($row['last_used'], false); |
|
| 1305 | - print "</td>"; |
|
| 1303 | + print "<td align='right' class='text-muted'>"; |
|
| 1304 | + print make_local_datetime($row['last_used'], false); |
|
| 1305 | + print "</td>"; |
|
| 1306 | 1306 | |
| 1307 | - print "</tr>"; |
|
| 1308 | - } |
|
| 1307 | + print "</tr>"; |
|
| 1308 | + } |
|
| 1309 | 1309 | |
| 1310 | - print "</table>"; |
|
| 1311 | - print "</div>"; |
|
| 1312 | - } |
|
| 1310 | + print "</table>"; |
|
| 1311 | + print "</div>"; |
|
| 1312 | + } |
|
| 1313 | 1313 | |
| 1314 | - private function encryptAppPassword($password) { |
|
| 1315 | - $salt = substr(bin2hex(get_random_bytes(24)), 0, 24); |
|
| 1314 | + private function encryptAppPassword($password) { |
|
| 1315 | + $salt = substr(bin2hex(get_random_bytes(24)), 0, 24); |
|
| 1316 | 1316 | |
| 1317 | - return "SSHA-512:".hash('sha512', $salt . $password). ":$salt"; |
|
| 1318 | - } |
|
| 1317 | + return "SSHA-512:".hash('sha512', $salt . $password). ":$salt"; |
|
| 1318 | + } |
|
| 1319 | 1319 | |
| 1320 | - public function deleteAppPassword() { |
|
| 1321 | - $ids = explode(",", clean($_REQUEST['ids'])); |
|
| 1322 | - $ids_qmarks = arr_qmarks($ids); |
|
| 1320 | + public function deleteAppPassword() { |
|
| 1321 | + $ids = explode(",", clean($_REQUEST['ids'])); |
|
| 1322 | + $ids_qmarks = arr_qmarks($ids); |
|
| 1323 | 1323 | |
| 1324 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_app_passwords WHERE id IN ($ids_qmarks) AND owner_uid = ?"); |
|
| 1325 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 1324 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_app_passwords WHERE id IN ($ids_qmarks) AND owner_uid = ?"); |
|
| 1325 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 1326 | 1326 | |
| 1327 | - $this->appPasswordList(); |
|
| 1328 | - } |
|
| 1327 | + $this->appPasswordList(); |
|
| 1328 | + } |
|
| 1329 | 1329 | |
| 1330 | - public function generateAppPassword() { |
|
| 1331 | - $title = clean($_REQUEST['title']); |
|
| 1332 | - $new_password = make_password(16); |
|
| 1333 | - $new_password_hash = $this->encryptAppPassword($new_password); |
|
| 1330 | + public function generateAppPassword() { |
|
| 1331 | + $title = clean($_REQUEST['title']); |
|
| 1332 | + $new_password = make_password(16); |
|
| 1333 | + $new_password_hash = $this->encryptAppPassword($new_password); |
|
| 1334 | 1334 | |
| 1335 | - print_warning(T_sprintf("Generated password <strong>%s</strong> for %s. Please remember it for future reference.", $new_password, $title)); |
|
| 1335 | + print_warning(T_sprintf("Generated password <strong>%s</strong> for %s. Please remember it for future reference.", $new_password, $title)); |
|
| 1336 | 1336 | |
| 1337 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_app_passwords |
|
| 1337 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_app_passwords |
|
| 1338 | 1338 | (title, pwd_hash, service, created, owner_uid) |
| 1339 | 1339 | VALUES |
| 1340 | 1340 | (?, ?, ?, NOW(), ?)"); |
| 1341 | 1341 | |
| 1342 | - $sth->execute([$title, $new_password_hash, Auth_Base::AUTH_SERVICE_API, $_SESSION['uid']]); |
|
| 1342 | + $sth->execute([$title, $new_password_hash, Auth_Base::AUTH_SERVICE_API, $_SESSION['uid']]); |
|
| 1343 | 1343 | |
| 1344 | - $this->appPasswordList(); |
|
| 1345 | - } |
|
| 1344 | + $this->appPasswordList(); |
|
| 1345 | + } |
|
| 1346 | 1346 | } |
@@ -1066,70 +1066,70 @@ |
||
| 1066 | 1066 | $qpart = ""; |
| 1067 | 1067 | |
| 1068 | 1068 | switch ($k) { |
| 1069 | - case "title": |
|
| 1070 | - $qpart = "title = " . $this->pdo->quote($feed_title); |
|
| 1071 | - break; |
|
| 1072 | - |
|
| 1073 | - case "feed_url": |
|
| 1074 | - $qpart = "feed_url = " . $this->pdo->quote($feed_url); |
|
| 1075 | - break; |
|
| 1076 | - |
|
| 1077 | - case "update_interval": |
|
| 1078 | - $qpart = "update_interval = " . $this->pdo->quote($upd_intl); |
|
| 1079 | - break; |
|
| 1080 | - |
|
| 1081 | - case "purge_interval": |
|
| 1082 | - $qpart = "purge_interval =" . $this->pdo->quote($purge_intl); |
|
| 1083 | - break; |
|
| 1084 | - |
|
| 1085 | - case "auth_login": |
|
| 1086 | - $qpart = "auth_login = " . $this->pdo->quote($auth_login); |
|
| 1087 | - break; |
|
| 1088 | - |
|
| 1089 | - case "auth_pass": |
|
| 1090 | - $qpart = "auth_pass =" . $this->pdo->quote($auth_pass). ", auth_pass_encrypted = false"; |
|
| 1091 | - break; |
|
| 1092 | - |
|
| 1093 | - case "private": |
|
| 1094 | - $qpart = "private = " . $this->pdo->quote($private); |
|
| 1095 | - break; |
|
| 1096 | - |
|
| 1097 | - case "include_in_digest": |
|
| 1098 | - $qpart = "include_in_digest = " . $this->pdo->quote($include_in_digest); |
|
| 1099 | - break; |
|
| 1100 | - |
|
| 1101 | - case "always_display_enclosures": |
|
| 1102 | - $qpart = "always_display_enclosures = " . $this->pdo->quote($always_display_enclosures); |
|
| 1103 | - break; |
|
| 1104 | - |
|
| 1105 | - case "mark_unread_on_update": |
|
| 1106 | - $qpart = "mark_unread_on_update = " . $this->pdo->quote($mark_unread_on_update); |
|
| 1107 | - break; |
|
| 1108 | - |
|
| 1109 | - case "cache_images": |
|
| 1110 | - $qpart = "cache_images = " . $this->pdo->quote($cache_images); |
|
| 1111 | - break; |
|
| 1112 | - |
|
| 1113 | - case "hide_images": |
|
| 1114 | - $qpart = "hide_images = " . $this->pdo->quote($hide_images); |
|
| 1115 | - break; |
|
| 1116 | - |
|
| 1117 | - case "cat_id": |
|
| 1118 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1119 | - if ($cat_id) { |
|
| 1120 | - $qpart = "cat_id = " . $this->pdo->quote($cat_id); |
|
| 1121 | - } else { |
|
| 1122 | - $qpart = 'cat_id = NULL'; |
|
| 1123 | - } |
|
| 1069 | + case "title": |
|
| 1070 | + $qpart = "title = " . $this->pdo->quote($feed_title); |
|
| 1071 | + break; |
|
| 1072 | + |
|
| 1073 | + case "feed_url": |
|
| 1074 | + $qpart = "feed_url = " . $this->pdo->quote($feed_url); |
|
| 1075 | + break; |
|
| 1076 | + |
|
| 1077 | + case "update_interval": |
|
| 1078 | + $qpart = "update_interval = " . $this->pdo->quote($upd_intl); |
|
| 1079 | + break; |
|
| 1080 | + |
|
| 1081 | + case "purge_interval": |
|
| 1082 | + $qpart = "purge_interval =" . $this->pdo->quote($purge_intl); |
|
| 1083 | + break; |
|
| 1084 | + |
|
| 1085 | + case "auth_login": |
|
| 1086 | + $qpart = "auth_login = " . $this->pdo->quote($auth_login); |
|
| 1087 | + break; |
|
| 1088 | + |
|
| 1089 | + case "auth_pass": |
|
| 1090 | + $qpart = "auth_pass =" . $this->pdo->quote($auth_pass). ", auth_pass_encrypted = false"; |
|
| 1091 | + break; |
|
| 1092 | + |
|
| 1093 | + case "private": |
|
| 1094 | + $qpart = "private = " . $this->pdo->quote($private); |
|
| 1095 | + break; |
|
| 1096 | + |
|
| 1097 | + case "include_in_digest": |
|
| 1098 | + $qpart = "include_in_digest = " . $this->pdo->quote($include_in_digest); |
|
| 1099 | + break; |
|
| 1100 | + |
|
| 1101 | + case "always_display_enclosures": |
|
| 1102 | + $qpart = "always_display_enclosures = " . $this->pdo->quote($always_display_enclosures); |
|
| 1103 | + break; |
|
| 1104 | + |
|
| 1105 | + case "mark_unread_on_update": |
|
| 1106 | + $qpart = "mark_unread_on_update = " . $this->pdo->quote($mark_unread_on_update); |
|
| 1107 | + break; |
|
| 1108 | + |
|
| 1109 | + case "cache_images": |
|
| 1110 | + $qpart = "cache_images = " . $this->pdo->quote($cache_images); |
|
| 1111 | + break; |
|
| 1112 | + |
|
| 1113 | + case "hide_images": |
|
| 1114 | + $qpart = "hide_images = " . $this->pdo->quote($hide_images); |
|
| 1115 | + break; |
|
| 1116 | + |
|
| 1117 | + case "cat_id": |
|
| 1118 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1119 | + if ($cat_id) { |
|
| 1120 | + $qpart = "cat_id = " . $this->pdo->quote($cat_id); |
|
| 1124 | 1121 | } else { |
| 1125 | - $qpart = ""; |
|
| 1122 | + $qpart = 'cat_id = NULL'; |
|
| 1126 | 1123 | } |
| 1124 | + } else { |
|
| 1125 | + $qpart = ""; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - break; |
|
| 1128 | + break; |
|
| 1129 | 1129 | |
| 1130 | - case "feed_language": |
|
| 1131 | - $qpart = "feed_language = " . $this->pdo->quote($feed_language); |
|
| 1132 | - break; |
|
| 1130 | + case "feed_language": |
|
| 1131 | + $qpart = "feed_language = " . $this->pdo->quote($feed_language); |
|
| 1132 | + break; |
|
| 1133 | 1133 | |
| 1134 | 1134 | } |
| 1135 | 1135 | |
@@ -1,87 +1,87 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Pref_Feeds extends Handler_Protected { |
| 3 | - public function csrf_ignore($method) { |
|
| 4 | - $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
|
| 5 | - "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
|
| 6 | - "batchsubscribe"); |
|
| 3 | + public function csrf_ignore($method) { |
|
| 4 | + $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
|
| 5 | + "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
|
| 6 | + "batchsubscribe"); |
|
| 7 | 7 | |
| 8 | - return array_search($method, $csrf_ignored) !== false; |
|
| 9 | - } |
|
| 8 | + return array_search($method, $csrf_ignored) !== false; |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public static function get_ts_languages() { |
|
| 12 | - $rv = []; |
|
| 11 | + public static function get_ts_languages() { |
|
| 12 | + $rv = []; |
|
| 13 | 13 | |
| 14 | - if (DB_TYPE == "pgsql") { |
|
| 15 | - $dbh = Db::pdo(); |
|
| 14 | + if (DB_TYPE == "pgsql") { |
|
| 15 | + $dbh = Db::pdo(); |
|
| 16 | 16 | |
| 17 | - $res = $dbh->query("SELECT cfgname FROM pg_ts_config"); |
|
| 17 | + $res = $dbh->query("SELECT cfgname FROM pg_ts_config"); |
|
| 18 | 18 | |
| 19 | - while ($row = $res->fetch()) { |
|
| 20 | - array_push($rv, ucfirst($row['cfgname'])); |
|
| 21 | - } |
|
| 22 | - } |
|
| 19 | + while ($row = $res->fetch()) { |
|
| 20 | + array_push($rv, ucfirst($row['cfgname'])); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - return $rv; |
|
| 25 | - } |
|
| 24 | + return $rv; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function batch_edit_cbox($elem, $label = false) { |
|
| 28 | - print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" |
|
| 27 | + public function batch_edit_cbox($elem, $label = false) { |
|
| 28 | + print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" |
|
| 29 | 29 | onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">"; |
| 30 | - } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function renamecat() { |
|
| 33 | - $title = clean($_REQUEST['title']); |
|
| 34 | - $id = clean($_REQUEST['id']); |
|
| 32 | + public function renamecat() { |
|
| 33 | + $title = clean($_REQUEST['title']); |
|
| 34 | + $id = clean($_REQUEST['id']); |
|
| 35 | 35 | |
| 36 | - if ($title) { |
|
| 37 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET |
|
| 36 | + if ($title) { |
|
| 37 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET |
|
| 38 | 38 | title = ? WHERE id = ? AND owner_uid = ?"); |
| 39 | - $sth->execute([$title, $id, $_SESSION['uid']]); |
|
| 40 | - } |
|
| 41 | - } |
|
| 39 | + $sth->execute([$title, $id, $_SESSION['uid']]); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - private function get_category_items($cat_id) { |
|
| 43 | + private function get_category_items($cat_id) { |
|
| 44 | 44 | |
| 45 | - if (clean($_REQUEST['mode']) != 2) |
|
| 46 | - $search = $_SESSION["prefs_feed_search"]; |
|
| 47 | - else |
|
| 48 | - $search = ""; |
|
| 45 | + if (clean($_REQUEST['mode']) != 2) |
|
| 46 | + $search = $_SESSION["prefs_feed_search"]; |
|
| 47 | + else |
|
| 48 | + $search = ""; |
|
| 49 | 49 | |
| 50 | - // first one is set by API |
|
| 51 | - $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
| 52 | - (clean($_REQUEST['mode']) != 2 && !$search); |
|
| 50 | + // first one is set by API |
|
| 51 | + $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
| 52 | + (clean($_REQUEST['mode']) != 2 && !$search); |
|
| 53 | 53 | |
| 54 | - $items = array(); |
|
| 54 | + $items = array(); |
|
| 55 | 55 | |
| 56 | - $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
| 56 | + $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
| 57 | 57 | WHERE owner_uid = ? AND parent_cat = ? ORDER BY order_id, title"); |
| 58 | - $sth->execute([$_SESSION['uid'], $cat_id]); |
|
| 58 | + $sth->execute([$_SESSION['uid'], $cat_id]); |
|
| 59 | 59 | |
| 60 | - while ($line = $sth->fetch()) { |
|
| 60 | + while ($line = $sth->fetch()) { |
|
| 61 | 61 | |
| 62 | - $cat = array(); |
|
| 63 | - $cat['id'] = 'CAT:' . $line['id']; |
|
| 64 | - $cat['bare_id'] = (int)$line['id']; |
|
| 65 | - $cat['name'] = $line['title']; |
|
| 66 | - $cat['items'] = array(); |
|
| 67 | - $cat['checkbox'] = false; |
|
| 68 | - $cat['type'] = 'category'; |
|
| 69 | - $cat['unread'] = -1; |
|
| 70 | - $cat['child_unread'] = -1; |
|
| 71 | - $cat['auxcounter'] = -1; |
|
| 72 | - $cat['parent_id'] = $cat_id; |
|
| 62 | + $cat = array(); |
|
| 63 | + $cat['id'] = 'CAT:' . $line['id']; |
|
| 64 | + $cat['bare_id'] = (int)$line['id']; |
|
| 65 | + $cat['name'] = $line['title']; |
|
| 66 | + $cat['items'] = array(); |
|
| 67 | + $cat['checkbox'] = false; |
|
| 68 | + $cat['type'] = 'category'; |
|
| 69 | + $cat['unread'] = -1; |
|
| 70 | + $cat['child_unread'] = -1; |
|
| 71 | + $cat['auxcounter'] = -1; |
|
| 72 | + $cat['parent_id'] = $cat_id; |
|
| 73 | 73 | |
| 74 | - $cat['items'] = $this->get_category_items($line['id']); |
|
| 74 | + $cat['items'] = $this->get_category_items($line['id']); |
|
| 75 | 75 | |
| 76 | - $num_children = $this->calculate_children_count($cat); |
|
| 77 | - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
| 76 | + $num_children = $this->calculate_children_count($cat); |
|
| 77 | + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
| 78 | 78 | |
| 79 | - if ($num_children > 0 || $show_empty_cats) |
|
| 80 | - array_push($items, $cat); |
|
| 79 | + if ($num_children > 0 || $show_empty_cats) |
|
| 80 | + array_push($items, $cat); |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
| 84 | + $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
| 85 | 85 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
| 86 | 86 | FROM ttrss_feeds |
| 87 | 87 | WHERE cat_id = :cat AND |
@@ -89,679 +89,679 @@ discard block |
||
| 89 | 89 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) |
| 90 | 90 | ORDER BY order_id, title"); |
| 91 | 91 | |
| 92 | - $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
| 93 | - |
|
| 94 | - while ($feed_line = $fsth->fetch()) { |
|
| 95 | - $feed = array(); |
|
| 96 | - $feed['id'] = 'FEED:' . $feed_line['id']; |
|
| 97 | - $feed['bare_id'] = (int)$feed_line['id']; |
|
| 98 | - $feed['auxcounter'] = -1; |
|
| 99 | - $feed['name'] = $feed_line['title']; |
|
| 100 | - $feed['checkbox'] = false; |
|
| 101 | - $feed['unread'] = -1; |
|
| 102 | - $feed['error'] = $feed_line['last_error']; |
|
| 103 | - $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
| 104 | - $feed['param'] = make_local_datetime( |
|
| 105 | - $feed_line['last_updated'], true); |
|
| 106 | - $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
|
| 107 | - |
|
| 108 | - array_push($items, $feed); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $items; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - public function getfeedtree() { |
|
| 115 | - print json_encode($this->makefeedtree()); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function makefeedtree() { |
|
| 119 | - |
|
| 120 | - if (clean($_REQUEST['mode']) != 2) |
|
| 121 | - $search = $_SESSION["prefs_feed_search"]; |
|
| 122 | - else |
|
| 123 | - $search = ""; |
|
| 124 | - |
|
| 125 | - $root = array(); |
|
| 126 | - $root['id'] = 'root'; |
|
| 127 | - $root['name'] = __('Feeds'); |
|
| 128 | - $root['items'] = array(); |
|
| 129 | - $root['type'] = 'category'; |
|
| 130 | - |
|
| 131 | - $enable_cats = get_pref('ENABLE_FEED_CATS'); |
|
| 132 | - |
|
| 133 | - if (clean($_REQUEST['mode']) == 2) { |
|
| 134 | - |
|
| 135 | - if ($enable_cats) { |
|
| 136 | - $cat = $this->feedlist_init_cat(-1); |
|
| 137 | - } else { |
|
| 138 | - $cat['items'] = array(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
|
| 142 | - array_push($cat['items'], $this->feedlist_init_feed($i)); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /* Plugin feeds for -1 */ |
|
| 146 | - |
|
| 147 | - $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
| 148 | - |
|
| 149 | - if ($feeds) { |
|
| 150 | - foreach ($feeds as $feed) { |
|
| 151 | - $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); |
|
| 152 | - |
|
| 153 | - $item = array(); |
|
| 154 | - $item['id'] = 'FEED:' . $feed_id; |
|
| 155 | - $item['bare_id'] = (int)$feed_id; |
|
| 156 | - $item['auxcounter'] = -1; |
|
| 157 | - $item['name'] = $feed['title']; |
|
| 158 | - $item['checkbox'] = false; |
|
| 159 | - $item['error'] = ''; |
|
| 160 | - $item['icon'] = $feed['icon']; |
|
| 161 | - |
|
| 162 | - $item['param'] = ''; |
|
| 163 | - $item['unread'] = -1; |
|
| 164 | - $item['type'] = 'feed'; |
|
| 165 | - |
|
| 166 | - array_push($cat['items'], $item); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if ($enable_cats) { |
|
| 171 | - array_push($root['items'], $cat); |
|
| 172 | - } else { |
|
| 173 | - $root['items'] = array_merge($root['items'], $cat['items']); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $sth = $this->pdo->prepare("SELECT * FROM |
|
| 92 | + $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
| 93 | + |
|
| 94 | + while ($feed_line = $fsth->fetch()) { |
|
| 95 | + $feed = array(); |
|
| 96 | + $feed['id'] = 'FEED:' . $feed_line['id']; |
|
| 97 | + $feed['bare_id'] = (int)$feed_line['id']; |
|
| 98 | + $feed['auxcounter'] = -1; |
|
| 99 | + $feed['name'] = $feed_line['title']; |
|
| 100 | + $feed['checkbox'] = false; |
|
| 101 | + $feed['unread'] = -1; |
|
| 102 | + $feed['error'] = $feed_line['last_error']; |
|
| 103 | + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
| 104 | + $feed['param'] = make_local_datetime( |
|
| 105 | + $feed_line['last_updated'], true); |
|
| 106 | + $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
|
| 107 | + |
|
| 108 | + array_push($items, $feed); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $items; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + public function getfeedtree() { |
|
| 115 | + print json_encode($this->makefeedtree()); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function makefeedtree() { |
|
| 119 | + |
|
| 120 | + if (clean($_REQUEST['mode']) != 2) |
|
| 121 | + $search = $_SESSION["prefs_feed_search"]; |
|
| 122 | + else |
|
| 123 | + $search = ""; |
|
| 124 | + |
|
| 125 | + $root = array(); |
|
| 126 | + $root['id'] = 'root'; |
|
| 127 | + $root['name'] = __('Feeds'); |
|
| 128 | + $root['items'] = array(); |
|
| 129 | + $root['type'] = 'category'; |
|
| 130 | + |
|
| 131 | + $enable_cats = get_pref('ENABLE_FEED_CATS'); |
|
| 132 | + |
|
| 133 | + if (clean($_REQUEST['mode']) == 2) { |
|
| 134 | + |
|
| 135 | + if ($enable_cats) { |
|
| 136 | + $cat = $this->feedlist_init_cat(-1); |
|
| 137 | + } else { |
|
| 138 | + $cat['items'] = array(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
|
| 142 | + array_push($cat['items'], $this->feedlist_init_feed($i)); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /* Plugin feeds for -1 */ |
|
| 146 | + |
|
| 147 | + $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
| 148 | + |
|
| 149 | + if ($feeds) { |
|
| 150 | + foreach ($feeds as $feed) { |
|
| 151 | + $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); |
|
| 152 | + |
|
| 153 | + $item = array(); |
|
| 154 | + $item['id'] = 'FEED:' . $feed_id; |
|
| 155 | + $item['bare_id'] = (int)$feed_id; |
|
| 156 | + $item['auxcounter'] = -1; |
|
| 157 | + $item['name'] = $feed['title']; |
|
| 158 | + $item['checkbox'] = false; |
|
| 159 | + $item['error'] = ''; |
|
| 160 | + $item['icon'] = $feed['icon']; |
|
| 161 | + |
|
| 162 | + $item['param'] = ''; |
|
| 163 | + $item['unread'] = -1; |
|
| 164 | + $item['type'] = 'feed'; |
|
| 165 | + |
|
| 166 | + array_push($cat['items'], $item); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if ($enable_cats) { |
|
| 171 | + array_push($root['items'], $cat); |
|
| 172 | + } else { |
|
| 173 | + $root['items'] = array_merge($root['items'], $cat['items']); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $sth = $this->pdo->prepare("SELECT * FROM |
|
| 177 | 177 | ttrss_labels2 WHERE owner_uid = ? ORDER by caption"); |
| 178 | - $sth->execute([$_SESSION['uid']]); |
|
| 178 | + $sth->execute([$_SESSION['uid']]); |
|
| 179 | 179 | |
| 180 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 181 | - $cat = $this->feedlist_init_cat(-2); |
|
| 182 | - } else { |
|
| 183 | - $cat['items'] = array(); |
|
| 184 | - } |
|
| 180 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 181 | + $cat = $this->feedlist_init_cat(-2); |
|
| 182 | + } else { |
|
| 183 | + $cat['items'] = array(); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - $num_labels = 0; |
|
| 187 | - while ($line = $sth->fetch()) { |
|
| 188 | - ++$num_labels; |
|
| 186 | + $num_labels = 0; |
|
| 187 | + while ($line = $sth->fetch()) { |
|
| 188 | + ++$num_labels; |
|
| 189 | 189 | |
| 190 | - $label_id = Labels::label_to_feed_id($line['id']); |
|
| 190 | + $label_id = Labels::label_to_feed_id($line['id']); |
|
| 191 | 191 | |
| 192 | - $feed = $this->feedlist_init_feed($label_id, false, 0); |
|
| 192 | + $feed = $this->feedlist_init_feed($label_id, false, 0); |
|
| 193 | 193 | |
| 194 | - $feed['fg_color'] = $line['fg_color']; |
|
| 195 | - $feed['bg_color'] = $line['bg_color']; |
|
| 194 | + $feed['fg_color'] = $line['fg_color']; |
|
| 195 | + $feed['bg_color'] = $line['bg_color']; |
|
| 196 | 196 | |
| 197 | - array_push($cat['items'], $feed); |
|
| 198 | - } |
|
| 197 | + array_push($cat['items'], $feed); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - if ($num_labels) { |
|
| 201 | - if ($enable_cats) { |
|
| 202 | - array_push($root['items'], $cat); |
|
| 203 | - } else { |
|
| 204 | - $root['items'] = array_merge($root['items'], $cat['items']); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 200 | + if ($num_labels) { |
|
| 201 | + if ($enable_cats) { |
|
| 202 | + array_push($root['items'], $cat); |
|
| 203 | + } else { |
|
| 204 | + $root['items'] = array_merge($root['items'], $cat['items']); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - if ($enable_cats) { |
|
| 210 | - $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
| 211 | - (clean($_REQUEST['mode']) != 2 && !$search); |
|
| 209 | + if ($enable_cats) { |
|
| 210 | + $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
| 211 | + (clean($_REQUEST['mode']) != 2 && !$search); |
|
| 212 | 212 | |
| 213 | - $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
| 213 | + $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
| 214 | 214 | WHERE owner_uid = ? AND parent_cat IS NULL ORDER BY order_id, title"); |
| 215 | - $sth->execute([$_SESSION['uid']]); |
|
| 216 | - |
|
| 217 | - while ($line = $sth->fetch()) { |
|
| 218 | - $cat = array(); |
|
| 219 | - $cat['id'] = 'CAT:' . $line['id']; |
|
| 220 | - $cat['bare_id'] = (int)$line['id']; |
|
| 221 | - $cat['auxcounter'] = -1; |
|
| 222 | - $cat['name'] = $line['title']; |
|
| 223 | - $cat['items'] = array(); |
|
| 224 | - $cat['checkbox'] = false; |
|
| 225 | - $cat['type'] = 'category'; |
|
| 226 | - $cat['unread'] = -1; |
|
| 227 | - $cat['child_unread'] = -1; |
|
| 228 | - |
|
| 229 | - $cat['items'] = $this->get_category_items($line['id']); |
|
| 230 | - |
|
| 231 | - $num_children = $this->calculate_children_count($cat); |
|
| 232 | - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
| 233 | - |
|
| 234 | - if ($num_children > 0 || $show_empty_cats) |
|
| 235 | - array_push($root['items'], $cat); |
|
| 236 | - |
|
| 237 | - $root['param'] += count($cat['items']); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /* Uncategorized is a special case */ |
|
| 241 | - |
|
| 242 | - $cat = array(); |
|
| 243 | - $cat['id'] = 'CAT:0'; |
|
| 244 | - $cat['bare_id'] = 0; |
|
| 245 | - $cat['auxcounter'] = -1; |
|
| 246 | - $cat['name'] = __("Uncategorized"); |
|
| 247 | - $cat['items'] = array(); |
|
| 248 | - $cat['type'] = 'category'; |
|
| 249 | - $cat['checkbox'] = false; |
|
| 250 | - $cat['unread'] = -1; |
|
| 251 | - $cat['child_unread'] = -1; |
|
| 252 | - |
|
| 253 | - $fsth = $this->pdo->prepare("SELECT id, title,last_error, |
|
| 215 | + $sth->execute([$_SESSION['uid']]); |
|
| 216 | + |
|
| 217 | + while ($line = $sth->fetch()) { |
|
| 218 | + $cat = array(); |
|
| 219 | + $cat['id'] = 'CAT:' . $line['id']; |
|
| 220 | + $cat['bare_id'] = (int)$line['id']; |
|
| 221 | + $cat['auxcounter'] = -1; |
|
| 222 | + $cat['name'] = $line['title']; |
|
| 223 | + $cat['items'] = array(); |
|
| 224 | + $cat['checkbox'] = false; |
|
| 225 | + $cat['type'] = 'category'; |
|
| 226 | + $cat['unread'] = -1; |
|
| 227 | + $cat['child_unread'] = -1; |
|
| 228 | + |
|
| 229 | + $cat['items'] = $this->get_category_items($line['id']); |
|
| 230 | + |
|
| 231 | + $num_children = $this->calculate_children_count($cat); |
|
| 232 | + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
| 233 | + |
|
| 234 | + if ($num_children > 0 || $show_empty_cats) |
|
| 235 | + array_push($root['items'], $cat); |
|
| 236 | + |
|
| 237 | + $root['param'] += count($cat['items']); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /* Uncategorized is a special case */ |
|
| 241 | + |
|
| 242 | + $cat = array(); |
|
| 243 | + $cat['id'] = 'CAT:0'; |
|
| 244 | + $cat['bare_id'] = 0; |
|
| 245 | + $cat['auxcounter'] = -1; |
|
| 246 | + $cat['name'] = __("Uncategorized"); |
|
| 247 | + $cat['items'] = array(); |
|
| 248 | + $cat['type'] = 'category'; |
|
| 249 | + $cat['checkbox'] = false; |
|
| 250 | + $cat['unread'] = -1; |
|
| 251 | + $cat['child_unread'] = -1; |
|
| 252 | + |
|
| 253 | + $fsth = $this->pdo->prepare("SELECT id, title,last_error, |
|
| 254 | 254 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
| 255 | 255 | FROM ttrss_feeds |
| 256 | 256 | WHERE cat_id IS NULL AND |
| 257 | 257 | owner_uid = :uid AND |
| 258 | 258 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) |
| 259 | 259 | ORDER BY order_id, title"); |
| 260 | - $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
| 261 | - |
|
| 262 | - while ($feed_line = $fsth->fetch()) { |
|
| 263 | - $feed = array(); |
|
| 264 | - $feed['id'] = 'FEED:' . $feed_line['id']; |
|
| 265 | - $feed['bare_id'] = (int)$feed_line['id']; |
|
| 266 | - $feed['auxcounter'] = -1; |
|
| 267 | - $feed['name'] = $feed_line['title']; |
|
| 268 | - $feed['checkbox'] = false; |
|
| 269 | - $feed['error'] = $feed_line['last_error']; |
|
| 270 | - $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
| 271 | - $feed['param'] = make_local_datetime( |
|
| 272 | - $feed_line['last_updated'], true); |
|
| 273 | - $feed['unread'] = -1; |
|
| 274 | - $feed['type'] = 'feed'; |
|
| 275 | - $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
|
| 276 | - |
|
| 277 | - array_push($cat['items'], $feed); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
|
| 281 | - |
|
| 282 | - if (count($cat['items']) > 0 || $show_empty_cats) |
|
| 283 | - array_push($root['items'], $cat); |
|
| 284 | - |
|
| 285 | - $num_children = $this->calculate_children_count($root); |
|
| 286 | - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
| 287 | - |
|
| 288 | - } else { |
|
| 289 | - $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
| 260 | + $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
| 261 | + |
|
| 262 | + while ($feed_line = $fsth->fetch()) { |
|
| 263 | + $feed = array(); |
|
| 264 | + $feed['id'] = 'FEED:' . $feed_line['id']; |
|
| 265 | + $feed['bare_id'] = (int)$feed_line['id']; |
|
| 266 | + $feed['auxcounter'] = -1; |
|
| 267 | + $feed['name'] = $feed_line['title']; |
|
| 268 | + $feed['checkbox'] = false; |
|
| 269 | + $feed['error'] = $feed_line['last_error']; |
|
| 270 | + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
| 271 | + $feed['param'] = make_local_datetime( |
|
| 272 | + $feed_line['last_updated'], true); |
|
| 273 | + $feed['unread'] = -1; |
|
| 274 | + $feed['type'] = 'feed'; |
|
| 275 | + $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
|
| 276 | + |
|
| 277 | + array_push($cat['items'], $feed); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
|
| 281 | + |
|
| 282 | + if (count($cat['items']) > 0 || $show_empty_cats) |
|
| 283 | + array_push($root['items'], $cat); |
|
| 284 | + |
|
| 285 | + $num_children = $this->calculate_children_count($root); |
|
| 286 | + $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
| 287 | + |
|
| 288 | + } else { |
|
| 289 | + $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
| 290 | 290 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
| 291 | 291 | FROM ttrss_feeds |
| 292 | 292 | WHERE owner_uid = :uid AND |
| 293 | 293 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) |
| 294 | 294 | ORDER BY order_id, title"); |
| 295 | - $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
| 296 | - |
|
| 297 | - while ($feed_line = $fsth->fetch()) { |
|
| 298 | - $feed = array(); |
|
| 299 | - $feed['id'] = 'FEED:' . $feed_line['id']; |
|
| 300 | - $feed['bare_id'] = (int)$feed_line['id']; |
|
| 301 | - $feed['auxcounter'] = -1; |
|
| 302 | - $feed['name'] = $feed_line['title']; |
|
| 303 | - $feed['checkbox'] = false; |
|
| 304 | - $feed['error'] = $feed_line['last_error']; |
|
| 305 | - $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
| 306 | - $feed['param'] = make_local_datetime( |
|
| 307 | - $feed_line['last_updated'], true); |
|
| 308 | - $feed['unread'] = -1; |
|
| 309 | - $feed['type'] = 'feed'; |
|
| 310 | - $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
|
| 311 | - |
|
| 312 | - array_push($root['items'], $feed); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($root['items'])), count($root['items'])); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $fl = array(); |
|
| 319 | - $fl['identifier'] = 'id'; |
|
| 320 | - $fl['label'] = 'name'; |
|
| 321 | - |
|
| 322 | - if (clean($_REQUEST['mode']) != 2) { |
|
| 323 | - $fl['items'] = array($root); |
|
| 324 | - } else { |
|
| 325 | - $fl['items'] = $root['items']; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return $fl; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - public function catsortreset() { |
|
| 332 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
| 295 | + $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
| 296 | + |
|
| 297 | + while ($feed_line = $fsth->fetch()) { |
|
| 298 | + $feed = array(); |
|
| 299 | + $feed['id'] = 'FEED:' . $feed_line['id']; |
|
| 300 | + $feed['bare_id'] = (int)$feed_line['id']; |
|
| 301 | + $feed['auxcounter'] = -1; |
|
| 302 | + $feed['name'] = $feed_line['title']; |
|
| 303 | + $feed['checkbox'] = false; |
|
| 304 | + $feed['error'] = $feed_line['last_error']; |
|
| 305 | + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
| 306 | + $feed['param'] = make_local_datetime( |
|
| 307 | + $feed_line['last_updated'], true); |
|
| 308 | + $feed['unread'] = -1; |
|
| 309 | + $feed['type'] = 'feed'; |
|
| 310 | + $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
|
| 311 | + |
|
| 312 | + array_push($root['items'], $feed); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($root['items'])), count($root['items'])); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $fl = array(); |
|
| 319 | + $fl['identifier'] = 'id'; |
|
| 320 | + $fl['label'] = 'name'; |
|
| 321 | + |
|
| 322 | + if (clean($_REQUEST['mode']) != 2) { |
|
| 323 | + $fl['items'] = array($root); |
|
| 324 | + } else { |
|
| 325 | + $fl['items'] = $root['items']; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return $fl; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + public function catsortreset() { |
|
| 332 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
| 333 | 333 | SET order_id = 0 WHERE owner_uid = ?"); |
| 334 | - $sth->execute([$_SESSION['uid']]); |
|
| 335 | - } |
|
| 334 | + $sth->execute([$_SESSION['uid']]); |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - public function feedsortreset() { |
|
| 338 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
| 337 | + public function feedsortreset() { |
|
| 338 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
| 339 | 339 | SET order_id = 0 WHERE owner_uid = ?"); |
| 340 | - $sth->execute([$_SESSION['uid']]); |
|
| 341 | - } |
|
| 340 | + $sth->execute([$_SESSION['uid']]); |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
|
| 343 | + private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
|
| 344 | 344 | |
| 345 | - $prefix = ""; |
|
| 346 | - for ($i = 0; $i < $nest_level; $i++) |
|
| 347 | - $prefix .= " "; |
|
| 345 | + $prefix = ""; |
|
| 346 | + for ($i = 0; $i < $nest_level; $i++) |
|
| 347 | + $prefix .= " "; |
|
| 348 | 348 | |
| 349 | - Debug::log("$prefix C: $item_id P: $parent_id"); |
|
| 349 | + Debug::log("$prefix C: $item_id P: $parent_id"); |
|
| 350 | 350 | |
| 351 | - $bare_item_id = substr($item_id, strpos($item_id, ':')+1); |
|
| 351 | + $bare_item_id = substr($item_id, strpos($item_id, ':')+1); |
|
| 352 | 352 | |
| 353 | - if ($item_id != 'root') { |
|
| 354 | - if ($parent_id && $parent_id != 'root') { |
|
| 355 | - $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1); |
|
| 356 | - $parent_qpart = $parent_bare_id; |
|
| 357 | - } else { |
|
| 358 | - $parent_qpart = null; |
|
| 359 | - } |
|
| 353 | + if ($item_id != 'root') { |
|
| 354 | + if ($parent_id && $parent_id != 'root') { |
|
| 355 | + $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1); |
|
| 356 | + $parent_qpart = $parent_bare_id; |
|
| 357 | + } else { |
|
| 358 | + $parent_qpart = null; |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
| 361 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
| 362 | 362 | SET parent_cat = ? WHERE id = ? AND |
| 363 | 363 | owner_uid = ?"); |
| 364 | - $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]); |
|
| 365 | - } |
|
| 364 | + $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]); |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - $order_id = 1; |
|
| 367 | + $order_id = 1; |
|
| 368 | 368 | |
| 369 | - $cat = $data_map[$item_id]; |
|
| 369 | + $cat = $data_map[$item_id]; |
|
| 370 | 370 | |
| 371 | - if ($cat && is_array($cat)) { |
|
| 372 | - foreach ($cat as $item) { |
|
| 373 | - $id = $item['_reference']; |
|
| 374 | - $bare_id = substr($id, strpos($id, ':')+1); |
|
| 371 | + if ($cat && is_array($cat)) { |
|
| 372 | + foreach ($cat as $item) { |
|
| 373 | + $id = $item['_reference']; |
|
| 374 | + $bare_id = substr($id, strpos($id, ':')+1); |
|
| 375 | 375 | |
| 376 | - Debug::log("$prefix [$order_id] $id/$bare_id"); |
|
| 376 | + Debug::log("$prefix [$order_id] $id/$bare_id"); |
|
| 377 | 377 | |
| 378 | - if ($item['_reference']) { |
|
| 378 | + if ($item['_reference']) { |
|
| 379 | 379 | |
| 380 | - if (strpos($id, "FEED") === 0) { |
|
| 380 | + if (strpos($id, "FEED") === 0) { |
|
| 381 | 381 | |
| 382 | - $cat_id = ($item_id != "root") ? $bare_item_id : null; |
|
| 382 | + $cat_id = ($item_id != "root") ? $bare_item_id : null; |
|
| 383 | 383 | |
| 384 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
| 384 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
| 385 | 385 | SET order_id = ?, cat_id = ? |
| 386 | 386 | WHERE id = ? AND owner_uid = ?"); |
| 387 | 387 | |
| 388 | - $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]); |
|
| 388 | + $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]); |
|
| 389 | 389 | |
| 390 | - } else if (strpos($id, "CAT:") === 0) { |
|
| 391 | - $this->process_category_order($data_map, $item['_reference'], $item_id, |
|
| 392 | - $nest_level+1); |
|
| 390 | + } else if (strpos($id, "CAT:") === 0) { |
|
| 391 | + $this->process_category_order($data_map, $item['_reference'], $item_id, |
|
| 392 | + $nest_level+1); |
|
| 393 | 393 | |
| 394 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
| 394 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
| 395 | 395 | SET order_id = ? WHERE id = ? AND |
| 396 | 396 | owner_uid = ?"); |
| 397 | - $sth->execute([$order_id, $bare_id, $_SESSION['uid']]); |
|
| 398 | - } |
|
| 399 | - } |
|
| 397 | + $sth->execute([$order_id, $bare_id, $_SESSION['uid']]); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - ++$order_id; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 401 | + ++$order_id; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - public function savefeedorder() { |
|
| 407 | - $data = json_decode($_POST['payload'], true); |
|
| 406 | + public function savefeedorder() { |
|
| 407 | + $data = json_decode($_POST['payload'], true); |
|
| 408 | 408 | |
| 409 | - #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
|
| 410 | - #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
|
| 409 | + #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
|
| 410 | + #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
|
| 411 | 411 | |
| 412 | - if (!is_array($data['items'])) |
|
| 413 | - $data['items'] = json_decode($data['items'], true); |
|
| 412 | + if (!is_array($data['items'])) |
|
| 413 | + $data['items'] = json_decode($data['items'], true); |
|
| 414 | 414 | |
| 415 | 415 | # print_r($data['items']); |
| 416 | 416 | |
| 417 | - if (is_array($data) && is_array($data['items'])) { |
|
| 417 | + if (is_array($data) && is_array($data['items'])) { |
|
| 418 | 418 | # $cat_order_id = 0; |
| 419 | 419 | |
| 420 | - $data_map = array(); |
|
| 421 | - $root_item = false; |
|
| 420 | + $data_map = array(); |
|
| 421 | + $root_item = false; |
|
| 422 | 422 | |
| 423 | - foreach ($data['items'] as $item) { |
|
| 423 | + foreach ($data['items'] as $item) { |
|
| 424 | 424 | |
| 425 | 425 | # if ($item['id'] != 'root') { |
| 426 | - if (is_array($item['items'])) { |
|
| 427 | - if (isset($item['items']['_reference'])) { |
|
| 428 | - $data_map[$item['id']] = array($item['items']); |
|
| 429 | - } else { |
|
| 430 | - $data_map[$item['id']] = $item['items']; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - if ($item['id'] == 'root') { |
|
| 434 | - $root_item = $item['id']; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $this->process_category_order($data_map, $root_item); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - public function removeicon() { |
|
| 443 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
| 444 | - |
|
| 445 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
| 446 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 447 | - |
|
| 448 | - if ($sth->fetch()) { |
|
| 449 | - @unlink(ICONS_DIR . "/$feed_id.ico"); |
|
| 450 | - |
|
| 451 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL where id = ?"); |
|
| 452 | - $sth->execute([$feed_id]); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - public function uploadicon() { |
|
| 457 | - header("Content-type: text/html"); |
|
| 458 | - |
|
| 459 | - if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { |
|
| 460 | - $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); |
|
| 461 | - |
|
| 462 | - $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], |
|
| 463 | - $tmp_file); |
|
| 464 | - |
|
| 465 | - if (!$result) { |
|
| 466 | - return; |
|
| 467 | - } |
|
| 468 | - } else { |
|
| 469 | - return; |
|
| 470 | - } |
|
| 426 | + if (is_array($item['items'])) { |
|
| 427 | + if (isset($item['items']['_reference'])) { |
|
| 428 | + $data_map[$item['id']] = array($item['items']); |
|
| 429 | + } else { |
|
| 430 | + $data_map[$item['id']] = $item['items']; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + if ($item['id'] == 'root') { |
|
| 434 | + $root_item = $item['id']; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $this->process_category_order($data_map, $root_item); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + public function removeicon() { |
|
| 443 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
| 444 | + |
|
| 445 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
| 446 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 447 | + |
|
| 448 | + if ($sth->fetch()) { |
|
| 449 | + @unlink(ICONS_DIR . "/$feed_id.ico"); |
|
| 450 | + |
|
| 451 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL where id = ?"); |
|
| 452 | + $sth->execute([$feed_id]); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + public function uploadicon() { |
|
| 457 | + header("Content-type: text/html"); |
|
| 458 | + |
|
| 459 | + if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { |
|
| 460 | + $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); |
|
| 461 | + |
|
| 462 | + $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], |
|
| 463 | + $tmp_file); |
|
| 464 | + |
|
| 465 | + if (!$result) { |
|
| 466 | + return; |
|
| 467 | + } |
|
| 468 | + } else { |
|
| 469 | + return; |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - $icon_file = $tmp_file; |
|
| 473 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
| 474 | - $rc = 2; // failed |
|
| 472 | + $icon_file = $tmp_file; |
|
| 473 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
| 474 | + $rc = 2; // failed |
|
| 475 | 475 | |
| 476 | - if (is_file($icon_file) && $feed_id) { |
|
| 477 | - if (filesize($icon_file) < 65535) { |
|
| 476 | + if (is_file($icon_file) && $feed_id) { |
|
| 477 | + if (filesize($icon_file) < 65535) { |
|
| 478 | 478 | |
| 479 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
| 480 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 479 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
| 480 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 481 | 481 | |
| 482 | - if ($sth->fetch()) { |
|
| 483 | - @unlink(ICONS_DIR . "/$feed_id.ico"); |
|
| 484 | - if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { |
|
| 482 | + if ($sth->fetch()) { |
|
| 483 | + @unlink(ICONS_DIR . "/$feed_id.ico"); |
|
| 484 | + if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { |
|
| 485 | 485 | |
| 486 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = '' WHERE id = ?"); |
|
| 487 | - $sth->execute([$feed_id]); |
|
| 486 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = '' WHERE id = ?"); |
|
| 487 | + $sth->execute([$feed_id]); |
|
| 488 | 488 | |
| 489 | - $rc = 0; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } else { |
|
| 493 | - $rc = 1; |
|
| 494 | - } |
|
| 495 | - } |
|
| 489 | + $rc = 0; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } else { |
|
| 493 | + $rc = 1; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | - if (is_file($icon_file)) @unlink($icon_file); |
|
| 497 | + if (is_file($icon_file)) @unlink($icon_file); |
|
| 498 | 498 | |
| 499 | - print $rc; |
|
| 500 | - return; |
|
| 501 | - } |
|
| 499 | + print $rc; |
|
| 500 | + return; |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - public function editfeed() { |
|
| 504 | - global $purge_intervals; |
|
| 505 | - global $update_intervals; |
|
| 503 | + public function editfeed() { |
|
| 504 | + global $purge_intervals; |
|
| 505 | + global $update_intervals; |
|
| 506 | 506 | |
| 507 | 507 | |
| 508 | - $feed_id = clean($_REQUEST["id"]); |
|
| 508 | + $feed_id = clean($_REQUEST["id"]); |
|
| 509 | 509 | |
| 510 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND |
|
| 510 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND |
|
| 511 | 511 | owner_uid = ?"); |
| 512 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 512 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 513 | 513 | |
| 514 | - if ($row = $sth->fetch()) { |
|
| 515 | - print '<div dojoType="dijit.layout.TabContainer" style="height : 450px"> |
|
| 514 | + if ($row = $sth->fetch()) { |
|
| 515 | + print '<div dojoType="dijit.layout.TabContainer" style="height : 450px"> |
|
| 516 | 516 | <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">'; |
| 517 | 517 | |
| 518 | - $title = htmlspecialchars($row["title"]); |
|
| 518 | + $title = htmlspecialchars($row["title"]); |
|
| 519 | 519 | |
| 520 | - print_hidden("id", "$feed_id"); |
|
| 521 | - print_hidden("op", "pref-feeds"); |
|
| 522 | - print_hidden("method", "editSave"); |
|
| 520 | + print_hidden("id", "$feed_id"); |
|
| 521 | + print_hidden("op", "pref-feeds"); |
|
| 522 | + print_hidden("method", "editSave"); |
|
| 523 | 523 | |
| 524 | - print "<header>".__("Feed")."</header>"; |
|
| 525 | - print "<section>"; |
|
| 524 | + print "<header>".__("Feed")."</header>"; |
|
| 525 | + print "<section>"; |
|
| 526 | 526 | |
| 527 | - /* Title */ |
|
| 527 | + /* Title */ |
|
| 528 | 528 | |
| 529 | - print "<fieldset>"; |
|
| 529 | + print "<fieldset>"; |
|
| 530 | 530 | |
| 531 | - print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
| 531 | + print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
| 532 | 532 | placeHolder=\"".__("Feed Title")."\" |
| 533 | 533 | style='font-size : 16px; width: 500px' name='title' value=\"$title\">"; |
| 534 | 534 | |
| 535 | - print "</fieldset>"; |
|
| 535 | + print "</fieldset>"; |
|
| 536 | 536 | |
| 537 | - /* Feed URL */ |
|
| 537 | + /* Feed URL */ |
|
| 538 | 538 | |
| 539 | - $feed_url = htmlspecialchars($row["feed_url"]); |
|
| 539 | + $feed_url = htmlspecialchars($row["feed_url"]); |
|
| 540 | 540 | |
| 541 | - print "<fieldset>"; |
|
| 541 | + print "<fieldset>"; |
|
| 542 | 542 | |
| 543 | - print "<label>" . __('URL:') . "</label> "; |
|
| 544 | - print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
| 543 | + print "<label>" . __('URL:') . "</label> "; |
|
| 544 | + print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
| 545 | 545 | placeHolder=\"".__("Feed URL")."\" |
| 546 | 546 | regExp='^(http|https)://.*' style='width : 300px' |
| 547 | 547 | name='feed_url' value=\"$feed_url\">"; |
| 548 | 548 | |
| 549 | - $last_error = $row["last_error"]; |
|
| 549 | + $last_error = $row["last_error"]; |
|
| 550 | 550 | |
| 551 | - if ($last_error) { |
|
| 552 | - print " <i class=\"material-icons\" |
|
| 551 | + if ($last_error) { |
|
| 552 | + print " <i class=\"material-icons\" |
|
| 553 | 553 | title=\"".htmlspecialchars($last_error)."\">error</i>"; |
| 554 | - } |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | - print "</fieldset>"; |
|
| 556 | + print "</fieldset>"; |
|
| 557 | 557 | |
| 558 | - /* Category */ |
|
| 558 | + /* Category */ |
|
| 559 | 559 | |
| 560 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 560 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 561 | 561 | |
| 562 | - $cat_id = $row["cat_id"]; |
|
| 562 | + $cat_id = $row["cat_id"]; |
|
| 563 | 563 | |
| 564 | - print "<fieldset>"; |
|
| 564 | + print "<fieldset>"; |
|
| 565 | 565 | |
| 566 | - print "<label>" . __('Place in category:') . "</label> "; |
|
| 566 | + print "<label>" . __('Place in category:') . "</label> "; |
|
| 567 | 567 | |
| 568 | - print_feed_cat_select("cat_id", $cat_id, |
|
| 569 | - 'dojoType="fox.form.Select"'); |
|
| 568 | + print_feed_cat_select("cat_id", $cat_id, |
|
| 569 | + 'dojoType="fox.form.Select"'); |
|
| 570 | 570 | |
| 571 | - print "</fieldset>"; |
|
| 572 | - } |
|
| 571 | + print "</fieldset>"; |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | - /* Site URL */ |
|
| 574 | + /* Site URL */ |
|
| 575 | 575 | |
| 576 | - $site_url = htmlspecialchars($row["site_url"]); |
|
| 576 | + $site_url = htmlspecialchars($row["site_url"]); |
|
| 577 | 577 | |
| 578 | - print "<fieldset>"; |
|
| 578 | + print "<fieldset>"; |
|
| 579 | 579 | |
| 580 | - print "<label>" . __('Site URL:') . "</label> "; |
|
| 581 | - print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
| 580 | + print "<label>" . __('Site URL:') . "</label> "; |
|
| 581 | + print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
| 582 | 582 | placeHolder=\"".__("Site URL")."\" |
| 583 | 583 | regExp='^(http|https)://.*' style='width : 300px' |
| 584 | 584 | name='site_url' value=\"$site_url\">"; |
| 585 | 585 | |
| 586 | - print "</fieldset>"; |
|
| 586 | + print "</fieldset>"; |
|
| 587 | 587 | |
| 588 | - /* FTS Stemming Language */ |
|
| 588 | + /* FTS Stemming Language */ |
|
| 589 | 589 | |
| 590 | - if (DB_TYPE == "pgsql") { |
|
| 591 | - $feed_language = $row["feed_language"]; |
|
| 590 | + if (DB_TYPE == "pgsql") { |
|
| 591 | + $feed_language = $row["feed_language"]; |
|
| 592 | 592 | |
| 593 | - if (!$feed_language) |
|
| 594 | - $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE'); |
|
| 593 | + if (!$feed_language) |
|
| 594 | + $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE'); |
|
| 595 | 595 | |
| 596 | - print "<fieldset>"; |
|
| 596 | + print "<fieldset>"; |
|
| 597 | 597 | |
| 598 | - print "<label>" . __('Language:') . "</label> "; |
|
| 599 | - print_select("feed_language", $feed_language, $this::get_ts_languages(), |
|
| 600 | - 'dojoType="fox.form.Select"'); |
|
| 598 | + print "<label>" . __('Language:') . "</label> "; |
|
| 599 | + print_select("feed_language", $feed_language, $this::get_ts_languages(), |
|
| 600 | + 'dojoType="fox.form.Select"'); |
|
| 601 | 601 | |
| 602 | - print "</fieldset>"; |
|
| 603 | - } |
|
| 602 | + print "</fieldset>"; |
|
| 603 | + } |
|
| 604 | 604 | |
| 605 | - print "</section>"; |
|
| 605 | + print "</section>"; |
|
| 606 | 606 | |
| 607 | - print "<header>".__("Update")."</header>"; |
|
| 608 | - print "<section>"; |
|
| 607 | + print "<header>".__("Update")."</header>"; |
|
| 608 | + print "<section>"; |
|
| 609 | 609 | |
| 610 | - /* Update Interval */ |
|
| 610 | + /* Update Interval */ |
|
| 611 | 611 | |
| 612 | - $update_interval = $row["update_interval"]; |
|
| 612 | + $update_interval = $row["update_interval"]; |
|
| 613 | 613 | |
| 614 | - print "<fieldset>"; |
|
| 614 | + print "<fieldset>"; |
|
| 615 | 615 | |
| 616 | - print "<label>".__("Interval:")."</label> "; |
|
| 616 | + print "<label>".__("Interval:")."</label> "; |
|
| 617 | 617 | |
| 618 | - print_select_hash("update_interval", $update_interval, $update_intervals, |
|
| 619 | - 'dojoType="fox.form.Select"'); |
|
| 618 | + print_select_hash("update_interval", $update_interval, $update_intervals, |
|
| 619 | + 'dojoType="fox.form.Select"'); |
|
| 620 | 620 | |
| 621 | - print "</fieldset>"; |
|
| 621 | + print "</fieldset>"; |
|
| 622 | 622 | |
| 623 | - /* Purge intl */ |
|
| 623 | + /* Purge intl */ |
|
| 624 | 624 | |
| 625 | - $purge_interval = $row["purge_interval"]; |
|
| 625 | + $purge_interval = $row["purge_interval"]; |
|
| 626 | 626 | |
| 627 | - print "<fieldset>"; |
|
| 627 | + print "<fieldset>"; |
|
| 628 | 628 | |
| 629 | - print "<label>" . __('Article purging:') . "</label> "; |
|
| 629 | + print "<label>" . __('Article purging:') . "</label> "; |
|
| 630 | 630 | |
| 631 | - print_select_hash("purge_interval", $purge_interval, $purge_intervals, |
|
| 632 | - 'dojoType="fox.form.Select" ' . |
|
| 633 | - ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); |
|
| 631 | + print_select_hash("purge_interval", $purge_interval, $purge_intervals, |
|
| 632 | + 'dojoType="fox.form.Select" ' . |
|
| 633 | + ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); |
|
| 634 | 634 | |
| 635 | - print "</fieldset>"; |
|
| 635 | + print "</fieldset>"; |
|
| 636 | 636 | |
| 637 | - print "</section>"; |
|
| 637 | + print "</section>"; |
|
| 638 | 638 | |
| 639 | - $auth_login = htmlspecialchars($row["auth_login"]); |
|
| 640 | - $auth_pass = htmlspecialchars($row["auth_pass"]); |
|
| 639 | + $auth_login = htmlspecialchars($row["auth_login"]); |
|
| 640 | + $auth_pass = htmlspecialchars($row["auth_pass"]); |
|
| 641 | 641 | |
| 642 | - $auth_enabled = $auth_login !== '' || $auth_pass !== ''; |
|
| 642 | + $auth_enabled = $auth_login !== '' || $auth_pass !== ''; |
|
| 643 | 643 | |
| 644 | - $auth_style = $auth_enabled ? '' : 'display: none'; |
|
| 645 | - print "<div id='feedEditDlg_loginContainer' style='$auth_style'>"; |
|
| 646 | - print "<header>".__("Authentication")."</header>"; |
|
| 647 | - print "<section>"; |
|
| 644 | + $auth_style = $auth_enabled ? '' : 'display: none'; |
|
| 645 | + print "<div id='feedEditDlg_loginContainer' style='$auth_style'>"; |
|
| 646 | + print "<header>".__("Authentication")."</header>"; |
|
| 647 | + print "<section>"; |
|
| 648 | 648 | |
| 649 | - print "<fieldset>"; |
|
| 649 | + print "<fieldset>"; |
|
| 650 | 650 | |
| 651 | - print "<input dojoType='dijit.form.TextBox' id='feedEditDlg_login' |
|
| 651 | + print "<input dojoType='dijit.form.TextBox' id='feedEditDlg_login' |
|
| 652 | 652 | placeHolder='".__("Login")."' |
| 653 | 653 | autocomplete='new-password' |
| 654 | 654 | name='auth_login' value=\"$auth_login\">"; |
| 655 | 655 | |
| 656 | - print "</fieldset><fieldset>"; |
|
| 656 | + print "</fieldset><fieldset>"; |
|
| 657 | 657 | |
| 658 | - print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
| 658 | + print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
| 659 | 659 | autocomplete='new-password' |
| 660 | 660 | placeHolder='".__("Password")."' |
| 661 | 661 | value=\"$auth_pass\">"; |
| 662 | 662 | |
| 663 | - print "<div dojoType='dijit.Tooltip' connectId='feedEditDlg_login' position='below'> |
|
| 663 | + print "<div dojoType='dijit.Tooltip' connectId='feedEditDlg_login' position='below'> |
|
| 664 | 664 | ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." |
| 665 | 665 | </div>"; |
| 666 | 666 | |
| 667 | - print "</fieldset>"; |
|
| 667 | + print "</fieldset>"; |
|
| 668 | 668 | |
| 669 | - print "</section></div>"; |
|
| 669 | + print "</section></div>"; |
|
| 670 | 670 | |
| 671 | - $auth_checked = $auth_enabled ? 'checked' : ''; |
|
| 672 | - print "<label class='checkbox'> |
|
| 671 | + $auth_checked = $auth_enabled ? 'checked' : ''; |
|
| 672 | + print "<label class='checkbox'> |
|
| 673 | 673 | <input type='checkbox' $auth_checked name='need_auth' dojoType='dijit.form.CheckBox' id='feedEditDlg_loginCheck' |
| 674 | 674 | onclick='displayIfChecked(this, \"feedEditDlg_loginContainer\")'> |
| 675 | 675 | ".__('This feed requires authentication.')."</label>"; |
| 676 | 676 | |
| 677 | - print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">'; |
|
| 677 | + print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">'; |
|
| 678 | 678 | |
| 679 | - print "<section class='narrow'>"; |
|
| 679 | + print "<section class='narrow'>"; |
|
| 680 | 680 | |
| 681 | - $include_in_digest = $row["include_in_digest"]; |
|
| 681 | + $include_in_digest = $row["include_in_digest"]; |
|
| 682 | 682 | |
| 683 | - if ($include_in_digest) { |
|
| 684 | - $checked = "checked=\"1\""; |
|
| 685 | - } else { |
|
| 686 | - $checked = ""; |
|
| 687 | - } |
|
| 683 | + if ($include_in_digest) { |
|
| 684 | + $checked = "checked=\"1\""; |
|
| 685 | + } else { |
|
| 686 | + $checked = ""; |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | - print "<fieldset class='narrow'>"; |
|
| 689 | + print "<fieldset class='narrow'>"; |
|
| 690 | 690 | |
| 691 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" |
|
| 691 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" |
|
| 692 | 692 | name=\"include_in_digest\" |
| 693 | 693 | $checked> ".__('Include in e-mail digest')."</label>"; |
| 694 | 694 | |
| 695 | - print "</fieldset>"; |
|
| 695 | + print "</fieldset>"; |
|
| 696 | 696 | |
| 697 | - $always_display_enclosures = $row["always_display_enclosures"]; |
|
| 697 | + $always_display_enclosures = $row["always_display_enclosures"]; |
|
| 698 | 698 | |
| 699 | - if ($always_display_enclosures) { |
|
| 700 | - $checked = "checked"; |
|
| 701 | - } else { |
|
| 702 | - $checked = ""; |
|
| 703 | - } |
|
| 699 | + if ($always_display_enclosures) { |
|
| 700 | + $checked = "checked"; |
|
| 701 | + } else { |
|
| 702 | + $checked = ""; |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | - print "<fieldset class='narrow'>"; |
|
| 705 | + print "<fieldset class='narrow'>"; |
|
| 706 | 706 | |
| 707 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" |
|
| 707 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" |
|
| 708 | 708 | name=\"always_display_enclosures\" |
| 709 | 709 | $checked> ".__('Always display image attachments')."</label>"; |
| 710 | 710 | |
| 711 | - print "</fieldset>"; |
|
| 711 | + print "</fieldset>"; |
|
| 712 | 712 | |
| 713 | - $hide_images = $row["hide_images"]; |
|
| 713 | + $hide_images = $row["hide_images"]; |
|
| 714 | 714 | |
| 715 | - if ($hide_images) { |
|
| 716 | - $checked = "checked=\"1\""; |
|
| 717 | - } else { |
|
| 718 | - $checked = ""; |
|
| 719 | - } |
|
| 715 | + if ($hide_images) { |
|
| 716 | + $checked = "checked=\"1\""; |
|
| 717 | + } else { |
|
| 718 | + $checked = ""; |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | - print "<fieldset class='narrow'>"; |
|
| 721 | + print "<fieldset class='narrow'>"; |
|
| 722 | 722 | |
| 723 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='hide_images' |
|
| 723 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='hide_images' |
|
| 724 | 724 | name='hide_images' $checked> ".__('Do not embed media')."</label>"; |
| 725 | 725 | |
| 726 | - print "</fieldset>"; |
|
| 726 | + print "</fieldset>"; |
|
| 727 | 727 | |
| 728 | - $cache_images = $row["cache_images"]; |
|
| 728 | + $cache_images = $row["cache_images"]; |
|
| 729 | 729 | |
| 730 | - if ($cache_images) { |
|
| 731 | - $checked = "checked=\"1\""; |
|
| 732 | - } else { |
|
| 733 | - $checked = ""; |
|
| 734 | - } |
|
| 730 | + if ($cache_images) { |
|
| 731 | + $checked = "checked=\"1\""; |
|
| 732 | + } else { |
|
| 733 | + $checked = ""; |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | - print "<fieldset class='narrow'>"; |
|
| 736 | + print "<fieldset class='narrow'>"; |
|
| 737 | 737 | |
| 738 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='cache_images' |
|
| 738 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='cache_images' |
|
| 739 | 739 | name='cache_images' $checked> ". __('Cache media')."</label>"; |
| 740 | 740 | |
| 741 | - print "</fieldset>"; |
|
| 741 | + print "</fieldset>"; |
|
| 742 | 742 | |
| 743 | - $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
| 743 | + $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
| 744 | 744 | |
| 745 | - if ($mark_unread_on_update) { |
|
| 746 | - $checked = "checked"; |
|
| 747 | - } else { |
|
| 748 | - $checked = ""; |
|
| 749 | - } |
|
| 745 | + if ($mark_unread_on_update) { |
|
| 746 | + $checked = "checked"; |
|
| 747 | + } else { |
|
| 748 | + $checked = ""; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - print "<fieldset class='narrow'>"; |
|
| 751 | + print "<fieldset class='narrow'>"; |
|
| 752 | 752 | |
| 753 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='mark_unread_on_update' |
|
| 753 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='mark_unread_on_update' |
|
| 754 | 754 | name='mark_unread_on_update' $checked> ".__('Mark updated articles as unread')."</label>"; |
| 755 | 755 | |
| 756 | - print "</fieldset>"; |
|
| 756 | + print "</fieldset>"; |
|
| 757 | 757 | |
| 758 | - print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">'; |
|
| 758 | + print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">'; |
|
| 759 | 759 | |
| 760 | - /* Icon */ |
|
| 760 | + /* Icon */ |
|
| 761 | 761 | |
| 762 | - print "<img class='feedIcon feed-editor-icon' src=\"".Feeds::getFeedIcon($feed_id)."\">"; |
|
| 762 | + print "<img class='feedIcon feed-editor-icon' src=\"".Feeds::getFeedIcon($feed_id)."\">"; |
|
| 763 | 763 | |
| 764 | - print "<form onsubmit='return false;' id='feed_icon_upload_form' |
|
| 764 | + print "<form onsubmit='return false;' id='feed_icon_upload_form' |
|
| 765 | 765 | enctype='multipart/form-data' method='POST'> |
| 766 | 766 | <label class='dijitButton'>".__("Choose file...")." |
| 767 | 767 | <input style='display: none' id='icon_file' size='10' name='icon_file' type='file'> |
@@ -775,231 +775,231 @@ discard block |
||
| 775 | 775 | type='submit'>".__('Remove')."</button> |
| 776 | 776 | </form>"; |
| 777 | 777 | |
| 778 | - print "</section>"; |
|
| 778 | + print "</section>"; |
|
| 779 | 779 | |
| 780 | - print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">'; |
|
| 780 | + print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">'; |
|
| 781 | 781 | |
| 782 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
|
| 783 | - "hook_prefs_edit_feed", $feed_id); |
|
| 782 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
|
| 783 | + "hook_prefs_edit_feed", $feed_id); |
|
| 784 | 784 | |
| 785 | - print "</div></div>"; |
|
| 785 | + print "</div></div>"; |
|
| 786 | 786 | |
| 787 | - $title = htmlspecialchars($title, ENT_QUOTES); |
|
| 787 | + $title = htmlspecialchars($title, ENT_QUOTES); |
|
| 788 | 788 | |
| 789 | - print "<footer> |
|
| 789 | + print "<footer> |
|
| 790 | 790 | <button style='float : left' class='alt-danger' dojoType='dijit.form.Button' onclick='return CommonDialogs.unsubscribeFeed($feed_id, \"$title\")'>". |
| 791 | - __('Unsubscribe')."</button> |
|
| 791 | + __('Unsubscribe')."</button> |
|
| 792 | 792 | <button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> |
| 793 | 793 | <button dojoType='dijit.form.Button' onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> |
| 794 | 794 | </footer>"; |
| 795 | - } |
|
| 796 | - } |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | 797 | |
| 798 | - public function editfeeds() { |
|
| 799 | - global $purge_intervals; |
|
| 800 | - global $update_intervals; |
|
| 798 | + public function editfeeds() { |
|
| 799 | + global $purge_intervals; |
|
| 800 | + global $update_intervals; |
|
| 801 | 801 | |
| 802 | - $feed_ids = clean($_REQUEST["ids"]); |
|
| 802 | + $feed_ids = clean($_REQUEST["ids"]); |
|
| 803 | 803 | |
| 804 | - print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
|
| 804 | + print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
|
| 805 | 805 | |
| 806 | - print "<p>"; |
|
| 806 | + print "<p>"; |
|
| 807 | 807 | |
| 808 | - print_hidden("ids", "$feed_ids"); |
|
| 809 | - print_hidden("op", "pref-feeds"); |
|
| 810 | - print_hidden("method", "batchEditSave"); |
|
| 808 | + print_hidden("ids", "$feed_ids"); |
|
| 809 | + print_hidden("op", "pref-feeds"); |
|
| 810 | + print_hidden("method", "batchEditSave"); |
|
| 811 | 811 | |
| 812 | - print "<header>".__("Feed")."</header>"; |
|
| 813 | - print "<section>"; |
|
| 812 | + print "<header>".__("Feed")."</header>"; |
|
| 813 | + print "<section>"; |
|
| 814 | 814 | |
| 815 | - /* Category */ |
|
| 815 | + /* Category */ |
|
| 816 | 816 | |
| 817 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 817 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 818 | 818 | |
| 819 | - print "<fieldset>"; |
|
| 819 | + print "<fieldset>"; |
|
| 820 | 820 | |
| 821 | - print "<label>" . __('Place in category:') . "</label> "; |
|
| 821 | + print "<label>" . __('Place in category:') . "</label> "; |
|
| 822 | 822 | |
| 823 | - print_feed_cat_select("cat_id", false, |
|
| 824 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
| 823 | + print_feed_cat_select("cat_id", false, |
|
| 824 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
| 825 | 825 | |
| 826 | - $this->batch_edit_cbox("cat_id"); |
|
| 826 | + $this->batch_edit_cbox("cat_id"); |
|
| 827 | 827 | |
| 828 | - print "</fieldset>"; |
|
| 829 | - } |
|
| 828 | + print "</fieldset>"; |
|
| 829 | + } |
|
| 830 | 830 | |
| 831 | - /* FTS Stemming Language */ |
|
| 831 | + /* FTS Stemming Language */ |
|
| 832 | 832 | |
| 833 | - if (DB_TYPE == "pgsql") { |
|
| 834 | - print "<fieldset>"; |
|
| 833 | + if (DB_TYPE == "pgsql") { |
|
| 834 | + print "<fieldset>"; |
|
| 835 | 835 | |
| 836 | - print "<label>" . __('Language:') . "</label> "; |
|
| 837 | - print_select("feed_language", "", $this::get_ts_languages(), |
|
| 838 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
| 836 | + print "<label>" . __('Language:') . "</label> "; |
|
| 837 | + print_select("feed_language", "", $this::get_ts_languages(), |
|
| 838 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
| 839 | 839 | |
| 840 | - $this->batch_edit_cbox("feed_language"); |
|
| 840 | + $this->batch_edit_cbox("feed_language"); |
|
| 841 | 841 | |
| 842 | - print "</fieldset>"; |
|
| 843 | - } |
|
| 842 | + print "</fieldset>"; |
|
| 843 | + } |
|
| 844 | 844 | |
| 845 | - print "</section>"; |
|
| 845 | + print "</section>"; |
|
| 846 | 846 | |
| 847 | - print "<header>".__("Update")."</header>"; |
|
| 848 | - print "<section>"; |
|
| 847 | + print "<header>".__("Update")."</header>"; |
|
| 848 | + print "<section>"; |
|
| 849 | 849 | |
| 850 | - /* Update Interval */ |
|
| 850 | + /* Update Interval */ |
|
| 851 | 851 | |
| 852 | - print "<fieldset>"; |
|
| 852 | + print "<fieldset>"; |
|
| 853 | 853 | |
| 854 | - print "<label>".__("Interval:")."</label> "; |
|
| 854 | + print "<label>".__("Interval:")."</label> "; |
|
| 855 | 855 | |
| 856 | - print_select_hash("update_interval", "", $update_intervals, |
|
| 857 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
| 856 | + print_select_hash("update_interval", "", $update_intervals, |
|
| 857 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
| 858 | 858 | |
| 859 | - $this->batch_edit_cbox("update_interval"); |
|
| 859 | + $this->batch_edit_cbox("update_interval"); |
|
| 860 | 860 | |
| 861 | - print "</fieldset>"; |
|
| 861 | + print "</fieldset>"; |
|
| 862 | 862 | |
| 863 | - /* Purge intl */ |
|
| 863 | + /* Purge intl */ |
|
| 864 | 864 | |
| 865 | - if (FORCE_ARTICLE_PURGE == 0) { |
|
| 865 | + if (FORCE_ARTICLE_PURGE == 0) { |
|
| 866 | 866 | |
| 867 | - print "<fieldset>"; |
|
| 867 | + print "<fieldset>"; |
|
| 868 | 868 | |
| 869 | - print "<label>" . __('Article purging:') . "</label> "; |
|
| 869 | + print "<label>" . __('Article purging:') . "</label> "; |
|
| 870 | 870 | |
| 871 | - print_select_hash("purge_interval", "", $purge_intervals, |
|
| 872 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
| 871 | + print_select_hash("purge_interval", "", $purge_intervals, |
|
| 872 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
| 873 | 873 | |
| 874 | - $this->batch_edit_cbox("purge_interval"); |
|
| 874 | + $this->batch_edit_cbox("purge_interval"); |
|
| 875 | 875 | |
| 876 | - print "</fieldset>"; |
|
| 877 | - } |
|
| 876 | + print "</fieldset>"; |
|
| 877 | + } |
|
| 878 | 878 | |
| 879 | - print "</section>"; |
|
| 880 | - print "<header>".__("Authentication")."</header>"; |
|
| 881 | - print "<section>"; |
|
| 879 | + print "</section>"; |
|
| 880 | + print "<header>".__("Authentication")."</header>"; |
|
| 881 | + print "<section>"; |
|
| 882 | 882 | |
| 883 | - print "<fieldset>"; |
|
| 883 | + print "<fieldset>"; |
|
| 884 | 884 | |
| 885 | - print "<input dojoType='dijit.form.TextBox' |
|
| 885 | + print "<input dojoType='dijit.form.TextBox' |
|
| 886 | 886 | placeHolder=\"".__("Login")."\" disabled='1' |
| 887 | 887 | autocomplete='new-password' |
| 888 | 888 | name='auth_login' value=''>"; |
| 889 | 889 | |
| 890 | - $this->batch_edit_cbox("auth_login"); |
|
| 890 | + $this->batch_edit_cbox("auth_login"); |
|
| 891 | 891 | |
| 892 | - print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
| 892 | + print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
| 893 | 893 | autocomplete='new-password' |
| 894 | 894 | placeHolder=\"".__("Password")."\" disabled='1' |
| 895 | 895 | value=''>"; |
| 896 | 896 | |
| 897 | - $this->batch_edit_cbox("auth_pass"); |
|
| 897 | + $this->batch_edit_cbox("auth_pass"); |
|
| 898 | 898 | |
| 899 | - print "</fieldset>"; |
|
| 899 | + print "</fieldset>"; |
|
| 900 | 900 | |
| 901 | - print "</section>"; |
|
| 902 | - print "<header>".__("Options")."</header>"; |
|
| 903 | - print "<section>"; |
|
| 901 | + print "</section>"; |
|
| 902 | + print "<header>".__("Options")."</header>"; |
|
| 903 | + print "<section>"; |
|
| 904 | 904 | |
| 905 | - print "<fieldset class='narrow'>"; |
|
| 906 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='include_in_digest' |
|
| 905 | + print "<fieldset class='narrow'>"; |
|
| 906 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='include_in_digest' |
|
| 907 | 907 | name='include_in_digest' dojoType='dijit.form.CheckBox'> ".__('Include in e-mail digest')."</label>"; |
| 908 | 908 | |
| 909 | - print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); |
|
| 909 | + print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); |
|
| 910 | 910 | |
| 911 | - print "</fieldset><fieldset class='narrow'>"; |
|
| 911 | + print "</fieldset><fieldset class='narrow'>"; |
|
| 912 | 912 | |
| 913 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='always_display_enclosures' |
|
| 913 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='always_display_enclosures' |
|
| 914 | 914 | name='always_display_enclosures' dojoType='dijit.form.CheckBox'> ".__('Always display image attachments')."</label>"; |
| 915 | 915 | |
| 916 | - print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); |
|
| 916 | + print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); |
|
| 917 | 917 | |
| 918 | - print "</fieldset><fieldset class='narrow'>"; |
|
| 918 | + print "</fieldset><fieldset class='narrow'>"; |
|
| 919 | 919 | |
| 920 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='hide_images' |
|
| 920 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='hide_images' |
|
| 921 | 921 | name='hide_images' dojoType='dijit.form.CheckBox'> ". __('Do not embed media')."</label>"; |
| 922 | 922 | |
| 923 | - print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); |
|
| 923 | + print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); |
|
| 924 | 924 | |
| 925 | - print "</fieldset><fieldset class='narrow'>"; |
|
| 925 | + print "</fieldset><fieldset class='narrow'>"; |
|
| 926 | 926 | |
| 927 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='cache_images' |
|
| 927 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='cache_images' |
|
| 928 | 928 | name='cache_images' dojoType='dijit.form.CheckBox'> ".__('Cache media')."</label>"; |
| 929 | 929 | |
| 930 | - print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
|
| 930 | + print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
|
| 931 | 931 | |
| 932 | - print "</fieldset><fieldset class='narrow'>"; |
|
| 932 | + print "</fieldset><fieldset class='narrow'>"; |
|
| 933 | 933 | |
| 934 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='mark_unread_on_update' |
|
| 934 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='mark_unread_on_update' |
|
| 935 | 935 | name='mark_unread_on_update' dojoType='dijit.form.CheckBox'> ".__('Mark updated articles as unread')."</label>"; |
| 936 | 936 | |
| 937 | - print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); |
|
| 937 | + print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); |
|
| 938 | 938 | |
| 939 | - print "</fieldset>"; |
|
| 939 | + print "</fieldset>"; |
|
| 940 | 940 | |
| 941 | - print "</section>"; |
|
| 941 | + print "</section>"; |
|
| 942 | 942 | |
| 943 | - print "<footer> |
|
| 943 | + print "<footer> |
|
| 944 | 944 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary' |
| 945 | 945 | onclick=\"return dijit.byId('feedEditDlg').execute()\">". |
| 946 | - __('Save')."</button> |
|
| 946 | + __('Save')."</button> |
|
| 947 | 947 | <button dojoType='dijit.form.Button' |
| 948 | 948 | onclick=\"return dijit.byId('feedEditDlg').hide()\">". |
| 949 | - __('Cancel')."</button> |
|
| 949 | + __('Cancel')."</button> |
|
| 950 | 950 | </footer>"; |
| 951 | 951 | |
| 952 | - return; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - public function batchEditSave() { |
|
| 956 | - return $this->editsaveops(true); |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - public function editSave() { |
|
| 960 | - return $this->editsaveops(false); |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - public function editsaveops($batch) { |
|
| 964 | - |
|
| 965 | - $feed_title = trim(clean($_POST["title"])); |
|
| 966 | - $feed_url = trim(clean($_POST["feed_url"])); |
|
| 967 | - $site_url = trim(clean($_POST["site_url"])); |
|
| 968 | - $upd_intl = (int) clean($_POST["update_interval"]); |
|
| 969 | - $purge_intl = (int) clean($_POST["purge_interval"]); |
|
| 970 | - $feed_id = (int) clean($_POST["id"]); /* editSave */ |
|
| 971 | - $feed_ids = explode(",", clean($_POST["ids"])); /* batchEditSave */ |
|
| 972 | - $cat_id = (int) clean($_POST["cat_id"]); |
|
| 973 | - $auth_login = trim(clean($_POST["auth_login"])); |
|
| 974 | - $auth_pass = trim(clean($_POST["auth_pass"])); |
|
| 975 | - $private = checkbox_to_sql_bool(clean($_POST["private"])); |
|
| 976 | - $include_in_digest = checkbox_to_sql_bool( |
|
| 977 | - clean($_POST["include_in_digest"])); |
|
| 978 | - $cache_images = checkbox_to_sql_bool( |
|
| 979 | - clean($_POST["cache_images"])); |
|
| 980 | - $hide_images = checkbox_to_sql_bool( |
|
| 981 | - clean($_POST["hide_images"])); |
|
| 982 | - $always_display_enclosures = checkbox_to_sql_bool( |
|
| 983 | - clean($_POST["always_display_enclosures"])); |
|
| 984 | - |
|
| 985 | - $mark_unread_on_update = checkbox_to_sql_bool( |
|
| 986 | - clean($_POST["mark_unread_on_update"])); |
|
| 987 | - |
|
| 988 | - $feed_language = trim(clean($_POST["feed_language"])); |
|
| 989 | - |
|
| 990 | - if (!$batch) { |
|
| 991 | - if (clean($_POST["need_auth"]) !== 'on') { |
|
| 992 | - $auth_login = ''; |
|
| 993 | - $auth_pass = ''; |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); |
|
| 952 | + return; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + public function batchEditSave() { |
|
| 956 | + return $this->editsaveops(true); |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + public function editSave() { |
|
| 960 | + return $this->editsaveops(false); |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + public function editsaveops($batch) { |
|
| 964 | + |
|
| 965 | + $feed_title = trim(clean($_POST["title"])); |
|
| 966 | + $feed_url = trim(clean($_POST["feed_url"])); |
|
| 967 | + $site_url = trim(clean($_POST["site_url"])); |
|
| 968 | + $upd_intl = (int) clean($_POST["update_interval"]); |
|
| 969 | + $purge_intl = (int) clean($_POST["purge_interval"]); |
|
| 970 | + $feed_id = (int) clean($_POST["id"]); /* editSave */ |
|
| 971 | + $feed_ids = explode(",", clean($_POST["ids"])); /* batchEditSave */ |
|
| 972 | + $cat_id = (int) clean($_POST["cat_id"]); |
|
| 973 | + $auth_login = trim(clean($_POST["auth_login"])); |
|
| 974 | + $auth_pass = trim(clean($_POST["auth_pass"])); |
|
| 975 | + $private = checkbox_to_sql_bool(clean($_POST["private"])); |
|
| 976 | + $include_in_digest = checkbox_to_sql_bool( |
|
| 977 | + clean($_POST["include_in_digest"])); |
|
| 978 | + $cache_images = checkbox_to_sql_bool( |
|
| 979 | + clean($_POST["cache_images"])); |
|
| 980 | + $hide_images = checkbox_to_sql_bool( |
|
| 981 | + clean($_POST["hide_images"])); |
|
| 982 | + $always_display_enclosures = checkbox_to_sql_bool( |
|
| 983 | + clean($_POST["always_display_enclosures"])); |
|
| 984 | + |
|
| 985 | + $mark_unread_on_update = checkbox_to_sql_bool( |
|
| 986 | + clean($_POST["mark_unread_on_update"])); |
|
| 987 | + |
|
| 988 | + $feed_language = trim(clean($_POST["feed_language"])); |
|
| 989 | + |
|
| 990 | + if (!$batch) { |
|
| 991 | + if (clean($_POST["need_auth"]) !== 'on') { |
|
| 992 | + $auth_login = ''; |
|
| 993 | + $auth_pass = ''; |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); |
|
| 997 | 997 | $sth->execute([$feed_id]); |
| 998 | 998 | $row = $sth->fetch();$orig_feed_url = $row["feed_url"]; |
| 999 | 999 | |
| 1000 | 1000 | $reset_basic_info = $orig_feed_url != $feed_url; */ |
| 1001 | 1001 | |
| 1002 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET |
|
| 1002 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET |
|
| 1003 | 1003 | cat_id = :cat_id, |
| 1004 | 1004 | title = :title, |
| 1005 | 1005 | feed_url = :feed_url, |
@@ -1018,253 +1018,253 @@ discard block |
||
| 1018 | 1018 | feed_language = :feed_language |
| 1019 | 1019 | WHERE id = :id AND owner_uid = :uid"); |
| 1020 | 1020 | |
| 1021 | - $sth->execute([":title" => $feed_title, |
|
| 1022 | - ":cat_id" => $cat_id ? $cat_id : null, |
|
| 1023 | - ":feed_url" => $feed_url, |
|
| 1024 | - ":site_url" => $site_url, |
|
| 1025 | - ":upd_intl" => $upd_intl, |
|
| 1026 | - ":purge_intl" => $purge_intl, |
|
| 1027 | - ":auth_login" => $auth_login, |
|
| 1028 | - ":auth_pass" => $auth_pass, |
|
| 1029 | - ":private" => (int)$private, |
|
| 1030 | - ":cache_images" => (int)$cache_images, |
|
| 1031 | - ":hide_images" => (int)$hide_images, |
|
| 1032 | - ":include_in_digest" => (int)$include_in_digest, |
|
| 1033 | - ":always_display_enclosures" => (int)$always_display_enclosures, |
|
| 1034 | - ":mark_unread_on_update" => (int)$mark_unread_on_update, |
|
| 1035 | - ":feed_language" => $feed_language, |
|
| 1036 | - ":id" => $feed_id, |
|
| 1037 | - ":uid" => $_SESSION['uid']]); |
|
| 1021 | + $sth->execute([":title" => $feed_title, |
|
| 1022 | + ":cat_id" => $cat_id ? $cat_id : null, |
|
| 1023 | + ":feed_url" => $feed_url, |
|
| 1024 | + ":site_url" => $site_url, |
|
| 1025 | + ":upd_intl" => $upd_intl, |
|
| 1026 | + ":purge_intl" => $purge_intl, |
|
| 1027 | + ":auth_login" => $auth_login, |
|
| 1028 | + ":auth_pass" => $auth_pass, |
|
| 1029 | + ":private" => (int)$private, |
|
| 1030 | + ":cache_images" => (int)$cache_images, |
|
| 1031 | + ":hide_images" => (int)$hide_images, |
|
| 1032 | + ":include_in_digest" => (int)$include_in_digest, |
|
| 1033 | + ":always_display_enclosures" => (int)$always_display_enclosures, |
|
| 1034 | + ":mark_unread_on_update" => (int)$mark_unread_on_update, |
|
| 1035 | + ":feed_language" => $feed_language, |
|
| 1036 | + ":id" => $feed_id, |
|
| 1037 | + ":uid" => $_SESSION['uid']]); |
|
| 1038 | 1038 | |
| 1039 | 1039 | /* if ($reset_basic_info) { |
| 1040 | 1040 | RSSUtils::set_basic_feed_info($feed_id); |
| 1041 | 1041 | } */ |
| 1042 | 1042 | |
| 1043 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
|
| 1044 | - "hook_prefs_save_feed", $feed_id); |
|
| 1043 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
|
| 1044 | + "hook_prefs_save_feed", $feed_id); |
|
| 1045 | 1045 | |
| 1046 | - } else { |
|
| 1047 | - $feed_data = array(); |
|
| 1046 | + } else { |
|
| 1047 | + $feed_data = array(); |
|
| 1048 | 1048 | |
| 1049 | - foreach (array_keys($_POST) as $k) { |
|
| 1050 | - if ($k != "op" && $k != "method" && $k != "ids") { |
|
| 1051 | - $feed_data[$k] = clean($_POST[$k]); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1049 | + foreach (array_keys($_POST) as $k) { |
|
| 1050 | + if ($k != "op" && $k != "method" && $k != "ids") { |
|
| 1051 | + $feed_data[$k] = clean($_POST[$k]); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | 1054 | |
| 1055 | - $this->pdo->beginTransaction(); |
|
| 1055 | + $this->pdo->beginTransaction(); |
|
| 1056 | 1056 | |
| 1057 | - $feed_ids_qmarks = arr_qmarks($feed_ids); |
|
| 1057 | + $feed_ids_qmarks = arr_qmarks($feed_ids); |
|
| 1058 | 1058 | |
| 1059 | - foreach (array_keys($feed_data) as $k) { |
|
| 1059 | + foreach (array_keys($feed_data) as $k) { |
|
| 1060 | 1060 | |
| 1061 | - $qpart = ""; |
|
| 1061 | + $qpart = ""; |
|
| 1062 | 1062 | |
| 1063 | - switch ($k) { |
|
| 1064 | - case "title": |
|
| 1065 | - $qpart = "title = " . $this->pdo->quote($feed_title); |
|
| 1066 | - break; |
|
| 1063 | + switch ($k) { |
|
| 1064 | + case "title": |
|
| 1065 | + $qpart = "title = " . $this->pdo->quote($feed_title); |
|
| 1066 | + break; |
|
| 1067 | 1067 | |
| 1068 | - case "feed_url": |
|
| 1069 | - $qpart = "feed_url = " . $this->pdo->quote($feed_url); |
|
| 1070 | - break; |
|
| 1068 | + case "feed_url": |
|
| 1069 | + $qpart = "feed_url = " . $this->pdo->quote($feed_url); |
|
| 1070 | + break; |
|
| 1071 | 1071 | |
| 1072 | - case "update_interval": |
|
| 1073 | - $qpart = "update_interval = " . $this->pdo->quote($upd_intl); |
|
| 1074 | - break; |
|
| 1072 | + case "update_interval": |
|
| 1073 | + $qpart = "update_interval = " . $this->pdo->quote($upd_intl); |
|
| 1074 | + break; |
|
| 1075 | 1075 | |
| 1076 | - case "purge_interval": |
|
| 1077 | - $qpart = "purge_interval =" . $this->pdo->quote($purge_intl); |
|
| 1078 | - break; |
|
| 1076 | + case "purge_interval": |
|
| 1077 | + $qpart = "purge_interval =" . $this->pdo->quote($purge_intl); |
|
| 1078 | + break; |
|
| 1079 | 1079 | |
| 1080 | - case "auth_login": |
|
| 1081 | - $qpart = "auth_login = " . $this->pdo->quote($auth_login); |
|
| 1082 | - break; |
|
| 1080 | + case "auth_login": |
|
| 1081 | + $qpart = "auth_login = " . $this->pdo->quote($auth_login); |
|
| 1082 | + break; |
|
| 1083 | 1083 | |
| 1084 | - case "auth_pass": |
|
| 1085 | - $qpart = "auth_pass =" . $this->pdo->quote($auth_pass). ", auth_pass_encrypted = false"; |
|
| 1086 | - break; |
|
| 1084 | + case "auth_pass": |
|
| 1085 | + $qpart = "auth_pass =" . $this->pdo->quote($auth_pass). ", auth_pass_encrypted = false"; |
|
| 1086 | + break; |
|
| 1087 | 1087 | |
| 1088 | - case "private": |
|
| 1089 | - $qpart = "private = " . $this->pdo->quote($private); |
|
| 1090 | - break; |
|
| 1088 | + case "private": |
|
| 1089 | + $qpart = "private = " . $this->pdo->quote($private); |
|
| 1090 | + break; |
|
| 1091 | 1091 | |
| 1092 | - case "include_in_digest": |
|
| 1093 | - $qpart = "include_in_digest = " . $this->pdo->quote($include_in_digest); |
|
| 1094 | - break; |
|
| 1092 | + case "include_in_digest": |
|
| 1093 | + $qpart = "include_in_digest = " . $this->pdo->quote($include_in_digest); |
|
| 1094 | + break; |
|
| 1095 | 1095 | |
| 1096 | - case "always_display_enclosures": |
|
| 1097 | - $qpart = "always_display_enclosures = " . $this->pdo->quote($always_display_enclosures); |
|
| 1098 | - break; |
|
| 1096 | + case "always_display_enclosures": |
|
| 1097 | + $qpart = "always_display_enclosures = " . $this->pdo->quote($always_display_enclosures); |
|
| 1098 | + break; |
|
| 1099 | 1099 | |
| 1100 | - case "mark_unread_on_update": |
|
| 1101 | - $qpart = "mark_unread_on_update = " . $this->pdo->quote($mark_unread_on_update); |
|
| 1102 | - break; |
|
| 1100 | + case "mark_unread_on_update": |
|
| 1101 | + $qpart = "mark_unread_on_update = " . $this->pdo->quote($mark_unread_on_update); |
|
| 1102 | + break; |
|
| 1103 | 1103 | |
| 1104 | - case "cache_images": |
|
| 1105 | - $qpart = "cache_images = " . $this->pdo->quote($cache_images); |
|
| 1106 | - break; |
|
| 1104 | + case "cache_images": |
|
| 1105 | + $qpart = "cache_images = " . $this->pdo->quote($cache_images); |
|
| 1106 | + break; |
|
| 1107 | 1107 | |
| 1108 | - case "hide_images": |
|
| 1109 | - $qpart = "hide_images = " . $this->pdo->quote($hide_images); |
|
| 1110 | - break; |
|
| 1108 | + case "hide_images": |
|
| 1109 | + $qpart = "hide_images = " . $this->pdo->quote($hide_images); |
|
| 1110 | + break; |
|
| 1111 | 1111 | |
| 1112 | - case "cat_id": |
|
| 1113 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1114 | - if ($cat_id) { |
|
| 1115 | - $qpart = "cat_id = " . $this->pdo->quote($cat_id); |
|
| 1116 | - } else { |
|
| 1117 | - $qpart = 'cat_id = NULL'; |
|
| 1118 | - } |
|
| 1119 | - } else { |
|
| 1120 | - $qpart = ""; |
|
| 1121 | - } |
|
| 1112 | + case "cat_id": |
|
| 1113 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1114 | + if ($cat_id) { |
|
| 1115 | + $qpart = "cat_id = " . $this->pdo->quote($cat_id); |
|
| 1116 | + } else { |
|
| 1117 | + $qpart = 'cat_id = NULL'; |
|
| 1118 | + } |
|
| 1119 | + } else { |
|
| 1120 | + $qpart = ""; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - break; |
|
| 1123 | + break; |
|
| 1124 | 1124 | |
| 1125 | - case "feed_language": |
|
| 1126 | - $qpart = "feed_language = " . $this->pdo->quote($feed_language); |
|
| 1127 | - break; |
|
| 1125 | + case "feed_language": |
|
| 1126 | + $qpart = "feed_language = " . $this->pdo->quote($feed_language); |
|
| 1127 | + break; |
|
| 1128 | 1128 | |
| 1129 | - } |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - if ($qpart) { |
|
| 1132 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks) |
|
| 1131 | + if ($qpart) { |
|
| 1132 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks) |
|
| 1133 | 1133 | AND owner_uid = ?"); |
| 1134 | - $sth->execute(array_merge($feed_ids, [$_SESSION['uid']])); |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1134 | + $sth->execute(array_merge($feed_ids, [$_SESSION['uid']])); |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - $this->pdo->commit(); |
|
| 1139 | - } |
|
| 1140 | - return; |
|
| 1141 | - } |
|
| 1138 | + $this->pdo->commit(); |
|
| 1139 | + } |
|
| 1140 | + return; |
|
| 1141 | + } |
|
| 1142 | 1142 | |
| 1143 | - public function remove() { |
|
| 1143 | + public function remove() { |
|
| 1144 | 1144 | |
| 1145 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 1145 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 1146 | 1146 | |
| 1147 | - foreach ($ids as $id) { |
|
| 1148 | - Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
|
| 1149 | - } |
|
| 1147 | + foreach ($ids as $id) { |
|
| 1148 | + Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | - return; |
|
| 1152 | - } |
|
| 1151 | + return; |
|
| 1152 | + } |
|
| 1153 | 1153 | |
| 1154 | - public function removeCat() { |
|
| 1155 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 1156 | - foreach ($ids as $id) { |
|
| 1157 | - $this->remove_feed_category($id, $_SESSION["uid"]); |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1154 | + public function removeCat() { |
|
| 1155 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 1156 | + foreach ($ids as $id) { |
|
| 1157 | + $this->remove_feed_category($id, $_SESSION["uid"]); |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | 1160 | |
| 1161 | - public function addCat() { |
|
| 1162 | - $feed_cat = trim(clean($_REQUEST["cat"])); |
|
| 1161 | + public function addCat() { |
|
| 1162 | + $feed_cat = trim(clean($_REQUEST["cat"])); |
|
| 1163 | 1163 | |
| 1164 | - Feeds::add_feed_category($feed_cat); |
|
| 1165 | - } |
|
| 1164 | + Feeds::add_feed_category($feed_cat); |
|
| 1165 | + } |
|
| 1166 | 1166 | |
| 1167 | - public function index() { |
|
| 1167 | + public function index() { |
|
| 1168 | 1168 | |
| 1169 | - print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
| 1170 | - print "<div style='padding : 0px' dojoType='dijit.layout.AccordionPane' |
|
| 1169 | + print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
| 1170 | + print "<div style='padding : 0px' dojoType='dijit.layout.AccordionPane' |
|
| 1171 | 1171 | title=\"<i class='material-icons'>rss_feed</i> ".__('Feeds')."\">"; |
| 1172 | 1172 | |
| 1173 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
| 1173 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
| 1174 | 1174 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
| 1175 | - $sth->execute([$_SESSION['uid']]); |
|
| 1175 | + $sth->execute([$_SESSION['uid']]); |
|
| 1176 | 1176 | |
| 1177 | - if ($row = $sth->fetch()) { |
|
| 1178 | - $num_errors = $row["num_errors"]; |
|
| 1179 | - } else { |
|
| 1180 | - $num_errors = 0; |
|
| 1181 | - } |
|
| 1177 | + if ($row = $sth->fetch()) { |
|
| 1178 | + $num_errors = $row["num_errors"]; |
|
| 1179 | + } else { |
|
| 1180 | + $num_errors = 0; |
|
| 1181 | + } |
|
| 1182 | 1182 | |
| 1183 | - if ($num_errors > 0) { |
|
| 1183 | + if ($num_errors > 0) { |
|
| 1184 | 1184 | |
| 1185 | - $error_button = "<button dojoType=\"dijit.form.Button\" |
|
| 1185 | + $error_button = "<button dojoType=\"dijit.form.Button\" |
|
| 1186 | 1186 | onclick=\"CommonDialogs.showFeedsWithErrors()\" id=\"errorButton\">" . |
| 1187 | - __("Feeds with errors") . "</button>"; |
|
| 1188 | - } |
|
| 1187 | + __("Feeds with errors") . "</button>"; |
|
| 1188 | + } |
|
| 1189 | 1189 | |
| 1190 | - $inactive_button = "<button dojoType=\"dijit.form.Button\" |
|
| 1190 | + $inactive_button = "<button dojoType=\"dijit.form.Button\" |
|
| 1191 | 1191 | id=\"pref_feeds_inactive_btn\" |
| 1192 | 1192 | style=\"display : none\" |
| 1193 | 1193 | onclick=\"dijit.byId('feedTree').showInactiveFeeds()\">" . |
| 1194 | - __("Inactive feeds") . "</button>"; |
|
| 1194 | + __("Inactive feeds") . "</button>"; |
|
| 1195 | 1195 | |
| 1196 | - $feed_search = clean($_REQUEST["search"]); |
|
| 1196 | + $feed_search = clean($_REQUEST["search"]); |
|
| 1197 | 1197 | |
| 1198 | - if (array_key_exists("search", $_REQUEST)) { |
|
| 1199 | - $_SESSION["prefs_feed_search"] = $feed_search; |
|
| 1200 | - } else { |
|
| 1201 | - $feed_search = $_SESSION["prefs_feed_search"]; |
|
| 1202 | - } |
|
| 1198 | + if (array_key_exists("search", $_REQUEST)) { |
|
| 1199 | + $_SESSION["prefs_feed_search"] = $feed_search; |
|
| 1200 | + } else { |
|
| 1201 | + $feed_search = $_SESSION["prefs_feed_search"]; |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | - print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
| 1204 | + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
| 1205 | 1205 | |
| 1206 | - print "<div region='top' dojoType=\"fox.Toolbar\">"; #toolbar |
|
| 1206 | + print "<div region='top' dojoType=\"fox.Toolbar\">"; #toolbar |
|
| 1207 | 1207 | |
| 1208 | - print "<div style='float : right; padding-right : 4px;'> |
|
| 1208 | + print "<div style='float : right; padding-right : 4px;'> |
|
| 1209 | 1209 | <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" |
| 1210 | 1210 | value=\"$feed_search\"> |
| 1211 | 1211 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedTree').reload()\">". |
| 1212 | - __('Search')."</button> |
|
| 1212 | + __('Search')."</button> |
|
| 1213 | 1213 | </div>"; |
| 1214 | 1214 | |
| 1215 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1216 | - "<span>" . __('Select')."</span>"; |
|
| 1217 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1218 | - print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" |
|
| 1215 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1216 | + "<span>" . __('Select')."</span>"; |
|
| 1217 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1218 | + print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" |
|
| 1219 | 1219 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
| 1220 | - print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" |
|
| 1220 | + print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" |
|
| 1221 | 1221 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
| 1222 | - print "</div></div>"; |
|
| 1222 | + print "</div></div>"; |
|
| 1223 | 1223 | |
| 1224 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1225 | - "<span>" . __('Feeds')."</span>"; |
|
| 1226 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1227 | - print "<div onclick=\"CommonDialogs.quickAddFeed()\" |
|
| 1224 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1225 | + "<span>" . __('Feeds')."</span>"; |
|
| 1226 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1227 | + print "<div onclick=\"CommonDialogs.quickAddFeed()\" |
|
| 1228 | 1228 | dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; |
| 1229 | - print "<div onclick=\"dijit.byId('feedTree').editSelectedFeed()\" |
|
| 1229 | + print "<div onclick=\"dijit.byId('feedTree').editSelectedFeed()\" |
|
| 1230 | 1230 | dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; |
| 1231 | - print "<div onclick=\"dijit.byId('feedTree').resetFeedOrder()\" |
|
| 1231 | + print "<div onclick=\"dijit.byId('feedTree').resetFeedOrder()\" |
|
| 1232 | 1232 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; |
| 1233 | - print "<div onclick=\"dijit.byId('feedTree').batchSubscribe()\" |
|
| 1233 | + print "<div onclick=\"dijit.byId('feedTree').batchSubscribe()\" |
|
| 1234 | 1234 | dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>"; |
| 1235 | - print "<div dojoType=\"dijit.MenuItem\" onclick=\"dijit.byId('feedTree').removeSelectedFeeds()\">" |
|
| 1236 | - .__('Unsubscribe')."</div> "; |
|
| 1237 | - print "</div></div>"; |
|
| 1238 | - |
|
| 1239 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1240 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1241 | - "<span>" . __('Categories')."</span>"; |
|
| 1242 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1243 | - print "<div onclick=\"dijit.byId('feedTree').createCategory()\" |
|
| 1235 | + print "<div dojoType=\"dijit.MenuItem\" onclick=\"dijit.byId('feedTree').removeSelectedFeeds()\">" |
|
| 1236 | + .__('Unsubscribe')."</div> "; |
|
| 1237 | + print "</div></div>"; |
|
| 1238 | + |
|
| 1239 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1240 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1241 | + "<span>" . __('Categories')."</span>"; |
|
| 1242 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1243 | + print "<div onclick=\"dijit.byId('feedTree').createCategory()\" |
|
| 1244 | 1244 | dojoType=\"dijit.MenuItem\">".__('Add category')."</div>"; |
| 1245 | - print "<div onclick=\"dijit.byId('feedTree').resetCatOrder()\" |
|
| 1245 | + print "<div onclick=\"dijit.byId('feedTree').resetCatOrder()\" |
|
| 1246 | 1246 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; |
| 1247 | - print "<div onclick=\"dijit.byId('feedTree').removeSelectedCategories()\" |
|
| 1247 | + print "<div onclick=\"dijit.byId('feedTree').removeSelectedCategories()\" |
|
| 1248 | 1248 | dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>"; |
| 1249 | - print "</div></div>"; |
|
| 1249 | + print "</div></div>"; |
|
| 1250 | 1250 | |
| 1251 | - } |
|
| 1251 | + } |
|
| 1252 | 1252 | |
| 1253 | - print $error_button; |
|
| 1254 | - print $inactive_button; |
|
| 1253 | + print $error_button; |
|
| 1254 | + print $inactive_button; |
|
| 1255 | 1255 | |
| 1256 | - print "</div>"; # toolbar |
|
| 1256 | + print "</div>"; # toolbar |
|
| 1257 | 1257 | |
| 1258 | - //print '</div>'; |
|
| 1259 | - print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">'; |
|
| 1258 | + //print '</div>'; |
|
| 1259 | + print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">'; |
|
| 1260 | 1260 | |
| 1261 | - print "<div id=\"feedlistLoading\"> |
|
| 1261 | + print "<div id=\"feedlistLoading\"> |
|
| 1262 | 1262 | <img src='images/indicator_tiny.gif'>". |
| 1263 | - __("Loading, please wait...")."</div>"; |
|
| 1263 | + __("Loading, please wait...")."</div>"; |
|
| 1264 | 1264 | |
| 1265 | - $auto_expand = $feed_search != "" ? "true" : "false"; |
|
| 1265 | + $auto_expand = $feed_search != "" ? "true" : "false"; |
|
| 1266 | 1266 | |
| 1267 | - print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" |
|
| 1267 | + print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" |
|
| 1268 | 1268 | url=\"backend.php?op=pref-feeds&method=getfeedtree\"> |
| 1269 | 1269 | </div> |
| 1270 | 1270 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" |
@@ -1297,23 +1297,23 @@ discard block |
||
| 1297 | 1297 | # ".__('<b>Hint:</b> you can drag feeds and categories around.')." |
| 1298 | 1298 | # </div>"; |
| 1299 | 1299 | |
| 1300 | - print '</div>'; |
|
| 1301 | - print '</div>'; |
|
| 1300 | + print '</div>'; |
|
| 1301 | + print '</div>'; |
|
| 1302 | 1302 | |
| 1303 | - print "</div>"; # feeds pane |
|
| 1303 | + print "</div>"; # feeds pane |
|
| 1304 | 1304 | |
| 1305 | - print "<div dojoType='dijit.layout.AccordionPane' |
|
| 1305 | + print "<div dojoType='dijit.layout.AccordionPane' |
|
| 1306 | 1306 | title='<i class=\"material-icons\">import_export</i> ".__('OPML')."'>"; |
| 1307 | 1307 | |
| 1308 | - print "<h3>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . "</h3>"; |
|
| 1308 | + print "<h3>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . "</h3>"; |
|
| 1309 | 1309 | |
| 1310 | - print_notice("Only main settings profile can be migrated using OPML."); |
|
| 1310 | + print_notice("Only main settings profile can be migrated using OPML."); |
|
| 1311 | 1311 | |
| 1312 | - print "<iframe id=\"upload_iframe\" |
|
| 1312 | + print "<iframe id=\"upload_iframe\" |
|
| 1313 | 1313 | name=\"upload_iframe\" onload=\"Helpers.OPML.onImportComplete(this)\" |
| 1314 | 1314 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; |
| 1315 | 1315 | |
| 1316 | - print "<form name='opml_form' style='display : inline-block' target='upload_iframe' |
|
| 1316 | + print "<form name='opml_form' style='display : inline-block' target='upload_iframe' |
|
| 1317 | 1317 | enctype='multipart/form-data' method='POST' |
| 1318 | 1318 | action='backend.php'> |
| 1319 | 1319 | <label class='dijitButton'>".__("Choose file...")." |
@@ -1322,116 +1322,116 @@ discard block |
||
| 1322 | 1322 | <input type='hidden' name='op' value='dlg'> |
| 1323 | 1323 | <input type='hidden' name='method' value='importOpml'> |
| 1324 | 1324 | <button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return Helpers.OPML.import();\" type=\"submit\">" . |
| 1325 | - __('Import OPML') . "</button>"; |
|
| 1325 | + __('Import OPML') . "</button>"; |
|
| 1326 | 1326 | |
| 1327 | - print "</form>"; |
|
| 1327 | + print "</form>"; |
|
| 1328 | 1328 | |
| 1329 | - print "<form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>"; |
|
| 1329 | + print "<form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>"; |
|
| 1330 | 1330 | |
| 1331 | - print "<button dojoType='dijit.form.Button' |
|
| 1331 | + print "<button dojoType='dijit.form.Button' |
|
| 1332 | 1332 | onclick='Helpers.OPML.export()' >" . |
| 1333 | - __('Export OPML') . "</button>"; |
|
| 1333 | + __('Export OPML') . "</button>"; |
|
| 1334 | 1334 | |
| 1335 | - print " <label class='checkbox'>"; |
|
| 1336 | - print_checkbox("include_settings", true, "1", ""); |
|
| 1337 | - print " " . __("Include settings"); |
|
| 1338 | - print "</label>"; |
|
| 1335 | + print " <label class='checkbox'>"; |
|
| 1336 | + print_checkbox("include_settings", true, "1", ""); |
|
| 1337 | + print " " . __("Include settings"); |
|
| 1338 | + print "</label>"; |
|
| 1339 | 1339 | |
| 1340 | - print "</form>"; |
|
| 1340 | + print "</form>"; |
|
| 1341 | 1341 | |
| 1342 | - print "<p/>"; |
|
| 1342 | + print "<p/>"; |
|
| 1343 | 1343 | |
| 1344 | - print "<h2>" . __("Published OPML") . "</h2>"; |
|
| 1344 | + print "<h2>" . __("Published OPML") . "</h2>"; |
|
| 1345 | 1345 | |
| 1346 | - print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . |
|
| 1347 | - " " . |
|
| 1348 | - __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>"; |
|
| 1346 | + print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . |
|
| 1347 | + " " . |
|
| 1348 | + __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>"; |
|
| 1349 | 1349 | |
| 1350 | - print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
|
| 1351 | - __('Display published OPML URL')."</button> "; |
|
| 1350 | + print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
|
| 1351 | + __('Display published OPML URL')."</button> "; |
|
| 1352 | 1352 | |
| 1353 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 1354 | - "hook_prefs_tab_section", "prefFeedsOPML"); |
|
| 1353 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 1354 | + "hook_prefs_tab_section", "prefFeedsOPML"); |
|
| 1355 | 1355 | |
| 1356 | - print "</div>"; # pane |
|
| 1356 | + print "</div>"; # pane |
|
| 1357 | 1357 | |
| 1358 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
| 1358 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
| 1359 | 1359 | title=\"<i class='material-icons'>share</i> ".__('Published & shared articles / Generated feeds')."\">"; |
| 1360 | 1360 | |
| 1361 | - print "<h3>" . __('Published articles can be subscribed by anyone who knows the following URL:') . "</h3>"; |
|
| 1361 | + print "<h3>" . __('Published articles can be subscribed by anyone who knows the following URL:') . "</h3>"; |
|
| 1362 | 1362 | |
| 1363 | - $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . |
|
| 1364 | - "/public.php?op=rss&id=-2&view-mode=all_articles");; |
|
| 1363 | + $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . |
|
| 1364 | + "/public.php?op=rss&id=-2&view-mode=all_articles");; |
|
| 1365 | 1365 | |
| 1366 | - print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Show as feed")."','generatedFeed', '$rss_url')\">". |
|
| 1367 | - __('Display URL')."</button> "; |
|
| 1366 | + print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Show as feed")."','generatedFeed', '$rss_url')\">". |
|
| 1367 | + __('Display URL')."</button> "; |
|
| 1368 | 1368 | |
| 1369 | - print "<button class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Helpers.clearFeedAccessKeys()\">". |
|
| 1370 | - __('Clear all generated URLs')."</button> "; |
|
| 1369 | + print "<button class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Helpers.clearFeedAccessKeys()\">". |
|
| 1370 | + __('Clear all generated URLs')."</button> "; |
|
| 1371 | 1371 | |
| 1372 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 1373 | - "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
|
| 1372 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
| 1373 | + "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
|
| 1374 | 1374 | |
| 1375 | - print "</div>"; #pane |
|
| 1375 | + print "</div>"; #pane |
|
| 1376 | 1376 | |
| 1377 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
| 1378 | - "hook_prefs_tab", "prefFeeds"); |
|
| 1377 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
| 1378 | + "hook_prefs_tab", "prefFeeds"); |
|
| 1379 | 1379 | |
| 1380 | - print "</div>"; #container |
|
| 1381 | - } |
|
| 1380 | + print "</div>"; #container |
|
| 1381 | + } |
|
| 1382 | 1382 | |
| 1383 | - private function feedlist_init_cat($cat_id) { |
|
| 1384 | - $obj = array(); |
|
| 1385 | - $cat_id = (int) $cat_id; |
|
| 1383 | + private function feedlist_init_cat($cat_id) { |
|
| 1384 | + $obj = array(); |
|
| 1385 | + $cat_id = (int) $cat_id; |
|
| 1386 | 1386 | |
| 1387 | - if ($cat_id > 0) { |
|
| 1388 | - $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); |
|
| 1389 | - } else if ($cat_id == 0 || $cat_id == -2) { |
|
| 1390 | - $cat_unread = Feeds::getCategoryUnread($cat_id); |
|
| 1391 | - } |
|
| 1387 | + if ($cat_id > 0) { |
|
| 1388 | + $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); |
|
| 1389 | + } else if ($cat_id == 0 || $cat_id == -2) { |
|
| 1390 | + $cat_unread = Feeds::getCategoryUnread($cat_id); |
|
| 1391 | + } |
|
| 1392 | 1392 | |
| 1393 | - $obj['id'] = 'CAT:' . $cat_id; |
|
| 1394 | - $obj['items'] = array(); |
|
| 1395 | - $obj['name'] = Feeds::getCategoryTitle($cat_id); |
|
| 1396 | - $obj['type'] = 'category'; |
|
| 1397 | - $obj['unread'] = (int) $cat_unread; |
|
| 1398 | - $obj['bare_id'] = $cat_id; |
|
| 1393 | + $obj['id'] = 'CAT:' . $cat_id; |
|
| 1394 | + $obj['items'] = array(); |
|
| 1395 | + $obj['name'] = Feeds::getCategoryTitle($cat_id); |
|
| 1396 | + $obj['type'] = 'category'; |
|
| 1397 | + $obj['unread'] = (int) $cat_unread; |
|
| 1398 | + $obj['bare_id'] = $cat_id; |
|
| 1399 | 1399 | |
| 1400 | - return $obj; |
|
| 1401 | - } |
|
| 1400 | + return $obj; |
|
| 1401 | + } |
|
| 1402 | 1402 | |
| 1403 | - private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { |
|
| 1404 | - $obj = array(); |
|
| 1405 | - $feed_id = (int) $feed_id; |
|
| 1403 | + private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { |
|
| 1404 | + $obj = array(); |
|
| 1405 | + $feed_id = (int) $feed_id; |
|
| 1406 | 1406 | |
| 1407 | - if (!$title) |
|
| 1408 | - $title = Feeds::getFeedTitle($feed_id, false); |
|
| 1407 | + if (!$title) |
|
| 1408 | + $title = Feeds::getFeedTitle($feed_id, false); |
|
| 1409 | 1409 | |
| 1410 | - if ($unread === false) |
|
| 1411 | - $unread = getFeedUnread($feed_id, false); |
|
| 1410 | + if ($unread === false) |
|
| 1411 | + $unread = getFeedUnread($feed_id, false); |
|
| 1412 | 1412 | |
| 1413 | - $obj['id'] = 'FEED:' . $feed_id; |
|
| 1414 | - $obj['name'] = $title; |
|
| 1415 | - $obj['unread'] = (int) $unread; |
|
| 1416 | - $obj['type'] = 'feed'; |
|
| 1417 | - $obj['error'] = $error; |
|
| 1418 | - $obj['updated'] = $updated; |
|
| 1419 | - $obj['icon'] = Feeds::getFeedIcon($feed_id); |
|
| 1420 | - $obj['bare_id'] = $feed_id; |
|
| 1421 | - $obj['auxcounter'] = 0; |
|
| 1413 | + $obj['id'] = 'FEED:' . $feed_id; |
|
| 1414 | + $obj['name'] = $title; |
|
| 1415 | + $obj['unread'] = (int) $unread; |
|
| 1416 | + $obj['type'] = 'feed'; |
|
| 1417 | + $obj['error'] = $error; |
|
| 1418 | + $obj['updated'] = $updated; |
|
| 1419 | + $obj['icon'] = Feeds::getFeedIcon($feed_id); |
|
| 1420 | + $obj['bare_id'] = $feed_id; |
|
| 1421 | + $obj['auxcounter'] = 0; |
|
| 1422 | 1422 | |
| 1423 | - return $obj; |
|
| 1424 | - } |
|
| 1423 | + return $obj; |
|
| 1424 | + } |
|
| 1425 | 1425 | |
| 1426 | - public function inactiveFeeds() { |
|
| 1426 | + public function inactiveFeeds() { |
|
| 1427 | 1427 | |
| 1428 | - if (DB_TYPE == "pgsql") { |
|
| 1429 | - $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
| 1430 | - } else { |
|
| 1431 | - $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
| 1432 | - } |
|
| 1428 | + if (DB_TYPE == "pgsql") { |
|
| 1429 | + $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
| 1430 | + } else { |
|
| 1431 | + $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
| 1432 | + } |
|
| 1433 | 1433 | |
| 1434 | - $sth = $this->pdo->prepare("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
|
| 1434 | + $sth = $this->pdo->prepare("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
|
| 1435 | 1435 | ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article |
| 1436 | 1436 | FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE |
| 1437 | 1437 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE |
@@ -1442,356 +1442,356 @@ discard block |
||
| 1442 | 1442 | ttrss_entries.id = ref_id |
| 1443 | 1443 | GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url |
| 1444 | 1444 | ORDER BY last_article"); |
| 1445 | - $sth->execute([$_SESSION['uid']]); |
|
| 1445 | + $sth->execute([$_SESSION['uid']]); |
|
| 1446 | 1446 | |
| 1447 | - print "<div dojoType='fox.Toolbar'>"; |
|
| 1448 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
| 1449 | - "<span>" . __('Select')."</span>"; |
|
| 1450 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
| 1451 | - print "<div onclick=\"Tables.select('inactive-feeds-list', true)\" |
|
| 1447 | + print "<div dojoType='fox.Toolbar'>"; |
|
| 1448 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
| 1449 | + "<span>" . __('Select')."</span>"; |
|
| 1450 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
| 1451 | + print "<div onclick=\"Tables.select('inactive-feeds-list', true)\" |
|
| 1452 | 1452 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
| 1453 | - print "<div onclick=\"Tables.select('inactive-feeds-list', false)\" |
|
| 1453 | + print "<div onclick=\"Tables.select('inactive-feeds-list', false)\" |
|
| 1454 | 1454 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
| 1455 | - print "</div></div>"; |
|
| 1456 | - print "</div>"; #toolbar |
|
| 1455 | + print "</div></div>"; |
|
| 1456 | + print "</div>"; #toolbar |
|
| 1457 | 1457 | |
| 1458 | - print "<div class='panel panel-scrollable'>"; |
|
| 1459 | - print "<table width='100%' id='inactive-feeds-list'>"; |
|
| 1458 | + print "<div class='panel panel-scrollable'>"; |
|
| 1459 | + print "<table width='100%' id='inactive-feeds-list'>"; |
|
| 1460 | 1460 | |
| 1461 | - $lnum = 1; |
|
| 1461 | + $lnum = 1; |
|
| 1462 | 1462 | |
| 1463 | - while ($line = $sth->fetch()) { |
|
| 1463 | + while ($line = $sth->fetch()) { |
|
| 1464 | 1464 | |
| 1465 | - $feed_id = $line["id"]; |
|
| 1465 | + $feed_id = $line["id"]; |
|
| 1466 | 1466 | |
| 1467 | - print "<tr data-row-id='$feed_id'>"; |
|
| 1467 | + print "<tr data-row-id='$feed_id'>"; |
|
| 1468 | 1468 | |
| 1469 | - print "<td width='5%' align='center'><input |
|
| 1469 | + print "<td width='5%' align='center'><input |
|
| 1470 | 1470 | onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' |
| 1471 | 1471 | type='checkbox'></td>"; |
| 1472 | - print "<td>"; |
|
| 1472 | + print "<td>"; |
|
| 1473 | 1473 | |
| 1474 | - print "<a href='#' ". |
|
| 1475 | - "title=\"".__("Click to edit feed")."\" ". |
|
| 1476 | - "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
| 1477 | - htmlspecialchars($line["title"])."</a>"; |
|
| 1474 | + print "<a href='#' ". |
|
| 1475 | + "title=\"".__("Click to edit feed")."\" ". |
|
| 1476 | + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
| 1477 | + htmlspecialchars($line["title"])."</a>"; |
|
| 1478 | 1478 | |
| 1479 | - print "</td><td class='text-muted' align='right'>"; |
|
| 1480 | - print make_local_datetime($line['last_article'], false); |
|
| 1481 | - print "</td>"; |
|
| 1482 | - print "</tr>"; |
|
| 1479 | + print "</td><td class='text-muted' align='right'>"; |
|
| 1480 | + print make_local_datetime($line['last_article'], false); |
|
| 1481 | + print "</td>"; |
|
| 1482 | + print "</tr>"; |
|
| 1483 | 1483 | |
| 1484 | - ++$lnum; |
|
| 1485 | - } |
|
| 1484 | + ++$lnum; |
|
| 1485 | + } |
|
| 1486 | 1486 | |
| 1487 | - print "</table>"; |
|
| 1488 | - print "</div>"; |
|
| 1487 | + print "</table>"; |
|
| 1488 | + print "</div>"; |
|
| 1489 | 1489 | |
| 1490 | - print "<footer> |
|
| 1490 | + print "<footer> |
|
| 1491 | 1491 | <button style='float : left' class=\"alt-danger\" dojoType='dijit.form.Button' onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" |
| 1492 | - .__('Unsubscribe from selected feeds')."</button> |
|
| 1492 | + .__('Unsubscribe from selected feeds')."</button> |
|
| 1493 | 1493 | <button dojoType='dijit.form.Button' onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">" |
| 1494 | - .__('Close this window')."</button> |
|
| 1494 | + .__('Close this window')."</button> |
|
| 1495 | 1495 | </footer>"; |
| 1496 | 1496 | |
| 1497 | - } |
|
| 1497 | + } |
|
| 1498 | 1498 | |
| 1499 | - public function feedsWithErrors() { |
|
| 1500 | - $sth = $this->pdo->prepare("SELECT id,title,feed_url,last_error,site_url |
|
| 1499 | + public function feedsWithErrors() { |
|
| 1500 | + $sth = $this->pdo->prepare("SELECT id,title,feed_url,last_error,site_url |
|
| 1501 | 1501 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
| 1502 | - $sth->execute([$_SESSION['uid']]); |
|
| 1502 | + $sth->execute([$_SESSION['uid']]); |
|
| 1503 | 1503 | |
| 1504 | - print "<div dojoType=\"fox.Toolbar\">"; |
|
| 1505 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1506 | - "<span>" . __('Select')."</span>"; |
|
| 1507 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1508 | - print "<div onclick=\"Tables.select('error-feeds-list', true)\" |
|
| 1504 | + print "<div dojoType=\"fox.Toolbar\">"; |
|
| 1505 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
| 1506 | + "<span>" . __('Select')."</span>"; |
|
| 1507 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 1508 | + print "<div onclick=\"Tables.select('error-feeds-list', true)\" |
|
| 1509 | 1509 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
| 1510 | - print "<div onclick=\"Tables.select('error-feeds-list', false)\" |
|
| 1510 | + print "<div onclick=\"Tables.select('error-feeds-list', false)\" |
|
| 1511 | 1511 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
| 1512 | - print "</div></div>"; |
|
| 1513 | - print "</div>"; #toolbar |
|
| 1512 | + print "</div></div>"; |
|
| 1513 | + print "</div>"; #toolbar |
|
| 1514 | 1514 | |
| 1515 | - print "<div class='panel panel-scrollable'>"; |
|
| 1516 | - print "<table width='100%' id='error-feeds-list'>"; |
|
| 1515 | + print "<div class='panel panel-scrollable'>"; |
|
| 1516 | + print "<table width='100%' id='error-feeds-list'>"; |
|
| 1517 | 1517 | |
| 1518 | - $lnum = 1; |
|
| 1518 | + $lnum = 1; |
|
| 1519 | 1519 | |
| 1520 | - while ($line = $sth->fetch()) { |
|
| 1520 | + while ($line = $sth->fetch()) { |
|
| 1521 | 1521 | |
| 1522 | - $feed_id = $line["id"]; |
|
| 1522 | + $feed_id = $line["id"]; |
|
| 1523 | 1523 | |
| 1524 | - print "<tr data-row-id='$feed_id'>"; |
|
| 1524 | + print "<tr data-row-id='$feed_id'>"; |
|
| 1525 | 1525 | |
| 1526 | - print "<td width='5%' align='center'><input |
|
| 1526 | + print "<td width='5%' align='center'><input |
|
| 1527 | 1527 | onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\" |
| 1528 | 1528 | type=\"checkbox\"></td>"; |
| 1529 | - print "<td>"; |
|
| 1529 | + print "<td>"; |
|
| 1530 | 1530 | |
| 1531 | - print "<a class=\"visibleLink\" href=\"#\" ". |
|
| 1532 | - "title=\"".__("Click to edit feed")."\" ". |
|
| 1533 | - "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
| 1534 | - htmlspecialchars($line["title"])."</a>: "; |
|
| 1531 | + print "<a class=\"visibleLink\" href=\"#\" ". |
|
| 1532 | + "title=\"".__("Click to edit feed")."\" ". |
|
| 1533 | + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
| 1534 | + htmlspecialchars($line["title"])."</a>: "; |
|
| 1535 | 1535 | |
| 1536 | - print "<span class=\"text-muted\">"; |
|
| 1537 | - print htmlspecialchars($line["last_error"]); |
|
| 1538 | - print "</span>"; |
|
| 1536 | + print "<span class=\"text-muted\">"; |
|
| 1537 | + print htmlspecialchars($line["last_error"]); |
|
| 1538 | + print "</span>"; |
|
| 1539 | 1539 | |
| 1540 | - print "</td>"; |
|
| 1541 | - print "</tr>"; |
|
| 1540 | + print "</td>"; |
|
| 1541 | + print "</tr>"; |
|
| 1542 | 1542 | |
| 1543 | - ++$lnum; |
|
| 1544 | - } |
|
| 1543 | + ++$lnum; |
|
| 1544 | + } |
|
| 1545 | 1545 | |
| 1546 | - print "</table>"; |
|
| 1547 | - print "</div>"; |
|
| 1546 | + print "</table>"; |
|
| 1547 | + print "</div>"; |
|
| 1548 | 1548 | |
| 1549 | - print "<footer>"; |
|
| 1550 | - print "<button style='float : left' class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" |
|
| 1551 | - .__('Unsubscribe from selected feeds')."</button> "; |
|
| 1549 | + print "<footer>"; |
|
| 1550 | + print "<button style='float : left' class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" |
|
| 1551 | + .__('Unsubscribe from selected feeds')."</button> "; |
|
| 1552 | 1552 | |
| 1553 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". |
|
| 1554 | - __('Close this window')."</button>"; |
|
| 1553 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". |
|
| 1554 | + __('Close this window')."</button>"; |
|
| 1555 | 1555 | |
| 1556 | - print "</footer>"; |
|
| 1557 | - } |
|
| 1556 | + print "</footer>"; |
|
| 1557 | + } |
|
| 1558 | 1558 | |
| 1559 | - private function remove_feed_category($id, $owner_uid) { |
|
| 1559 | + private function remove_feed_category($id, $owner_uid) { |
|
| 1560 | 1560 | |
| 1561 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories |
|
| 1561 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories |
|
| 1562 | 1562 | WHERE id = ? AND owner_uid = ?"); |
| 1563 | - $sth->execute([$id, $owner_uid]); |
|
| 1563 | + $sth->execute([$id, $owner_uid]); |
|
| 1564 | 1564 | |
| 1565 | - CCache::remove($id, $owner_uid, true); |
|
| 1566 | - } |
|
| 1565 | + CCache::remove($id, $owner_uid, true); |
|
| 1566 | + } |
|
| 1567 | 1567 | |
| 1568 | - public static function remove_feed($id, $owner_uid) { |
|
| 1569 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_UNSUBSCRIBE_FEED) as $p) { |
|
| 1570 | - if (! $p->hook_unsubscribe_feed($id, $owner_uid)) { |
|
| 1568 | + public static function remove_feed($id, $owner_uid) { |
|
| 1569 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_UNSUBSCRIBE_FEED) as $p) { |
|
| 1570 | + if (! $p->hook_unsubscribe_feed($id, $owner_uid)) { |
|
| 1571 | 1571 | user_error("feed $id (owner: $owner_uid) not removed due to plugin error (HOOK_UNSUBSCRIBE_FEED).", E_USER_WARNING); |
| 1572 | 1572 | return; |
| 1573 | - } |
|
| 1574 | - } |
|
| 1573 | + } |
|
| 1574 | + } |
|
| 1575 | 1575 | |
| 1576 | - $pdo = Db::pdo(); |
|
| 1576 | + $pdo = Db::pdo(); |
|
| 1577 | 1577 | |
| 1578 | - if ($id > 0) { |
|
| 1579 | - $pdo->beginTransaction(); |
|
| 1578 | + if ($id > 0) { |
|
| 1579 | + $pdo->beginTransaction(); |
|
| 1580 | 1580 | |
| 1581 | - /* save starred articles in Archived feed */ |
|
| 1581 | + /* save starred articles in Archived feed */ |
|
| 1582 | 1582 | |
| 1583 | - /* prepare feed if necessary */ |
|
| 1583 | + /* prepare feed if necessary */ |
|
| 1584 | 1584 | |
| 1585 | - $sth = $pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ? |
|
| 1585 | + $sth = $pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ? |
|
| 1586 | 1586 | AND owner_uid = ?"); |
| 1587 | - $sth->execute([$id, $owner_uid]); |
|
| 1587 | + $sth->execute([$id, $owner_uid]); |
|
| 1588 | 1588 | |
| 1589 | - if ($row = $sth->fetch()) { |
|
| 1590 | - $feed_url = $row["feed_url"]; |
|
| 1589 | + if ($row = $sth->fetch()) { |
|
| 1590 | + $feed_url = $row["feed_url"]; |
|
| 1591 | 1591 | |
| 1592 | - $sth = $pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
| 1592 | + $sth = $pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
| 1593 | 1593 | WHERE feed_url = ? AND owner_uid = ?"); |
| 1594 | - $sth->execute([$feed_url, $owner_uid]); |
|
| 1594 | + $sth->execute([$feed_url, $owner_uid]); |
|
| 1595 | 1595 | |
| 1596 | - if ($row = $sth->fetch()) { |
|
| 1597 | - $archive_id = $row["id"]; |
|
| 1598 | - } else { |
|
| 1599 | - $res = $pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
|
| 1600 | - $row = $res->fetch(); |
|
| 1596 | + if ($row = $sth->fetch()) { |
|
| 1597 | + $archive_id = $row["id"]; |
|
| 1598 | + } else { |
|
| 1599 | + $res = $pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
|
| 1600 | + $row = $res->fetch(); |
|
| 1601 | 1601 | |
| 1602 | - $new_feed_id = (int)$row['id'] + 1; |
|
| 1602 | + $new_feed_id = (int)$row['id'] + 1; |
|
| 1603 | 1603 | |
| 1604 | - $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
| 1604 | + $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
| 1605 | 1605 | (id, owner_uid, title, feed_url, site_url, created) |
| 1606 | 1606 | SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds |
| 1607 | 1607 | WHERE id = ?"); |
| 1608 | - $sth->execute([$new_feed_id, $id]); |
|
| 1608 | + $sth->execute([$new_feed_id, $id]); |
|
| 1609 | 1609 | |
| 1610 | - $archive_id = $new_feed_id; |
|
| 1611 | - } |
|
| 1610 | + $archive_id = $new_feed_id; |
|
| 1611 | + } |
|
| 1612 | 1612 | |
| 1613 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET feed_id = NULL, |
|
| 1613 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET feed_id = NULL, |
|
| 1614 | 1614 | orig_feed_id = ? WHERE feed_id = ? AND |
| 1615 | 1615 | marked = true AND owner_uid = ?"); |
| 1616 | 1616 | |
| 1617 | - $sth->execute([$archive_id, $id, $owner_uid]); |
|
| 1617 | + $sth->execute([$archive_id, $id, $owner_uid]); |
|
| 1618 | 1618 | |
| 1619 | - /* Remove access key for the feed */ |
|
| 1619 | + /* Remove access key for the feed */ |
|
| 1620 | 1620 | |
| 1621 | - $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
| 1621 | + $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
| 1622 | 1622 | feed_id = ? AND owner_uid = ?"); |
| 1623 | - $sth->execute([$id, $owner_uid]); |
|
| 1623 | + $sth->execute([$id, $owner_uid]); |
|
| 1624 | 1624 | |
| 1625 | - /* remove the feed */ |
|
| 1625 | + /* remove the feed */ |
|
| 1626 | 1626 | |
| 1627 | - $sth = $pdo->prepare("DELETE FROM ttrss_feeds |
|
| 1627 | + $sth = $pdo->prepare("DELETE FROM ttrss_feeds |
|
| 1628 | 1628 | WHERE id = ? AND owner_uid = ?"); |
| 1629 | - $sth->execute([$id, $owner_uid]); |
|
| 1630 | - } |
|
| 1629 | + $sth->execute([$id, $owner_uid]); |
|
| 1630 | + } |
|
| 1631 | 1631 | |
| 1632 | - $pdo->commit(); |
|
| 1632 | + $pdo->commit(); |
|
| 1633 | 1633 | |
| 1634 | - if (file_exists(ICONS_DIR . "/$id.ico")) { |
|
| 1635 | - unlink(ICONS_DIR . "/$id.ico"); |
|
| 1636 | - } |
|
| 1634 | + if (file_exists(ICONS_DIR . "/$id.ico")) { |
|
| 1635 | + unlink(ICONS_DIR . "/$id.ico"); |
|
| 1636 | + } |
|
| 1637 | 1637 | |
| 1638 | - CCache::remove($id, $owner_uid); |
|
| 1638 | + CCache::remove($id, $owner_uid); |
|
| 1639 | 1639 | |
| 1640 | - } else { |
|
| 1641 | - Labels::remove(Labels::feed_to_label_id($id), $owner_uid); |
|
| 1642 | - //CCache::remove($id, $owner_uid); don't think labels are cached |
|
| 1643 | - } |
|
| 1644 | - } |
|
| 1640 | + } else { |
|
| 1641 | + Labels::remove(Labels::feed_to_label_id($id), $owner_uid); |
|
| 1642 | + //CCache::remove($id, $owner_uid); don't think labels are cached |
|
| 1643 | + } |
|
| 1644 | + } |
|
| 1645 | 1645 | |
| 1646 | - public function batchSubscribe() { |
|
| 1647 | - print_hidden("op", "pref-feeds"); |
|
| 1648 | - print_hidden("method", "batchaddfeeds"); |
|
| 1646 | + public function batchSubscribe() { |
|
| 1647 | + print_hidden("op", "pref-feeds"); |
|
| 1648 | + print_hidden("method", "batchaddfeeds"); |
|
| 1649 | 1649 | |
| 1650 | - print "<header class='horizontal'>".__("One valid feed per line (no detection is done)")."</header>"; |
|
| 1651 | - print "<section>"; |
|
| 1650 | + print "<header class='horizontal'>".__("One valid feed per line (no detection is done)")."</header>"; |
|
| 1651 | + print "<section>"; |
|
| 1652 | 1652 | |
| 1653 | - print "<textarea |
|
| 1653 | + print "<textarea |
|
| 1654 | 1654 | style='font-size : 12px; width : 98%; height: 200px;' |
| 1655 | 1655 | dojoType='dijit.form.SimpleTextarea' name='feeds'></textarea>"; |
| 1656 | 1656 | |
| 1657 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1658 | - print "<fieldset>"; |
|
| 1659 | - print "<label>" . __('Place in category:') . "</label> "; |
|
| 1660 | - print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
|
| 1661 | - print "</fieldset>"; |
|
| 1662 | - } |
|
| 1657 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 1658 | + print "<fieldset>"; |
|
| 1659 | + print "<label>" . __('Place in category:') . "</label> "; |
|
| 1660 | + print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
|
| 1661 | + print "</fieldset>"; |
|
| 1662 | + } |
|
| 1663 | 1663 | |
| 1664 | - print "</section>"; |
|
| 1664 | + print "</section>"; |
|
| 1665 | 1665 | |
| 1666 | - print "<div id='feedDlg_loginContainer' style='display : none'>"; |
|
| 1666 | + print "<div id='feedDlg_loginContainer' style='display : none'>"; |
|
| 1667 | 1667 | |
| 1668 | - print "<header>" . __("Authentication") . "</header>"; |
|
| 1669 | - print "<section>"; |
|
| 1668 | + print "<header>" . __("Authentication") . "</header>"; |
|
| 1669 | + print "<section>"; |
|
| 1670 | 1670 | |
| 1671 | - print "<input dojoType='dijit.form.TextBox' name='login' placeHolder=\"".__("Login")."\"> |
|
| 1671 | + print "<input dojoType='dijit.form.TextBox' name='login' placeHolder=\"".__("Login")."\"> |
|
| 1672 | 1672 | <input placeHolder=\"".__("Password")."\" dojoType=\"dijit.form.TextBox\" type='password' |
| 1673 | 1673 | autocomplete='new-password' name='pass''></div>"; |
| 1674 | 1674 | |
| 1675 | - print "</section>"; |
|
| 1676 | - print "</div>"; |
|
| 1675 | + print "</section>"; |
|
| 1676 | + print "</div>"; |
|
| 1677 | 1677 | |
| 1678 | - print "<fieldset class='narrow'> |
|
| 1678 | + print "<fieldset class='narrow'> |
|
| 1679 | 1679 | <label class='checkbox'><input type='checkbox' name='need_auth' dojoType='dijit.form.CheckBox' |
| 1680 | 1680 | onclick='displayIfChecked(this, \"feedDlg_loginContainer\")'> ". |
| 1681 | - __('Feeds require authentication.')."</label></div>"; |
|
| 1682 | - print "</fieldset>"; |
|
| 1681 | + __('Feeds require authentication.')."</label></div>"; |
|
| 1682 | + print "</fieldset>"; |
|
| 1683 | 1683 | |
| 1684 | - print "<footer> |
|
| 1684 | + print "<footer> |
|
| 1685 | 1685 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__('Subscribe')."</button> |
| 1686 | 1686 | <button dojoType='dijit.form.Button' onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button> |
| 1687 | 1687 | </footer>"; |
| 1688 | - } |
|
| 1688 | + } |
|
| 1689 | 1689 | |
| 1690 | - public function batchAddFeeds() { |
|
| 1691 | - $cat_id = clean($_REQUEST['cat']); |
|
| 1692 | - $feeds = explode("\n", clean($_REQUEST['feeds'])); |
|
| 1693 | - $login = clean($_REQUEST['login']); |
|
| 1694 | - $pass = trim(clean($_REQUEST['pass'])); |
|
| 1690 | + public function batchAddFeeds() { |
|
| 1691 | + $cat_id = clean($_REQUEST['cat']); |
|
| 1692 | + $feeds = explode("\n", clean($_REQUEST['feeds'])); |
|
| 1693 | + $login = clean($_REQUEST['login']); |
|
| 1694 | + $pass = trim(clean($_REQUEST['pass'])); |
|
| 1695 | 1695 | |
| 1696 | - $csth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
|
| 1696 | + $csth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
|
| 1697 | 1697 | WHERE feed_url = ? AND owner_uid = ?"); |
| 1698 | 1698 | |
| 1699 | - $isth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 1699 | + $isth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 1700 | 1700 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) |
| 1701 | 1701 | VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)"); |
| 1702 | 1702 | |
| 1703 | - foreach ($feeds as $feed) { |
|
| 1704 | - $feed = trim($feed); |
|
| 1703 | + foreach ($feeds as $feed) { |
|
| 1704 | + $feed = trim($feed); |
|
| 1705 | 1705 | |
| 1706 | - if (Feeds::validate_feed_url($feed)) { |
|
| 1706 | + if (Feeds::validate_feed_url($feed)) { |
|
| 1707 | 1707 | |
| 1708 | - $this->pdo->beginTransaction(); |
|
| 1708 | + $this->pdo->beginTransaction(); |
|
| 1709 | 1709 | |
| 1710 | - $csth->execute([$feed, $_SESSION['uid']]); |
|
| 1710 | + $csth->execute([$feed, $_SESSION['uid']]); |
|
| 1711 | 1711 | |
| 1712 | - if (!$csth->fetch()) { |
|
| 1713 | - $isth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]); |
|
| 1714 | - } |
|
| 1712 | + if (!$csth->fetch()) { |
|
| 1713 | + $isth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]); |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - $this->pdo->commit(); |
|
| 1717 | - } |
|
| 1718 | - } |
|
| 1719 | - } |
|
| 1716 | + $this->pdo->commit(); |
|
| 1717 | + } |
|
| 1718 | + } |
|
| 1719 | + } |
|
| 1720 | 1720 | |
| 1721 | - public function regenOPMLKey() { |
|
| 1722 | - $this->update_feed_access_key('OPML:Publish', |
|
| 1723 | - false, $_SESSION["uid"]); |
|
| 1721 | + public function regenOPMLKey() { |
|
| 1722 | + $this->update_feed_access_key('OPML:Publish', |
|
| 1723 | + false, $_SESSION["uid"]); |
|
| 1724 | 1724 | |
| 1725 | - $new_link = Opml::opml_publish_url(); |
|
| 1725 | + $new_link = Opml::opml_publish_url(); |
|
| 1726 | 1726 | |
| 1727 | - print json_encode(array("link" => $new_link)); |
|
| 1728 | - } |
|
| 1727 | + print json_encode(array("link" => $new_link)); |
|
| 1728 | + } |
|
| 1729 | 1729 | |
| 1730 | - public function regenFeedKey() { |
|
| 1731 | - $feed_id = clean($_REQUEST['id']); |
|
| 1732 | - $is_cat = clean($_REQUEST['is_cat']); |
|
| 1730 | + public function regenFeedKey() { |
|
| 1731 | + $feed_id = clean($_REQUEST['id']); |
|
| 1732 | + $is_cat = clean($_REQUEST['is_cat']); |
|
| 1733 | 1733 | |
| 1734 | - $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
|
| 1734 | + $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
|
| 1735 | 1735 | |
| 1736 | - print json_encode(["link" => $new_key]); |
|
| 1737 | - } |
|
| 1736 | + print json_encode(["link" => $new_key]); |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | 1739 | |
| 1740 | - private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
|
| 1741 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
| 1740 | + private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
|
| 1741 | + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
| 1742 | 1742 | |
| 1743 | - // clear old value and generate new one |
|
| 1744 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys |
|
| 1743 | + // clear old value and generate new one |
|
| 1744 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys |
|
| 1745 | 1745 | WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?"); |
| 1746 | - $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]); |
|
| 1746 | + $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]); |
|
| 1747 | 1747 | |
| 1748 | - return Feeds::get_feed_access_key($feed_id, $is_cat, $owner_uid); |
|
| 1749 | - } |
|
| 1748 | + return Feeds::get_feed_access_key($feed_id, $is_cat, $owner_uid); |
|
| 1749 | + } |
|
| 1750 | 1750 | |
| 1751 | - // Silent |
|
| 1752 | - public function clearKeys() { |
|
| 1753 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
| 1751 | + // Silent |
|
| 1752 | + public function clearKeys() { |
|
| 1753 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
| 1754 | 1754 | owner_uid = ?"); |
| 1755 | - $sth->execute([$_SESSION['uid']]); |
|
| 1756 | - } |
|
| 1757 | - |
|
| 1758 | - private function calculate_children_count($cat) { |
|
| 1759 | - $c = 0; |
|
| 1760 | - |
|
| 1761 | - foreach ($cat['items'] as $child) { |
|
| 1762 | - if ($child['type'] == 'category') { |
|
| 1763 | - $c += $this->calculate_children_count($child); |
|
| 1764 | - } else { |
|
| 1765 | - $c += 1; |
|
| 1766 | - } |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - return $c; |
|
| 1770 | - } |
|
| 1771 | - |
|
| 1772 | - public function getinactivefeeds() { |
|
| 1773 | - if (DB_TYPE == "pgsql") { |
|
| 1774 | - $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
| 1775 | - } else { |
|
| 1776 | - $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE |
|
| 1755 | + $sth->execute([$_SESSION['uid']]); |
|
| 1756 | + } |
|
| 1757 | + |
|
| 1758 | + private function calculate_children_count($cat) { |
|
| 1759 | + $c = 0; |
|
| 1760 | + |
|
| 1761 | + foreach ($cat['items'] as $child) { |
|
| 1762 | + if ($child['type'] == 'category') { |
|
| 1763 | + $c += $this->calculate_children_count($child); |
|
| 1764 | + } else { |
|
| 1765 | + $c += 1; |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + return $c; |
|
| 1770 | + } |
|
| 1771 | + |
|
| 1772 | + public function getinactivefeeds() { |
|
| 1773 | + if (DB_TYPE == "pgsql") { |
|
| 1774 | + $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
| 1775 | + } else { |
|
| 1776 | + $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
| 1777 | + } |
|
| 1778 | + |
|
| 1779 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE |
|
| 1780 | 1780 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE |
| 1781 | 1781 | ttrss_entries.id = ref_id AND |
| 1782 | 1782 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND |
| 1783 | 1783 | ttrss_feeds.owner_uid = ?"); |
| 1784 | - $sth->execute([$_SESSION['uid']]); |
|
| 1785 | - |
|
| 1786 | - if ($row = $sth->fetch()) { |
|
| 1787 | - print (int)$row["num_inactive"]; |
|
| 1788 | - } |
|
| 1789 | - } |
|
| 1790 | - |
|
| 1791 | - public static function subscribe_to_feed_url() { |
|
| 1792 | - $url_path = get_self_url_prefix() . |
|
| 1793 | - "/public.php?op=subscribe&feed_url=%s"; |
|
| 1794 | - return $url_path; |
|
| 1795 | - } |
|
| 1784 | + $sth->execute([$_SESSION['uid']]); |
|
| 1785 | + |
|
| 1786 | + if ($row = $sth->fetch()) { |
|
| 1787 | + print (int)$row["num_inactive"]; |
|
| 1788 | + } |
|
| 1789 | + } |
|
| 1790 | + |
|
| 1791 | + public static function subscribe_to_feed_url() { |
|
| 1792 | + $url_path = get_self_url_prefix() . |
|
| 1793 | + "/public.php?op=subscribe&feed_url=%s"; |
|
| 1794 | + return $url_path; |
|
| 1795 | + } |
|
| 1796 | 1796 | |
| 1797 | 1797 | } |
@@ -1349,35 +1349,35 @@ |
||
| 1349 | 1349 | continue; |
| 1350 | 1350 | |
| 1351 | 1351 | switch ($rule["type"]) { |
| 1352 | - case "title": |
|
| 1353 | - $match = @preg_match("/$reg_exp/iu", $title); |
|
| 1354 | - break; |
|
| 1355 | - case "content": |
|
| 1356 | - // we don't need to deal with multiline regexps |
|
| 1357 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1352 | + case "title": |
|
| 1353 | + $match = @preg_match("/$reg_exp/iu", $title); |
|
| 1354 | + break; |
|
| 1355 | + case "content": |
|
| 1356 | + // we don't need to deal with multiline regexps |
|
| 1357 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1358 | 1358 | |
| 1359 | - $match = @preg_match("/$reg_exp/iu", $content); |
|
| 1360 | - break; |
|
| 1361 | - case "both": |
|
| 1362 | - // we don't need to deal with multiline regexps |
|
| 1363 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1359 | + $match = @preg_match("/$reg_exp/iu", $content); |
|
| 1360 | + break; |
|
| 1361 | + case "both": |
|
| 1362 | + // we don't need to deal with multiline regexps |
|
| 1363 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1364 | 1364 | |
| 1365 | - $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
| 1366 | - break; |
|
| 1367 | - case "link": |
|
| 1368 | - $match = @preg_match("/$reg_exp/iu", $link); |
|
| 1369 | - break; |
|
| 1370 | - case "author": |
|
| 1371 | - $match = @preg_match("/$reg_exp/iu", $author); |
|
| 1372 | - break; |
|
| 1373 | - case "tag": |
|
| 1374 | - foreach ($tags as $tag) { |
|
| 1375 | - if (@preg_match("/$reg_exp/iu", $tag)) { |
|
| 1376 | - $match = true; |
|
| 1377 | - break; |
|
| 1378 | - } |
|
| 1365 | + $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
| 1366 | + break; |
|
| 1367 | + case "link": |
|
| 1368 | + $match = @preg_match("/$reg_exp/iu", $link); |
|
| 1369 | + break; |
|
| 1370 | + case "author": |
|
| 1371 | + $match = @preg_match("/$reg_exp/iu", $author); |
|
| 1372 | + break; |
|
| 1373 | + case "tag": |
|
| 1374 | + foreach ($tags as $tag) { |
|
| 1375 | + if (@preg_match("/$reg_exp/iu", $tag)) { |
|
| 1376 | + $match = true; |
|
| 1377 | + break; |
|
| 1379 | 1378 | } |
| 1380 | - break; |
|
| 1379 | + } |
|
| 1380 | + break; |
|
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | if ($rule_inverse) $match = !$match; |
@@ -1,50 +1,50 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class RSSUtils { |
| 3 | - public static function calculate_article_hash($article, $pluginhost) { |
|
| 4 | - $tmp = ""; |
|
| 5 | - |
|
| 6 | - foreach ($article as $k => $v) { |
|
| 7 | - if ($k != "feed" && isset($v)) { |
|
| 8 | - $x = strip_tags(is_array($v) ? implode(",", $v) : $v); |
|
| 9 | - |
|
| 10 | - $tmp .= sha1("$k:" . sha1($x)); |
|
| 11 | - } |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - // Strips utf8mb4 characters (i.e. emoji) for mysql |
|
| 18 | - public static function strip_utf8mb4($str) { |
|
| 19 | - return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public static function cleanup_feed_browser() { |
|
| 23 | - $pdo = Db::pdo(); |
|
| 24 | - $pdo->query("DELETE FROM ttrss_feedbrowser_cache"); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public static function update_daemon_common($limit = DAEMON_FEED_LIMIT) { |
|
| 28 | - $schema_version = get_schema_version(); |
|
| 29 | - |
|
| 30 | - if ($schema_version != SCHEMA_VERSION) { |
|
| 31 | - die("Schema version is wrong, please upgrade the database.\n"); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - $pdo = Db::pdo(); |
|
| 35 | - |
|
| 36 | - if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) { |
|
| 37 | - if (DB_TYPE == "pgsql") { |
|
| 38 | - $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; |
|
| 39 | - } else { |
|
| 40 | - $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; |
|
| 41 | - } |
|
| 42 | - } else { |
|
| 43 | - $login_thresh_qpart = ""; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (DB_TYPE == "pgsql") { |
|
| 47 | - $update_limit_qpart = "AND (( |
|
| 3 | + public static function calculate_article_hash($article, $pluginhost) { |
|
| 4 | + $tmp = ""; |
|
| 5 | + |
|
| 6 | + foreach ($article as $k => $v) { |
|
| 7 | + if ($k != "feed" && isset($v)) { |
|
| 8 | + $x = strip_tags(is_array($v) ? implode(",", $v) : $v); |
|
| 9 | + |
|
| 10 | + $tmp .= sha1("$k:" . sha1($x)); |
|
| 11 | + } |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + // Strips utf8mb4 characters (i.e. emoji) for mysql |
|
| 18 | + public static function strip_utf8mb4($str) { |
|
| 19 | + return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public static function cleanup_feed_browser() { |
|
| 23 | + $pdo = Db::pdo(); |
|
| 24 | + $pdo->query("DELETE FROM ttrss_feedbrowser_cache"); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public static function update_daemon_common($limit = DAEMON_FEED_LIMIT) { |
|
| 28 | + $schema_version = get_schema_version(); |
|
| 29 | + |
|
| 30 | + if ($schema_version != SCHEMA_VERSION) { |
|
| 31 | + die("Schema version is wrong, please upgrade the database.\n"); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + $pdo = Db::pdo(); |
|
| 35 | + |
|
| 36 | + if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) { |
|
| 37 | + if (DB_TYPE == "pgsql") { |
|
| 38 | + $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; |
|
| 39 | + } else { |
|
| 40 | + $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; |
|
| 41 | + } |
|
| 42 | + } else { |
|
| 43 | + $login_thresh_qpart = ""; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (DB_TYPE == "pgsql") { |
|
| 47 | + $update_limit_qpart = "AND (( |
|
| 48 | 48 | ttrss_feeds.update_interval = 0 |
| 49 | 49 | AND ttrss_user_prefs.value != '-1' |
| 50 | 50 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | AND ttrss_user_prefs.value != '-1') |
| 56 | 56 | OR (last_updated = '1970-01-01 00:00:00' |
| 57 | 57 | AND ttrss_user_prefs.value != '-1'))"; |
| 58 | - } else { |
|
| 59 | - $update_limit_qpart = "AND (( |
|
| 58 | + } else { |
|
| 59 | + $update_limit_qpart = "AND (( |
|
| 60 | 60 | ttrss_feeds.update_interval = 0 |
| 61 | 61 | AND ttrss_user_prefs.value != '-1' |
| 62 | 62 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) |
@@ -67,22 +67,22 @@ discard block |
||
| 67 | 67 | AND ttrss_user_prefs.value != '-1') |
| 68 | 68 | OR (last_updated = '1970-01-01 00:00:00' |
| 69 | 69 | AND ttrss_user_prefs.value != '-1'))"; |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // Test if feed is currently being updated by another process. |
|
| 73 | - if (DB_TYPE == "pgsql") { |
|
| 74 | - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '10 minutes')"; |
|
| 75 | - } else { |
|
| 76 | - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))"; |
|
| 77 | - } |
|
| 72 | + // Test if feed is currently being updated by another process. |
|
| 73 | + if (DB_TYPE == "pgsql") { |
|
| 74 | + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '10 minutes')"; |
|
| 75 | + } else { |
|
| 76 | + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))"; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $query_limit = $limit ? sprintf("LIMIT %d", $limit) : ""; |
|
| 79 | + $query_limit = $limit ? sprintf("LIMIT %d", $limit) : ""; |
|
| 80 | 80 | |
| 81 | - // Update the least recently updated feeds first |
|
| 82 | - $query_order = "ORDER BY last_updated"; |
|
| 83 | - if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST"; |
|
| 81 | + // Update the least recently updated feeds first |
|
| 82 | + $query_order = "ORDER BY last_updated"; |
|
| 83 | + if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST"; |
|
| 84 | 84 | |
| 85 | - $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated |
|
| 85 | + $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated |
|
| 86 | 86 | FROM |
| 87 | 87 | ttrss_feeds, ttrss_users, ttrss_user_prefs |
| 88 | 88 | WHERE |
@@ -94,32 +94,32 @@ discard block |
||
| 94 | 94 | $updstart_thresh_qpart |
| 95 | 95 | $query_order $query_limit"; |
| 96 | 96 | |
| 97 | - $res = $pdo->query($query); |
|
| 97 | + $res = $pdo->query($query); |
|
| 98 | 98 | |
| 99 | - $feeds_to_update = array(); |
|
| 100 | - while ($line = $res->fetch()) { |
|
| 101 | - array_push($feeds_to_update, $line['feed_url']); |
|
| 102 | - } |
|
| 99 | + $feeds_to_update = array(); |
|
| 100 | + while ($line = $res->fetch()) { |
|
| 101 | + array_push($feeds_to_update, $line['feed_url']); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - Debug::log(sprintf("Scheduled %d feeds to update...", count($feeds_to_update))); |
|
| 104 | + Debug::log(sprintf("Scheduled %d feeds to update...", count($feeds_to_update))); |
|
| 105 | 105 | |
| 106 | - // Update last_update_started before actually starting the batch |
|
| 107 | - // in order to minimize collision risk for parallel daemon tasks |
|
| 108 | - if (count($feeds_to_update) > 0) { |
|
| 109 | - $feeds_qmarks = arr_qmarks($feeds_to_update); |
|
| 106 | + // Update last_update_started before actually starting the batch |
|
| 107 | + // in order to minimize collision risk for parallel daemon tasks |
|
| 108 | + if (count($feeds_to_update) > 0) { |
|
| 109 | + $feeds_qmarks = arr_qmarks($feeds_to_update); |
|
| 110 | 110 | |
| 111 | - $tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
| 111 | + $tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
| 112 | 112 | WHERE feed_url IN ($feeds_qmarks)"); |
| 113 | - $tmph->execute($feeds_to_update); |
|
| 114 | - } |
|
| 113 | + $tmph->execute($feeds_to_update); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - $nf = 0; |
|
| 117 | - $bstarted = microtime(true); |
|
| 116 | + $nf = 0; |
|
| 117 | + $bstarted = microtime(true); |
|
| 118 | 118 | |
| 119 | - $batch_owners = array(); |
|
| 119 | + $batch_owners = array(); |
|
| 120 | 120 | |
| 121 | - // since we have the data cached, we can deal with other feeds with the same url |
|
| 122 | - $usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid |
|
| 121 | + // since we have the data cached, we can deal with other feeds with the same url |
|
| 122 | + $usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid |
|
| 123 | 123 | FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE |
| 124 | 124 | ttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND |
| 125 | 125 | ttrss_users.id = ttrss_user_prefs.owner_uid AND |
@@ -130,715 +130,715 @@ discard block |
||
| 130 | 130 | $login_thresh_qpart |
| 131 | 131 | ORDER BY ttrss_feeds.id $query_limit"); |
| 132 | 132 | |
| 133 | - foreach ($feeds_to_update as $feed) { |
|
| 134 | - Debug::log("Base feed: $feed"); |
|
| 133 | + foreach ($feeds_to_update as $feed) { |
|
| 134 | + Debug::log("Base feed: $feed"); |
|
| 135 | 135 | |
| 136 | - $usth->execute([$feed]); |
|
| 137 | - //update_rss_feed($line["id"], true); |
|
| 136 | + $usth->execute([$feed]); |
|
| 137 | + //update_rss_feed($line["id"], true); |
|
| 138 | 138 | |
| 139 | - if ($tline = $usth->fetch()) { |
|
| 140 | - Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); |
|
| 139 | + if ($tline = $usth->fetch()) { |
|
| 140 | + Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); |
|
| 141 | 141 | |
| 142 | - if (array_search($tline["owner_uid"], $batch_owners) === false) |
|
| 143 | - array_push($batch_owners, $tline["owner_uid"]); |
|
| 142 | + if (array_search($tline["owner_uid"], $batch_owners) === false) |
|
| 143 | + array_push($batch_owners, $tline["owner_uid"]); |
|
| 144 | 144 | |
| 145 | - $fstarted = microtime(true); |
|
| 145 | + $fstarted = microtime(true); |
|
| 146 | 146 | |
| 147 | - try { |
|
| 148 | - RSSUtils::update_rss_feed($tline["id"], true, false); |
|
| 149 | - } catch (PDOException $e) { |
|
| 150 | - Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); |
|
| 147 | + try { |
|
| 148 | + RSSUtils::update_rss_feed($tline["id"], true, false); |
|
| 149 | + } catch (PDOException $e) { |
|
| 150 | + Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); |
|
| 151 | 151 | |
| 152 | - try { |
|
| 153 | - $pdo->rollback(); |
|
| 154 | - } catch (PDOException $e) { |
|
| 155 | - // it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be |
|
| 156 | - // thrown outside of an active transaction during feed update |
|
| 157 | - } |
|
| 158 | - } |
|
| 152 | + try { |
|
| 153 | + $pdo->rollback(); |
|
| 154 | + } catch (PDOException $e) { |
|
| 155 | + // it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be |
|
| 156 | + // thrown outside of an active transaction during feed update |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - Debug::log(sprintf(" %.4f (sec)", microtime(true) - $fstarted)); |
|
| 160 | + Debug::log(sprintf(" %.4f (sec)", microtime(true) - $fstarted)); |
|
| 161 | 161 | |
| 162 | - ++$nf; |
|
| 163 | - } |
|
| 164 | - } |
|
| 162 | + ++$nf; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if ($nf > 0) { |
|
| 167 | - Debug::log(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf, |
|
| 168 | - microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf)); |
|
| 169 | - } |
|
| 166 | + if ($nf > 0) { |
|
| 167 | + Debug::log(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf, |
|
| 168 | + microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf)); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - foreach ($batch_owners as $owner_uid) { |
|
| 172 | - Debug::log("Running housekeeping tasks for user $owner_uid..."); |
|
| 171 | + foreach ($batch_owners as $owner_uid) { |
|
| 172 | + Debug::log("Running housekeeping tasks for user $owner_uid..."); |
|
| 173 | 173 | |
| 174 | - RSSUtils::housekeeping_user($owner_uid); |
|
| 175 | - } |
|
| 174 | + RSSUtils::housekeeping_user($owner_uid); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - // Send feed digests by email if needed. |
|
| 178 | - Digest::send_headlines_digests(); |
|
| 177 | + // Send feed digests by email if needed. |
|
| 178 | + Digest::send_headlines_digests(); |
|
| 179 | 179 | |
| 180 | - return $nf; |
|
| 181 | - } |
|
| 180 | + return $nf; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - // this is used when subscribing |
|
| 184 | - public static function set_basic_feed_info($feed) { |
|
| 183 | + // this is used when subscribing |
|
| 184 | + public static function set_basic_feed_info($feed) { |
|
| 185 | 185 | |
| 186 | - $pdo = Db::pdo(); |
|
| 186 | + $pdo = Db::pdo(); |
|
| 187 | 187 | |
| 188 | - $sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login |
|
| 188 | + $sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login |
|
| 189 | 189 | FROM ttrss_feeds WHERE id = ?"); |
| 190 | - $sth->execute([$feed]); |
|
| 190 | + $sth->execute([$feed]); |
|
| 191 | 191 | |
| 192 | - if ($row = $sth->fetch()) { |
|
| 192 | + if ($row = $sth->fetch()) { |
|
| 193 | 193 | |
| 194 | - $owner_uid = $row["owner_uid"]; |
|
| 195 | - $auth_login = $row["auth_login"]; |
|
| 196 | - $auth_pass = $row["auth_pass"]; |
|
| 197 | - $fetch_url = $row["feed_url"]; |
|
| 194 | + $owner_uid = $row["owner_uid"]; |
|
| 195 | + $auth_login = $row["auth_login"]; |
|
| 196 | + $auth_pass = $row["auth_pass"]; |
|
| 197 | + $fetch_url = $row["feed_url"]; |
|
| 198 | 198 | |
| 199 | - $pluginhost = new PluginHost(); |
|
| 200 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
| 199 | + $pluginhost = new PluginHost(); |
|
| 200 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
| 201 | 201 | |
| 202 | - $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
| 203 | - $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
| 204 | - $pluginhost->load_data(); |
|
| 202 | + $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
| 203 | + $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
| 204 | + $pluginhost->load_data(); |
|
| 205 | 205 | |
| 206 | - $basic_info = array(); |
|
| 207 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { |
|
| 208 | - $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); |
|
| 209 | - } |
|
| 206 | + $basic_info = array(); |
|
| 207 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { |
|
| 208 | + $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - if (!$basic_info) { |
|
| 212 | - $feed_data = fetch_file_contents($fetch_url, false, |
|
| 213 | - $auth_login, $auth_pass, false, |
|
| 214 | - FEED_FETCH_TIMEOUT, |
|
| 215 | - 0); |
|
| 211 | + if (!$basic_info) { |
|
| 212 | + $feed_data = fetch_file_contents($fetch_url, false, |
|
| 213 | + $auth_login, $auth_pass, false, |
|
| 214 | + FEED_FETCH_TIMEOUT, |
|
| 215 | + 0); |
|
| 216 | 216 | |
| 217 | - $feed_data = trim($feed_data); |
|
| 217 | + $feed_data = trim($feed_data); |
|
| 218 | 218 | |
| 219 | - $rss = new FeedParser($feed_data); |
|
| 220 | - $rss->init(); |
|
| 219 | + $rss = new FeedParser($feed_data); |
|
| 220 | + $rss->init(); |
|
| 221 | 221 | |
| 222 | - if (!$rss->error()) { |
|
| 223 | - $basic_info = array( |
|
| 224 | - 'title' => mb_substr(clean($rss->get_title()), 0, 199), |
|
| 225 | - 'site_url' => mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245) |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - } |
|
| 222 | + if (!$rss->error()) { |
|
| 223 | + $basic_info = array( |
|
| 224 | + 'title' => mb_substr(clean($rss->get_title()), 0, 199), |
|
| 225 | + 'site_url' => mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245) |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - if ($basic_info && is_array($basic_info)) { |
|
| 231 | - $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
| 232 | - $sth->execute([$feed]); |
|
| 230 | + if ($basic_info && is_array($basic_info)) { |
|
| 231 | + $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
| 232 | + $sth->execute([$feed]); |
|
| 233 | 233 | |
| 234 | - if ($row = $sth->fetch()) { |
|
| 234 | + if ($row = $sth->fetch()) { |
|
| 235 | 235 | |
| 236 | - $registered_title = $row["title"]; |
|
| 237 | - $orig_site_url = $row["site_url"]; |
|
| 236 | + $registered_title = $row["title"]; |
|
| 237 | + $orig_site_url = $row["site_url"]; |
|
| 238 | 238 | |
| 239 | - if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) { |
|
| 239 | + if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) { |
|
| 240 | 240 | |
| 241 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
| 241 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
| 242 | 242 | title = ? WHERE id = ?"); |
| 243 | - $sth->execute([$basic_info['title'], $feed]); |
|
| 244 | - } |
|
| 243 | + $sth->execute([$basic_info['title'], $feed]); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) { |
|
| 247 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
| 246 | + if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) { |
|
| 247 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
| 248 | 248 | site_url = ? WHERE id = ?"); |
| 249 | - $sth->execute([$basic_info['site_url'], $feed]); |
|
| 250 | - } |
|
| 249 | + $sth->execute([$basic_info['site_url'], $feed]); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 259 | - */ |
|
| 260 | - public static function update_rss_feed($feed, $no_cache = false) { |
|
| 257 | + /** |
|
| 258 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 259 | + */ |
|
| 260 | + public static function update_rss_feed($feed, $no_cache = false) { |
|
| 261 | 261 | |
| 262 | - reset_fetch_domain_quota(); |
|
| 262 | + reset_fetch_domain_quota(); |
|
| 263 | 263 | |
| 264 | - Debug::log("start", Debug::$LOG_VERBOSE); |
|
| 264 | + Debug::log("start", Debug::$LOG_VERBOSE); |
|
| 265 | 265 | |
| 266 | - $pdo = Db::pdo(); |
|
| 266 | + $pdo = Db::pdo(); |
|
| 267 | 267 | |
| 268 | - $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
| 269 | - $sth->execute([$feed]); |
|
| 268 | + $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
| 269 | + $sth->execute([$feed]); |
|
| 270 | 270 | |
| 271 | - if (!$row = $sth->fetch()) { |
|
| 272 | - Debug::log("feed $feed not found, skipping."); |
|
| 273 | - user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING); |
|
| 274 | - return false; |
|
| 275 | - } |
|
| 271 | + if (!$row = $sth->fetch()) { |
|
| 272 | + Debug::log("feed $feed not found, skipping."); |
|
| 273 | + user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING); |
|
| 274 | + return false; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - $title = $row["title"]; |
|
| 278 | - $site_url = $row["site_url"]; |
|
| 277 | + $title = $row["title"]; |
|
| 278 | + $site_url = $row["site_url"]; |
|
| 279 | 279 | |
| 280 | - // feed was batch-subscribed or something, we need to get basic info |
|
| 281 | - // this is not optimal currently as it fetches stuff separately TODO: optimize |
|
| 282 | - if ($title == "[Unknown]" || !$title || !$site_url) { |
|
| 283 | - Debug::log("setting basic feed info for $feed [$title, $site_url]..."); |
|
| 284 | - RSSUtils::set_basic_feed_info($feed); |
|
| 285 | - } |
|
| 280 | + // feed was batch-subscribed or something, we need to get basic info |
|
| 281 | + // this is not optimal currently as it fetches stuff separately TODO: optimize |
|
| 282 | + if ($title == "[Unknown]" || !$title || !$site_url) { |
|
| 283 | + Debug::log("setting basic feed info for $feed [$title, $site_url]..."); |
|
| 284 | + RSSUtils::set_basic_feed_info($feed); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - $sth = $pdo->prepare("SELECT id,update_interval,auth_login, |
|
| 287 | + $sth = $pdo->prepare("SELECT id,update_interval,auth_login, |
|
| 288 | 288 | feed_url,auth_pass,cache_images, |
| 289 | 289 | mark_unread_on_update, owner_uid, |
| 290 | 290 | auth_pass_encrypted, feed_language, |
| 291 | 291 | last_modified, |
| 292 | 292 | ".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional |
| 293 | 293 | FROM ttrss_feeds WHERE id = ?"); |
| 294 | - $sth->execute([$feed]); |
|
| 294 | + $sth->execute([$feed]); |
|
| 295 | 295 | |
| 296 | - if ($row = $sth->fetch()) { |
|
| 296 | + if ($row = $sth->fetch()) { |
|
| 297 | 297 | |
| 298 | - $owner_uid = $row["owner_uid"]; |
|
| 299 | - $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
| 298 | + $owner_uid = $row["owner_uid"]; |
|
| 299 | + $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
| 300 | 300 | |
| 301 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
| 301 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
| 302 | 302 | WHERE id = ?"); |
| 303 | - $sth->execute([$feed]); |
|
| 303 | + $sth->execute([$feed]); |
|
| 304 | 304 | |
| 305 | - $auth_login = $row["auth_login"]; |
|
| 306 | - $auth_pass = $row["auth_pass"]; |
|
| 307 | - $stored_last_modified = $row["last_modified"]; |
|
| 308 | - $last_unconditional = $row["last_unconditional"]; |
|
| 309 | - $cache_images = $row["cache_images"]; |
|
| 310 | - $fetch_url = $row["feed_url"]; |
|
| 305 | + $auth_login = $row["auth_login"]; |
|
| 306 | + $auth_pass = $row["auth_pass"]; |
|
| 307 | + $stored_last_modified = $row["last_modified"]; |
|
| 308 | + $last_unconditional = $row["last_unconditional"]; |
|
| 309 | + $cache_images = $row["cache_images"]; |
|
| 310 | + $fetch_url = $row["feed_url"]; |
|
| 311 | 311 | |
| 312 | - $feed_language = mb_strtolower($row["feed_language"]); |
|
| 312 | + $feed_language = mb_strtolower($row["feed_language"]); |
|
| 313 | 313 | |
| 314 | - if (!$feed_language) |
|
| 315 | - $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid)); |
|
| 314 | + if (!$feed_language) |
|
| 315 | + $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid)); |
|
| 316 | 316 | |
| 317 | - if (!$feed_language) |
|
| 318 | - $feed_language = 'simple'; |
|
| 317 | + if (!$feed_language) |
|
| 318 | + $feed_language = 'simple'; |
|
| 319 | 319 | |
| 320 | - } else { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 320 | + } else { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - $date_feed_processed = date('Y-m-d H:i'); |
|
| 324 | + $date_feed_processed = date('Y-m-d H:i'); |
|
| 325 | 325 | |
| 326 | - $cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml"; |
|
| 326 | + $cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml"; |
|
| 327 | 327 | |
| 328 | - $pluginhost = new PluginHost(); |
|
| 329 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
| 328 | + $pluginhost = new PluginHost(); |
|
| 329 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
| 330 | 330 | |
| 331 | - $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
| 332 | - $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
| 333 | - $pluginhost->load_data(); |
|
| 331 | + $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
| 332 | + $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
| 333 | + $pluginhost->load_data(); |
|
| 334 | 334 | |
| 335 | - $rss_hash = false; |
|
| 335 | + $rss_hash = false; |
|
| 336 | 336 | |
| 337 | - $force_refetch = isset($_REQUEST["force_refetch"]); |
|
| 338 | - $feed_data = ""; |
|
| 337 | + $force_refetch = isset($_REQUEST["force_refetch"]); |
|
| 338 | + $feed_data = ""; |
|
| 339 | 339 | |
| 340 | - Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE); |
|
| 340 | + Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE); |
|
| 341 | 341 | |
| 342 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { |
|
| 343 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 344 | - $start = microtime(true); |
|
| 345 | - $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass); |
|
| 346 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 347 | - } |
|
| 342 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { |
|
| 343 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 344 | + $start = microtime(true); |
|
| 345 | + $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass); |
|
| 346 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - if ($feed_data) { |
|
| 350 | - Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 351 | - } else { |
|
| 352 | - Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 353 | - } |
|
| 349 | + if ($feed_data) { |
|
| 350 | + Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 351 | + } else { |
|
| 352 | + Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - // try cache |
|
| 356 | - if (!$feed_data && |
|
| 357 | - file_exists($cache_filename) && |
|
| 358 | - is_readable($cache_filename) && |
|
| 359 | - !$auth_login && !$auth_pass && |
|
| 360 | - filemtime($cache_filename) > time() - 30) { |
|
| 355 | + // try cache |
|
| 356 | + if (!$feed_data && |
|
| 357 | + file_exists($cache_filename) && |
|
| 358 | + is_readable($cache_filename) && |
|
| 359 | + !$auth_login && !$auth_pass && |
|
| 360 | + filemtime($cache_filename) > time() - 30) { |
|
| 361 | 361 | |
| 362 | - Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE); |
|
| 362 | + Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE); |
|
| 363 | 363 | |
| 364 | - @$feed_data = file_get_contents($cache_filename); |
|
| 364 | + @$feed_data = file_get_contents($cache_filename); |
|
| 365 | 365 | |
| 366 | - if ($feed_data) { |
|
| 367 | - $rss_hash = sha1($feed_data); |
|
| 368 | - } |
|
| 366 | + if ($feed_data) { |
|
| 367 | + $rss_hash = sha1($feed_data); |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - } else { |
|
| 371 | - Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE); |
|
| 372 | - } |
|
| 370 | + } else { |
|
| 371 | + Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - global $fetch_last_modified; |
|
| 374 | + global $fetch_last_modified; |
|
| 375 | 375 | |
| 376 | - // fetch feed from source |
|
| 377 | - if (!$feed_data) { |
|
| 378 | - Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE); |
|
| 376 | + // fetch feed from source |
|
| 377 | + if (!$feed_data) { |
|
| 378 | + Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE); |
|
| 379 | 379 | |
| 380 | - if (ini_get("open_basedir") && function_exists("curl_init")) { |
|
| 381 | - Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE); |
|
| 382 | - } |
|
| 380 | + if (ini_get("open_basedir") && function_exists("curl_init")) { |
|
| 381 | + Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE); |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) { |
|
| 385 | - Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE); |
|
| 384 | + if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) { |
|
| 385 | + Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE); |
|
| 386 | 386 | |
| 387 | - $force_refetch = true; |
|
| 388 | - } else { |
|
| 389 | - Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE); |
|
| 390 | - } |
|
| 387 | + $force_refetch = true; |
|
| 388 | + } else { |
|
| 389 | + Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE); |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE); |
|
| 392 | + Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE); |
|
| 393 | 393 | |
| 394 | - $feed_data = fetch_file_contents([ |
|
| 395 | - "url" => $fetch_url, |
|
| 396 | - "login" => $auth_login, |
|
| 397 | - "pass" => $auth_pass, |
|
| 398 | - "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, |
|
| 399 | - "last_modified" => $force_refetch ? "" : $stored_last_modified |
|
| 400 | - ]); |
|
| 394 | + $feed_data = fetch_file_contents([ |
|
| 395 | + "url" => $fetch_url, |
|
| 396 | + "login" => $auth_login, |
|
| 397 | + "pass" => $auth_pass, |
|
| 398 | + "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, |
|
| 399 | + "last_modified" => $force_refetch ? "" : $stored_last_modified |
|
| 400 | + ]); |
|
| 401 | 401 | |
| 402 | - $feed_data = trim($feed_data); |
|
| 402 | + $feed_data = trim($feed_data); |
|
| 403 | 403 | |
| 404 | - Debug::log("fetch done.", Debug::$LOG_VERBOSE); |
|
| 405 | - Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE); |
|
| 404 | + Debug::log("fetch done.", Debug::$LOG_VERBOSE); |
|
| 405 | + Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE); |
|
| 406 | 406 | |
| 407 | - if ($feed_data && $fetch_last_modified != $stored_last_modified) { |
|
| 408 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?"); |
|
| 409 | - $sth->execute([substr($fetch_last_modified, 0, 245), $feed]); |
|
| 410 | - } |
|
| 407 | + if ($feed_data && $fetch_last_modified != $stored_last_modified) { |
|
| 408 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?"); |
|
| 409 | + $sth->execute([substr($fetch_last_modified, 0, 245), $feed]); |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - // cache vanilla feed data for re-use |
|
| 413 | - if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) { |
|
| 414 | - $new_rss_hash = sha1($feed_data); |
|
| 412 | + // cache vanilla feed data for re-use |
|
| 413 | + if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) { |
|
| 414 | + $new_rss_hash = sha1($feed_data); |
|
| 415 | 415 | |
| 416 | - if ($new_rss_hash != $rss_hash) { |
|
| 417 | - Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE); |
|
| 418 | - @file_put_contents($cache_filename, $feed_data); |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 416 | + if ($new_rss_hash != $rss_hash) { |
|
| 417 | + Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE); |
|
| 418 | + @file_put_contents($cache_filename, $feed_data); |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - if (!$feed_data) { |
|
| 424 | - global $fetch_last_error; |
|
| 425 | - global $fetch_last_error_code; |
|
| 423 | + if (!$feed_data) { |
|
| 424 | + global $fetch_last_error; |
|
| 425 | + global $fetch_last_error_code; |
|
| 426 | 426 | |
| 427 | - Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE); |
|
| 427 | + Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE); |
|
| 428 | 428 | |
| 429 | - // If-Modified-Since |
|
| 430 | - if ($fetch_last_error_code != 304) { |
|
| 431 | - $error_message = $fetch_last_error; |
|
| 432 | - } else { |
|
| 433 | - Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE); |
|
| 434 | - $error_message = ""; |
|
| 435 | - } |
|
| 429 | + // If-Modified-Since |
|
| 430 | + if ($fetch_last_error_code != 304) { |
|
| 431 | + $error_message = $fetch_last_error; |
|
| 432 | + } else { |
|
| 433 | + Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE); |
|
| 434 | + $error_message = ""; |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
| 437 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
| 438 | 438 | last_updated = NOW() WHERE id = ?"); |
| 439 | - $sth->execute([$error_message, $feed]); |
|
| 439 | + $sth->execute([$error_message, $feed]); |
|
| 440 | 440 | |
| 441 | - return; |
|
| 442 | - } |
|
| 441 | + return; |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE); |
|
| 445 | - $feed_data_checksum = md5($feed_data); |
|
| 444 | + Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE); |
|
| 445 | + $feed_data_checksum = md5($feed_data); |
|
| 446 | 446 | |
| 447 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { |
|
| 448 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 449 | - $start = microtime(true); |
|
| 450 | - $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed); |
|
| 451 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 452 | - } |
|
| 447 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { |
|
| 448 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 449 | + $start = microtime(true); |
|
| 450 | + $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed); |
|
| 451 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 452 | + } |
|
| 453 | 453 | |
| 454 | - if (md5($feed_data) != $feed_data_checksum) { |
|
| 455 | - Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 456 | - } else { |
|
| 457 | - Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 458 | - } |
|
| 454 | + if (md5($feed_data) != $feed_data_checksum) { |
|
| 455 | + Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 456 | + } else { |
|
| 457 | + Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - $rss = new FeedParser($feed_data); |
|
| 461 | - $rss->init(); |
|
| 460 | + $rss = new FeedParser($feed_data); |
|
| 461 | + $rss->init(); |
|
| 462 | 462 | |
| 463 | - if (!$rss->error()) { |
|
| 463 | + if (!$rss->error()) { |
|
| 464 | 464 | |
| 465 | - Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE); |
|
| 465 | + Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE); |
|
| 466 | 466 | |
| 467 | - // We use local pluginhost here because we need to load different per-user feed plugins |
|
| 467 | + // We use local pluginhost here because we need to load different per-user feed plugins |
|
| 468 | 468 | |
| 469 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) { |
|
| 470 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 471 | - $start = microtime(true); |
|
| 472 | - $plugin->hook_feed_parsed($rss); |
|
| 473 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 474 | - } |
|
| 469 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) { |
|
| 470 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 471 | + $start = microtime(true); |
|
| 472 | + $plugin->hook_feed_parsed($rss); |
|
| 473 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - Debug::log("language: $feed_language", Debug::$LOG_VERBOSE); |
|
| 477 | - Debug::log("processing feed data...", Debug::$LOG_VERBOSE); |
|
| 476 | + Debug::log("language: $feed_language", Debug::$LOG_VERBOSE); |
|
| 477 | + Debug::log("processing feed data...", Debug::$LOG_VERBOSE); |
|
| 478 | 478 | |
| 479 | - if (DB_TYPE == "pgsql") { |
|
| 480 | - $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; |
|
| 481 | - } else { |
|
| 482 | - $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; |
|
| 483 | - } |
|
| 479 | + if (DB_TYPE == "pgsql") { |
|
| 480 | + $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; |
|
| 481 | + } else { |
|
| 482 | + $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color, |
|
| 485 | + $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color, |
|
| 486 | 486 | (favicon_last_checked IS NULL OR $favicon_interval_qpart) AS |
| 487 | 487 | favicon_needs_check |
| 488 | 488 | FROM ttrss_feeds WHERE id = ?"); |
| 489 | - $sth->execute([$feed]); |
|
| 489 | + $sth->execute([$feed]); |
|
| 490 | 490 | |
| 491 | - if ($row = $sth->fetch()) { |
|
| 492 | - $favicon_needs_check = $row["favicon_needs_check"]; |
|
| 493 | - $favicon_avg_color = $row["favicon_avg_color"]; |
|
| 494 | - $owner_uid = $row["owner_uid"]; |
|
| 495 | - } else { |
|
| 496 | - return false; |
|
| 497 | - } |
|
| 491 | + if ($row = $sth->fetch()) { |
|
| 492 | + $favicon_needs_check = $row["favicon_needs_check"]; |
|
| 493 | + $favicon_avg_color = $row["favicon_avg_color"]; |
|
| 494 | + $owner_uid = $row["owner_uid"]; |
|
| 495 | + } else { |
|
| 496 | + return false; |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245); |
|
| 499 | + $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245); |
|
| 500 | 500 | |
| 501 | - Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE); |
|
| 502 | - Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE); |
|
| 501 | + Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE); |
|
| 502 | + Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE); |
|
| 503 | 503 | |
| 504 | - if ($favicon_needs_check || $force_refetch) { |
|
| 504 | + if ($favicon_needs_check || $force_refetch) { |
|
| 505 | 505 | |
| 506 | - /* terrible hack: if we crash on floicon shit here, we won't check |
|
| 506 | + /* terrible hack: if we crash on floicon shit here, we won't check |
|
| 507 | 507 | * the icon avgcolor again (unless the icon got updated) */ |
| 508 | 508 | |
| 509 | - $favicon_file = ICONS_DIR . "/$feed.ico"; |
|
| 510 | - $favicon_modified = @filemtime($favicon_file); |
|
| 509 | + $favicon_file = ICONS_DIR . "/$feed.ico"; |
|
| 510 | + $favicon_modified = @filemtime($favicon_file); |
|
| 511 | 511 | |
| 512 | - Debug::log("checking favicon...", Debug::$LOG_VERBOSE); |
|
| 512 | + Debug::log("checking favicon...", Debug::$LOG_VERBOSE); |
|
| 513 | 513 | |
| 514 | - RSSUtils::check_feed_favicon($site_url, $feed); |
|
| 515 | - $favicon_modified_new = @filemtime($favicon_file); |
|
| 514 | + RSSUtils::check_feed_favicon($site_url, $feed); |
|
| 515 | + $favicon_modified_new = @filemtime($favicon_file); |
|
| 516 | 516 | |
| 517 | - if ($favicon_modified_new > $favicon_modified) |
|
| 518 | - $favicon_avg_color = ''; |
|
| 517 | + if ($favicon_modified_new > $favicon_modified) |
|
| 518 | + $favicon_avg_color = ''; |
|
| 519 | 519 | |
| 520 | - $favicon_colorstring = ""; |
|
| 521 | - if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') { |
|
| 522 | - require_once "colors.php"; |
|
| 520 | + $favicon_colorstring = ""; |
|
| 521 | + if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') { |
|
| 522 | + require_once "colors.php"; |
|
| 523 | 523 | |
| 524 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE |
|
| 524 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE |
|
| 525 | 525 | id = ?"); |
| 526 | - $sth->execute([$feed]); |
|
| 526 | + $sth->execute([$feed]); |
|
| 527 | 527 | |
| 528 | - $favicon_color = calculate_avg_color($favicon_file); |
|
| 528 | + $favicon_color = calculate_avg_color($favicon_file); |
|
| 529 | 529 | |
| 530 | - $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color); |
|
| 530 | + $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color); |
|
| 531 | 531 | |
| 532 | - } else if ($favicon_avg_color == 'fail') { |
|
| 533 | - Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE); |
|
| 534 | - } |
|
| 532 | + } else if ($favicon_avg_color == 'fail') { |
|
| 533 | + Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE); |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW() |
|
| 536 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW() |
|
| 537 | 537 | $favicon_colorstring WHERE id = ?"); |
| 538 | - $sth->execute([$feed]); |
|
| 539 | - } |
|
| 538 | + $sth->execute([$feed]); |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE); |
|
| 541 | + Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE); |
|
| 542 | 542 | |
| 543 | - $filters = RSSUtils::load_filters($feed, $owner_uid); |
|
| 543 | + $filters = RSSUtils::load_filters($feed, $owner_uid); |
|
| 544 | 544 | |
| 545 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 546 | - print_r($filters); |
|
| 547 | - } |
|
| 545 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 546 | + print_r($filters); |
|
| 547 | + } |
|
| 548 | 548 | |
| 549 | - Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE); |
|
| 549 | + Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE); |
|
| 550 | 550 | |
| 551 | - $items = $rss->get_items(); |
|
| 551 | + $items = $rss->get_items(); |
|
| 552 | 552 | |
| 553 | - if (!is_array($items)) { |
|
| 554 | - Debug::log("no articles found.", Debug::$LOG_VERBOSE); |
|
| 553 | + if (!is_array($items)) { |
|
| 554 | + Debug::log("no articles found.", Debug::$LOG_VERBOSE); |
|
| 555 | 555 | |
| 556 | - $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
| 556 | + $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
| 557 | 557 | SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?"); |
| 558 | - $sth->execute([$feed]); |
|
| 558 | + $sth->execute([$feed]); |
|
| 559 | 559 | |
| 560 | - return true; // no articles |
|
| 561 | - } |
|
| 560 | + return true; // no articles |
|
| 561 | + } |
|
| 562 | 562 | |
| 563 | - Debug::log("processing articles...", Debug::$LOG_VERBOSE); |
|
| 563 | + Debug::log("processing articles...", Debug::$LOG_VERBOSE); |
|
| 564 | 564 | |
| 565 | - $tstart = time(); |
|
| 565 | + $tstart = time(); |
|
| 566 | 566 | |
| 567 | - foreach ($items as $item) { |
|
| 568 | - $pdo->beginTransaction(); |
|
| 567 | + foreach ($items as $item) { |
|
| 568 | + $pdo->beginTransaction(); |
|
| 569 | 569 | |
| 570 | - if (Debug::get_loglevel() >= 3) { |
|
| 571 | - print_r($item); |
|
| 572 | - } |
|
| 570 | + if (Debug::get_loglevel() >= 3) { |
|
| 571 | + print_r($item); |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | - if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) { |
|
| 575 | - Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE); |
|
| 576 | - $pdo->commit(); |
|
| 577 | - break; |
|
| 578 | - } |
|
| 574 | + if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) { |
|
| 575 | + Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE); |
|
| 576 | + $pdo->commit(); |
|
| 577 | + break; |
|
| 578 | + } |
|
| 579 | 579 | |
| 580 | - $entry_guid = strip_tags($item->get_id()); |
|
| 581 | - if (!$entry_guid) $entry_guid = strip_tags($item->get_link()); |
|
| 582 | - if (!$entry_guid) $entry_guid = RSSUtils::make_guid_from_title($item->get_title()); |
|
| 580 | + $entry_guid = strip_tags($item->get_id()); |
|
| 581 | + if (!$entry_guid) $entry_guid = strip_tags($item->get_link()); |
|
| 582 | + if (!$entry_guid) $entry_guid = RSSUtils::make_guid_from_title($item->get_title()); |
|
| 583 | 583 | |
| 584 | - if (!$entry_guid) { |
|
| 585 | - $pdo->commit(); |
|
| 586 | - continue; |
|
| 587 | - } |
|
| 584 | + if (!$entry_guid) { |
|
| 585 | + $pdo->commit(); |
|
| 586 | + continue; |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - $entry_guid = "$owner_uid,$entry_guid"; |
|
| 589 | + $entry_guid = "$owner_uid,$entry_guid"; |
|
| 590 | 590 | |
| 591 | - $entry_guid_hashed = 'SHA1:' . sha1($entry_guid); |
|
| 591 | + $entry_guid_hashed = 'SHA1:' . sha1($entry_guid); |
|
| 592 | 592 | |
| 593 | - Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE); |
|
| 593 | + Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE); |
|
| 594 | 594 | |
| 595 | - $entry_timestamp = (int)$item->get_date(); |
|
| 595 | + $entry_timestamp = (int)$item->get_date(); |
|
| 596 | 596 | |
| 597 | - Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE); |
|
| 597 | + Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE); |
|
| 598 | 598 | |
| 599 | - $entry_title = strip_tags($item->get_title()); |
|
| 599 | + $entry_title = strip_tags($item->get_title()); |
|
| 600 | 600 | |
| 601 | - $entry_link = rewrite_relative_url($site_url, clean($item->get_link())); |
|
| 601 | + $entry_link = rewrite_relative_url($site_url, clean($item->get_link())); |
|
| 602 | 602 | |
| 603 | - $entry_language = mb_substr(trim($item->get_language()), 0, 2); |
|
| 603 | + $entry_language = mb_substr(trim($item->get_language()), 0, 2); |
|
| 604 | 604 | |
| 605 | - Debug::log("title $entry_title", Debug::$LOG_VERBOSE); |
|
| 606 | - Debug::log("link $entry_link", Debug::$LOG_VERBOSE); |
|
| 607 | - Debug::log("language $entry_language", Debug::$LOG_VERBOSE); |
|
| 605 | + Debug::log("title $entry_title", Debug::$LOG_VERBOSE); |
|
| 606 | + Debug::log("link $entry_link", Debug::$LOG_VERBOSE); |
|
| 607 | + Debug::log("language $entry_language", Debug::$LOG_VERBOSE); |
|
| 608 | 608 | |
| 609 | - if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; |
|
| 609 | + if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; |
|
| 610 | 610 | |
| 611 | - $entry_content = $item->get_content(); |
|
| 612 | - if (!$entry_content) $entry_content = $item->get_description(); |
|
| 611 | + $entry_content = $item->get_content(); |
|
| 612 | + if (!$entry_content) $entry_content = $item->get_description(); |
|
| 613 | 613 | |
| 614 | - if (Debug::get_loglevel() >= 3) { |
|
| 615 | - print "content: "; |
|
| 616 | - print htmlspecialchars($entry_content); |
|
| 617 | - print "\n"; |
|
| 618 | - } |
|
| 614 | + if (Debug::get_loglevel() >= 3) { |
|
| 615 | + print "content: "; |
|
| 616 | + print htmlspecialchars($entry_content); |
|
| 617 | + print "\n"; |
|
| 618 | + } |
|
| 619 | 619 | |
| 620 | - $entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245); |
|
| 621 | - $num_comments = (int) $item->get_comments_count(); |
|
| 620 | + $entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245); |
|
| 621 | + $num_comments = (int) $item->get_comments_count(); |
|
| 622 | 622 | |
| 623 | - $entry_author = strip_tags($item->get_author()); |
|
| 624 | - $entry_guid = mb_substr($entry_guid, 0, 245); |
|
| 623 | + $entry_author = strip_tags($item->get_author()); |
|
| 624 | + $entry_guid = mb_substr($entry_guid, 0, 245); |
|
| 625 | 625 | |
| 626 | - Debug::log("author $entry_author", Debug::$LOG_VERBOSE); |
|
| 627 | - Debug::log("looking for tags...", Debug::$LOG_VERBOSE); |
|
| 626 | + Debug::log("author $entry_author", Debug::$LOG_VERBOSE); |
|
| 627 | + Debug::log("looking for tags...", Debug::$LOG_VERBOSE); |
|
| 628 | 628 | |
| 629 | - $entry_tags = $item->get_categories(); |
|
| 630 | - Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE); |
|
| 629 | + $entry_tags = $item->get_categories(); |
|
| 630 | + Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE); |
|
| 631 | 631 | |
| 632 | - Debug::log("done collecting data.", Debug::$LOG_VERBOSE); |
|
| 632 | + Debug::log("done collecting data.", Debug::$LOG_VERBOSE); |
|
| 633 | 633 | |
| 634 | - $sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries |
|
| 634 | + $sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries |
|
| 635 | 635 | WHERE guid = ? OR guid = ?"); |
| 636 | - $sth->execute([$entry_guid, $entry_guid_hashed]); |
|
| 637 | - |
|
| 638 | - if ($row = $sth->fetch()) { |
|
| 639 | - $base_entry_id = $row["id"]; |
|
| 640 | - $entry_stored_hash = $row["content_hash"]; |
|
| 641 | - $article_labels = Article::get_article_labels($base_entry_id, $owner_uid); |
|
| 642 | - |
|
| 643 | - $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid); |
|
| 644 | - $entry_tags = array_unique(array_merge($entry_tags, $existing_tags)); |
|
| 645 | - } else { |
|
| 646 | - $base_entry_id = false; |
|
| 647 | - $entry_stored_hash = ""; |
|
| 648 | - $article_labels = array(); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - $article = array("owner_uid" => $owner_uid, // read only |
|
| 652 | - "guid" => $entry_guid, // read only |
|
| 653 | - "guid_hashed" => $entry_guid_hashed, // read only |
|
| 654 | - "title" => $entry_title, |
|
| 655 | - "content" => $entry_content, |
|
| 656 | - "link" => $entry_link, |
|
| 657 | - "labels" => $article_labels, // current limitation: can add labels to article, can't remove them |
|
| 658 | - "tags" => $entry_tags, |
|
| 659 | - "author" => $entry_author, |
|
| 660 | - "force_catchup" => false, // ugly hack for the time being |
|
| 661 | - "score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed |
|
| 662 | - "language" => $entry_language, |
|
| 663 | - "timestamp" => $entry_timestamp, |
|
| 664 | - "num_comments" => $num_comments, |
|
| 665 | - "feed" => array("id" => $feed, |
|
| 666 | - "fetch_url" => $fetch_url, |
|
| 667 | - "site_url" => $site_url, |
|
| 668 | - "cache_images" => $cache_images) |
|
| 669 | - ); |
|
| 670 | - |
|
| 671 | - $entry_plugin_data = ""; |
|
| 672 | - $entry_current_hash = RSSUtils::calculate_article_hash($article, $pluginhost); |
|
| 673 | - |
|
| 674 | - Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE); |
|
| 675 | - |
|
| 676 | - if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) { |
|
| 677 | - Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE); |
|
| 678 | - |
|
| 679 | - // we keep encountering the entry in feeds, so we need to |
|
| 680 | - // update date_updated column so that we don't get horrible |
|
| 681 | - // dupes when the entry gets purged and reinserted again e.g. |
|
| 682 | - // in the case of SLOW SLOW OMG SLOW updating feeds |
|
| 683 | - |
|
| 684 | - $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW() |
|
| 636 | + $sth->execute([$entry_guid, $entry_guid_hashed]); |
|
| 637 | + |
|
| 638 | + if ($row = $sth->fetch()) { |
|
| 639 | + $base_entry_id = $row["id"]; |
|
| 640 | + $entry_stored_hash = $row["content_hash"]; |
|
| 641 | + $article_labels = Article::get_article_labels($base_entry_id, $owner_uid); |
|
| 642 | + |
|
| 643 | + $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid); |
|
| 644 | + $entry_tags = array_unique(array_merge($entry_tags, $existing_tags)); |
|
| 645 | + } else { |
|
| 646 | + $base_entry_id = false; |
|
| 647 | + $entry_stored_hash = ""; |
|
| 648 | + $article_labels = array(); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + $article = array("owner_uid" => $owner_uid, // read only |
|
| 652 | + "guid" => $entry_guid, // read only |
|
| 653 | + "guid_hashed" => $entry_guid_hashed, // read only |
|
| 654 | + "title" => $entry_title, |
|
| 655 | + "content" => $entry_content, |
|
| 656 | + "link" => $entry_link, |
|
| 657 | + "labels" => $article_labels, // current limitation: can add labels to article, can't remove them |
|
| 658 | + "tags" => $entry_tags, |
|
| 659 | + "author" => $entry_author, |
|
| 660 | + "force_catchup" => false, // ugly hack for the time being |
|
| 661 | + "score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed |
|
| 662 | + "language" => $entry_language, |
|
| 663 | + "timestamp" => $entry_timestamp, |
|
| 664 | + "num_comments" => $num_comments, |
|
| 665 | + "feed" => array("id" => $feed, |
|
| 666 | + "fetch_url" => $fetch_url, |
|
| 667 | + "site_url" => $site_url, |
|
| 668 | + "cache_images" => $cache_images) |
|
| 669 | + ); |
|
| 670 | + |
|
| 671 | + $entry_plugin_data = ""; |
|
| 672 | + $entry_current_hash = RSSUtils::calculate_article_hash($article, $pluginhost); |
|
| 673 | + |
|
| 674 | + Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE); |
|
| 675 | + |
|
| 676 | + if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) { |
|
| 677 | + Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE); |
|
| 678 | + |
|
| 679 | + // we keep encountering the entry in feeds, so we need to |
|
| 680 | + // update date_updated column so that we don't get horrible |
|
| 681 | + // dupes when the entry gets purged and reinserted again e.g. |
|
| 682 | + // in the case of SLOW SLOW OMG SLOW updating feeds |
|
| 683 | + |
|
| 684 | + $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW() |
|
| 685 | 685 | WHERE id = ?"); |
| 686 | - $sth->execute([$base_entry_id]); |
|
| 686 | + $sth->execute([$base_entry_id]); |
|
| 687 | 687 | |
| 688 | - $pdo->commit(); |
|
| 689 | - continue; |
|
| 690 | - } |
|
| 688 | + $pdo->commit(); |
|
| 689 | + continue; |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | - Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE); |
|
| 692 | + Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE); |
|
| 693 | 693 | |
| 694 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) { |
|
| 695 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 694 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) { |
|
| 695 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
| 696 | 696 | |
| 697 | - $start = microtime(true); |
|
| 698 | - $article = $plugin->hook_article_filter($article); |
|
| 697 | + $start = microtime(true); |
|
| 698 | + $article = $plugin->hook_article_filter($article); |
|
| 699 | 699 | |
| 700 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 700 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 701 | 701 | |
| 702 | - $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ","; |
|
| 703 | - } |
|
| 702 | + $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ","; |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | 705 | if (Debug::get_loglevel() >= 3) { |
| 706 | - print "processed content: "; |
|
| 707 | - print htmlspecialchars($article["content"]); |
|
| 708 | - print "\n"; |
|
| 709 | - } |
|
| 706 | + print "processed content: "; |
|
| 707 | + print htmlspecialchars($article["content"]); |
|
| 708 | + print "\n"; |
|
| 709 | + } |
|
| 710 | 710 | |
| 711 | - Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE); |
|
| 711 | + Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE); |
|
| 712 | 712 | |
| 713 | - // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077 |
|
| 714 | - if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
| 715 | - foreach ($article as $k => $v) { |
|
| 716 | - // i guess we'll have to take the risk of 4byte unicode labels & tags here |
|
| 717 | - if (is_string($article[$k])) { |
|
| 718 | - $article[$k] = RSSUtils::strip_utf8mb4($v); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - } |
|
| 713 | + // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077 |
|
| 714 | + if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
| 715 | + foreach ($article as $k => $v) { |
|
| 716 | + // i guess we'll have to take the risk of 4byte unicode labels & tags here |
|
| 717 | + if (is_string($article[$k])) { |
|
| 718 | + $article[$k] = RSSUtils::strip_utf8mb4($v); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | - /* Collect article tags here so we could filter by them: */ |
|
| 723 | + /* Collect article tags here so we could filter by them: */ |
|
| 724 | 724 | |
| 725 | - $matched_rules = []; |
|
| 726 | - $matched_filters = []; |
|
| 725 | + $matched_rules = []; |
|
| 726 | + $matched_filters = []; |
|
| 727 | 727 | |
| 728 | - $article_filters = RSSUtils::get_article_filters($filters, $article["title"], |
|
| 729 | - $article["content"], $article["link"], $article["author"], |
|
| 730 | - $article["tags"], $matched_rules, $matched_filters); |
|
| 728 | + $article_filters = RSSUtils::get_article_filters($filters, $article["title"], |
|
| 729 | + $article["content"], $article["link"], $article["author"], |
|
| 730 | + $article["tags"], $matched_rules, $matched_filters); |
|
| 731 | 731 | |
| 732 | - // $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters |
|
| 733 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) { |
|
| 734 | - $plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters); |
|
| 735 | - } |
|
| 732 | + // $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters |
|
| 733 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) { |
|
| 734 | + $plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters); |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - $matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters); |
|
| 737 | + $matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters); |
|
| 738 | 738 | |
| 739 | - if (count($matched_filter_ids) > 0) { |
|
| 740 | - $filter_ids_qmarks = arr_qmarks($matched_filter_ids); |
|
| 739 | + if (count($matched_filter_ids) > 0) { |
|
| 740 | + $filter_ids_qmarks = arr_qmarks($matched_filter_ids); |
|
| 741 | 741 | |
| 742 | - $fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE |
|
| 742 | + $fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE |
|
| 743 | 743 | id IN ($filter_ids_qmarks) AND owner_uid = ?"); |
| 744 | 744 | |
| 745 | - $fsth->execute(array_merge($matched_filter_ids, [$owner_uid])); |
|
| 746 | - } |
|
| 745 | + $fsth->execute(array_merge($matched_filter_ids, [$owner_uid])); |
|
| 746 | + } |
|
| 747 | 747 | |
| 748 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 749 | - Debug::log("matched filters: ", Debug::$LOG_VERBOSE); |
|
| 748 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 749 | + Debug::log("matched filters: ", Debug::$LOG_VERBOSE); |
|
| 750 | 750 | |
| 751 | - if (count($matched_filters != 0)) { |
|
| 752 | - print_r($matched_filters); |
|
| 753 | - } |
|
| 751 | + if (count($matched_filters != 0)) { |
|
| 752 | + print_r($matched_filters); |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE); |
|
| 755 | + Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE); |
|
| 756 | 756 | |
| 757 | - if (count($matched_rules) != 0) { |
|
| 758 | - print_r($matched_rules); |
|
| 759 | - } |
|
| 757 | + if (count($matched_rules) != 0) { |
|
| 758 | + print_r($matched_rules); |
|
| 759 | + } |
|
| 760 | 760 | |
| 761 | - Debug::log("filter actions: ", Debug::$LOG_VERBOSE); |
|
| 761 | + Debug::log("filter actions: ", Debug::$LOG_VERBOSE); |
|
| 762 | 762 | |
| 763 | - if (count($article_filters) != 0) { |
|
| 764 | - print_r($article_filters); |
|
| 765 | - } |
|
| 766 | - } |
|
| 763 | + if (count($article_filters) != 0) { |
|
| 764 | + print_r($article_filters); |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - $plugin_filter_names = RSSUtils::find_article_filters($article_filters, "plugin"); |
|
| 769 | - $plugin_filter_actions = $pluginhost->get_filter_actions(); |
|
| 768 | + $plugin_filter_names = RSSUtils::find_article_filters($article_filters, "plugin"); |
|
| 769 | + $plugin_filter_actions = $pluginhost->get_filter_actions(); |
|
| 770 | 770 | |
| 771 | - if (count($plugin_filter_names) > 0) { |
|
| 772 | - Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE); |
|
| 771 | + if (count($plugin_filter_names) > 0) { |
|
| 772 | + Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE); |
|
| 773 | 773 | |
| 774 | - foreach ($plugin_filter_names as $pfn) { |
|
| 775 | - list($pfclass,$pfaction) = explode(":", $pfn["param"]); |
|
| 774 | + foreach ($plugin_filter_names as $pfn) { |
|
| 775 | + list($pfclass,$pfaction) = explode(":", $pfn["param"]); |
|
| 776 | 776 | |
| 777 | - if (isset($plugin_filter_actions[$pfclass])) { |
|
| 778 | - $plugin = $pluginhost->get_plugin($pfclass); |
|
| 777 | + if (isset($plugin_filter_actions[$pfclass])) { |
|
| 778 | + $plugin = $pluginhost->get_plugin($pfclass); |
|
| 779 | 779 | |
| 780 | - Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE); |
|
| 780 | + Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE); |
|
| 781 | 781 | |
| 782 | - if ($plugin) { |
|
| 783 | - $start = microtime(true); |
|
| 784 | - $article = $plugin->hook_article_filter_action($article, $pfaction); |
|
| 782 | + if ($plugin) { |
|
| 783 | + $start = microtime(true); |
|
| 784 | + $article = $plugin->hook_article_filter_action($article, $pfaction); |
|
| 785 | 785 | |
| 786 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 787 | - } else { |
|
| 788 | - Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE); |
|
| 789 | - } |
|
| 790 | - } else { |
|
| 791 | - Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE); |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } |
|
| 786 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
| 787 | + } else { |
|
| 788 | + Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE); |
|
| 789 | + } |
|
| 790 | + } else { |
|
| 791 | + Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE); |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | - $entry_tags = $article["tags"]; |
|
| 797 | - $entry_title = strip_tags($article["title"]); |
|
| 798 | - $entry_author = mb_substr(strip_tags($article["author"]), 0, 245); |
|
| 799 | - $entry_link = strip_tags($article["link"]); |
|
| 800 | - $entry_content = $article["content"]; // escaped below |
|
| 801 | - $entry_force_catchup = $article["force_catchup"]; |
|
| 802 | - $article_labels = $article["labels"]; |
|
| 803 | - $entry_score_modifier = (int) $article["score_modifier"]; |
|
| 804 | - $entry_language = $article["language"]; |
|
| 805 | - $entry_timestamp = $article["timestamp"]; |
|
| 806 | - $num_comments = $article["num_comments"]; |
|
| 796 | + $entry_tags = $article["tags"]; |
|
| 797 | + $entry_title = strip_tags($article["title"]); |
|
| 798 | + $entry_author = mb_substr(strip_tags($article["author"]), 0, 245); |
|
| 799 | + $entry_link = strip_tags($article["link"]); |
|
| 800 | + $entry_content = $article["content"]; // escaped below |
|
| 801 | + $entry_force_catchup = $article["force_catchup"]; |
|
| 802 | + $article_labels = $article["labels"]; |
|
| 803 | + $entry_score_modifier = (int) $article["score_modifier"]; |
|
| 804 | + $entry_language = $article["language"]; |
|
| 805 | + $entry_timestamp = $article["timestamp"]; |
|
| 806 | + $num_comments = $article["num_comments"]; |
|
| 807 | 807 | |
| 808 | - if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) { |
|
| 809 | - $entry_timestamp = time(); |
|
| 810 | - } |
|
| 808 | + if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) { |
|
| 809 | + $entry_timestamp = time(); |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | - $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); |
|
| 812 | + $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); |
|
| 813 | 813 | |
| 814 | - Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE); |
|
| 815 | - Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE); |
|
| 814 | + Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE); |
|
| 815 | + Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE); |
|
| 816 | 816 | |
| 817 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 818 | - Debug::log("article labels:", Debug::$LOG_VERBOSE); |
|
| 817 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 818 | + Debug::log("article labels:", Debug::$LOG_VERBOSE); |
|
| 819 | 819 | |
| 820 | - if (count($article_labels) != 0) { |
|
| 821 | - print_r($article_labels); |
|
| 822 | - } |
|
| 823 | - } |
|
| 820 | + if (count($article_labels) != 0) { |
|
| 821 | + print_r($article_labels); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE); |
|
| 825 | + Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE); |
|
| 826 | 826 | |
| 827 | - if ($cache_images) |
|
| 828 | - RSSUtils::cache_media($entry_content, $site_url); |
|
| 827 | + if ($cache_images) |
|
| 828 | + RSSUtils::cache_media($entry_content, $site_url); |
|
| 829 | 829 | |
| 830 | - $csth = $pdo->prepare("SELECT id FROM ttrss_entries |
|
| 830 | + $csth = $pdo->prepare("SELECT id FROM ttrss_entries |
|
| 831 | 831 | WHERE guid = ? OR guid = ?"); |
| 832 | - $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
| 832 | + $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
| 833 | 833 | |
| 834 | - if (!$row = $csth->fetch()) { |
|
| 834 | + if (!$row = $csth->fetch()) { |
|
| 835 | 835 | |
| 836 | - Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE); |
|
| 836 | + Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE); |
|
| 837 | 837 | |
| 838 | - // base post entry does not exist, create it |
|
| 838 | + // base post entry does not exist, create it |
|
| 839 | 839 | |
| 840 | - $usth = $pdo->prepare( |
|
| 841 | - "INSERT INTO ttrss_entries |
|
| 840 | + $usth = $pdo->prepare( |
|
| 841 | + "INSERT INTO ttrss_entries |
|
| 842 | 842 | (title, |
| 843 | 843 | guid, |
| 844 | 844 | link, |
@@ -859,110 +859,110 @@ discard block |
||
| 859 | 859 | NOW(), |
| 860 | 860 | ?, ?, ?, ?, ?, ?)"); |
| 861 | 861 | |
| 862 | - $usth->execute([$entry_title, |
|
| 863 | - $entry_guid_hashed, |
|
| 864 | - $entry_link, |
|
| 865 | - $entry_timestamp_fmt, |
|
| 866 | - "$entry_content", |
|
| 867 | - $entry_current_hash, |
|
| 868 | - $date_feed_processed, |
|
| 869 | - $entry_comments, |
|
| 870 | - (int)$num_comments, |
|
| 871 | - $entry_plugin_data, |
|
| 872 | - "$entry_language", |
|
| 873 | - "$entry_author"]); |
|
| 862 | + $usth->execute([$entry_title, |
|
| 863 | + $entry_guid_hashed, |
|
| 864 | + $entry_link, |
|
| 865 | + $entry_timestamp_fmt, |
|
| 866 | + "$entry_content", |
|
| 867 | + $entry_current_hash, |
|
| 868 | + $date_feed_processed, |
|
| 869 | + $entry_comments, |
|
| 870 | + (int)$num_comments, |
|
| 871 | + $entry_plugin_data, |
|
| 872 | + "$entry_language", |
|
| 873 | + "$entry_author"]); |
|
| 874 | 874 | |
| 875 | - } |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | - $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
| 877 | + $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
| 878 | 878 | |
| 879 | - $entry_ref_id = 0; |
|
| 880 | - $entry_int_id = 0; |
|
| 879 | + $entry_ref_id = 0; |
|
| 880 | + $entry_int_id = 0; |
|
| 881 | 881 | |
| 882 | - if ($row = $csth->fetch()) { |
|
| 882 | + if ($row = $csth->fetch()) { |
|
| 883 | 883 | |
| 884 | - Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE); |
|
| 884 | + Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE); |
|
| 885 | 885 | |
| 886 | - $ref_id = $row['id']; |
|
| 887 | - $entry_ref_id = $ref_id; |
|
| 886 | + $ref_id = $row['id']; |
|
| 887 | + $entry_ref_id = $ref_id; |
|
| 888 | 888 | |
| 889 | - if (RSSUtils::find_article_filter($article_filters, "filter")) { |
|
| 890 | - Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE); |
|
| 891 | - $pdo->commit(); |
|
| 892 | - continue; |
|
| 893 | - } |
|
| 889 | + if (RSSUtils::find_article_filter($article_filters, "filter")) { |
|
| 890 | + Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE); |
|
| 891 | + $pdo->commit(); |
|
| 892 | + continue; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - $score = RSSUtils::calculate_article_score($article_filters) + $entry_score_modifier; |
|
| 895 | + $score = RSSUtils::calculate_article_score($article_filters) + $entry_score_modifier; |
|
| 896 | 896 | |
| 897 | - Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE); |
|
| 897 | + Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE); |
|
| 898 | 898 | |
| 899 | - // check for user post link to main table |
|
| 899 | + // check for user post link to main table |
|
| 900 | 900 | |
| 901 | - $sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE |
|
| 901 | + $sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE |
|
| 902 | 902 | ref_id = ? AND owner_uid = ?"); |
| 903 | - $sth->execute([$ref_id, $owner_uid]); |
|
| 904 | - |
|
| 905 | - // okay it doesn't exist - create user entry |
|
| 906 | - if ($row = $sth->fetch()) { |
|
| 907 | - $entry_ref_id = $row["ref_id"]; |
|
| 908 | - $entry_int_id = $row["int_id"]; |
|
| 909 | - |
|
| 910 | - Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
| 911 | - } else { |
|
| 912 | - |
|
| 913 | - Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE); |
|
| 914 | - |
|
| 915 | - if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) { |
|
| 916 | - $unread = 1; |
|
| 917 | - $last_read_qpart = null; |
|
| 918 | - } else { |
|
| 919 | - $unread = 0; |
|
| 920 | - $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) { |
|
| 924 | - $marked = 1; |
|
| 925 | - } else { |
|
| 926 | - $marked = 0; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - if (RSSUtils::find_article_filter($article_filters, 'publish')) { |
|
| 930 | - $published = 1; |
|
| 931 | - } else { |
|
| 932 | - $published = 0; |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - $last_marked = ($marked == 1) ? 'NOW()' : 'NULL'; |
|
| 936 | - $last_published = ($published == 1) ? 'NOW()' : 'NULL'; |
|
| 937 | - |
|
| 938 | - $sth = $pdo->prepare( |
|
| 939 | - "INSERT INTO ttrss_user_entries |
|
| 903 | + $sth->execute([$ref_id, $owner_uid]); |
|
| 904 | + |
|
| 905 | + // okay it doesn't exist - create user entry |
|
| 906 | + if ($row = $sth->fetch()) { |
|
| 907 | + $entry_ref_id = $row["ref_id"]; |
|
| 908 | + $entry_int_id = $row["int_id"]; |
|
| 909 | + |
|
| 910 | + Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
| 911 | + } else { |
|
| 912 | + |
|
| 913 | + Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE); |
|
| 914 | + |
|
| 915 | + if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) { |
|
| 916 | + $unread = 1; |
|
| 917 | + $last_read_qpart = null; |
|
| 918 | + } else { |
|
| 919 | + $unread = 0; |
|
| 920 | + $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) { |
|
| 924 | + $marked = 1; |
|
| 925 | + } else { |
|
| 926 | + $marked = 0; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + if (RSSUtils::find_article_filter($article_filters, 'publish')) { |
|
| 930 | + $published = 1; |
|
| 931 | + } else { |
|
| 932 | + $published = 0; |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + $last_marked = ($marked == 1) ? 'NOW()' : 'NULL'; |
|
| 936 | + $last_published = ($published == 1) ? 'NOW()' : 'NULL'; |
|
| 937 | + |
|
| 938 | + $sth = $pdo->prepare( |
|
| 939 | + "INSERT INTO ttrss_user_entries |
|
| 940 | 940 | (ref_id, owner_uid, feed_id, unread, last_read, marked, |
| 941 | 941 | published, score, tag_cache, label_cache, uuid, |
| 942 | 942 | last_marked, last_published) |
| 943 | 943 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ".$last_marked.", ".$last_published.")"); |
| 944 | 944 | |
| 945 | - $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked, |
|
| 946 | - $published, $score]); |
|
| 945 | + $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked, |
|
| 946 | + $published, $score]); |
|
| 947 | 947 | |
| 948 | - $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
| 948 | + $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
| 949 | 949 | ref_id = ? AND owner_uid = ? AND |
| 950 | 950 | feed_id = ? LIMIT 1"); |
| 951 | 951 | |
| 952 | - $sth->execute([$ref_id, $owner_uid, $feed]); |
|
| 952 | + $sth->execute([$ref_id, $owner_uid, $feed]); |
|
| 953 | 953 | |
| 954 | - if ($row = $sth->fetch()) |
|
| 955 | - $entry_int_id = $row['int_id']; |
|
| 956 | - } |
|
| 954 | + if ($row = $sth->fetch()) |
|
| 955 | + $entry_int_id = $row['int_id']; |
|
| 956 | + } |
|
| 957 | 957 | |
| 958 | - Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
| 958 | + Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
| 959 | 959 | |
| 960 | - if (DB_TYPE == "pgsql") |
|
| 961 | - $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; |
|
| 962 | - else |
|
| 963 | - $tsvector_qpart = ""; |
|
| 960 | + if (DB_TYPE == "pgsql") |
|
| 961 | + $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; |
|
| 962 | + else |
|
| 963 | + $tsvector_qpart = ""; |
|
| 964 | 964 | |
| 965 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
| 965 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
| 966 | 966 | SET title = :title, |
| 967 | 967 | $tsvector_qpart |
| 968 | 968 | content = :content, |
@@ -975,634 +975,634 @@ discard block |
||
| 975 | 975 | lang = :lang |
| 976 | 976 | WHERE id = :id"); |
| 977 | 977 | |
| 978 | - $params = [":title" => $entry_title, |
|
| 979 | - ":content" => "$entry_content", |
|
| 980 | - ":content_hash" => $entry_current_hash, |
|
| 981 | - ":updated" => $entry_timestamp_fmt, |
|
| 982 | - ":num_comments" => (int)$num_comments, |
|
| 983 | - ":plugin_data" => $entry_plugin_data, |
|
| 984 | - ":author" => "$entry_author", |
|
| 985 | - ":lang" => $entry_language, |
|
| 986 | - ":id" => $ref_id]; |
|
| 987 | - |
|
| 988 | - if (DB_TYPE == "pgsql") { |
|
| 989 | - $params[":ts_lang"] = $feed_language; |
|
| 990 | - $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000); |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - $sth->execute($params); |
|
| 994 | - |
|
| 995 | - // update aux data |
|
| 996 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 978 | + $params = [":title" => $entry_title, |
|
| 979 | + ":content" => "$entry_content", |
|
| 980 | + ":content_hash" => $entry_current_hash, |
|
| 981 | + ":updated" => $entry_timestamp_fmt, |
|
| 982 | + ":num_comments" => (int)$num_comments, |
|
| 983 | + ":plugin_data" => $entry_plugin_data, |
|
| 984 | + ":author" => "$entry_author", |
|
| 985 | + ":lang" => $entry_language, |
|
| 986 | + ":id" => $ref_id]; |
|
| 987 | + |
|
| 988 | + if (DB_TYPE == "pgsql") { |
|
| 989 | + $params[":ts_lang"] = $feed_language; |
|
| 990 | + $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000); |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + $sth->execute($params); |
|
| 994 | + |
|
| 995 | + // update aux data |
|
| 996 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 997 | 997 | SET score = ? WHERE ref_id = ?"); |
| 998 | - $sth->execute([$score, $ref_id]); |
|
| 998 | + $sth->execute([$score, $ref_id]); |
|
| 999 | 999 | |
| 1000 | - if ($mark_unread_on_update && |
|
| 1001 | - !$entry_force_catchup && |
|
| 1002 | - !RSSUtils::find_article_filter($article_filters, 'catchup')) { |
|
| 1000 | + if ($mark_unread_on_update && |
|
| 1001 | + !$entry_force_catchup && |
|
| 1002 | + !RSSUtils::find_article_filter($article_filters, 'catchup')) { |
|
| 1003 | 1003 | |
| 1004 | - Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE); |
|
| 1004 | + Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE); |
|
| 1005 | 1005 | |
| 1006 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1006 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1007 | 1007 | SET last_read = null, unread = true WHERE ref_id = ?"); |
| 1008 | - $sth->execute([$ref_id]); |
|
| 1009 | - } else { |
|
| 1010 | - Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE); |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1008 | + $sth->execute([$ref_id]); |
|
| 1009 | + } else { |
|
| 1010 | + Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE); |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | 1013 | |
| 1014 | - Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE); |
|
| 1014 | + Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE); |
|
| 1015 | 1015 | |
| 1016 | - foreach ($article_labels as $label) { |
|
| 1017 | - Labels::add_article($entry_ref_id, $label[1], $owner_uid); |
|
| 1018 | - } |
|
| 1016 | + foreach ($article_labels as $label) { |
|
| 1017 | + Labels::add_article($entry_ref_id, $label[1], $owner_uid); |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | - Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE); |
|
| 1020 | + Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE); |
|
| 1021 | 1021 | |
| 1022 | - RSSUtils::assign_article_to_label_filters($entry_ref_id, $article_filters, |
|
| 1023 | - $owner_uid, $article_labels); |
|
| 1022 | + RSSUtils::assign_article_to_label_filters($entry_ref_id, $article_filters, |
|
| 1023 | + $owner_uid, $article_labels); |
|
| 1024 | 1024 | |
| 1025 | - Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE); |
|
| 1025 | + Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE); |
|
| 1026 | 1026 | |
| 1027 | - // enclosures |
|
| 1027 | + // enclosures |
|
| 1028 | 1028 | |
| 1029 | - $enclosures = array(); |
|
| 1029 | + $enclosures = array(); |
|
| 1030 | 1030 | |
| 1031 | - $encs = $item->get_enclosures(); |
|
| 1031 | + $encs = $item->get_enclosures(); |
|
| 1032 | 1032 | |
| 1033 | - if (is_array($encs)) { |
|
| 1034 | - foreach ($encs as $e) { |
|
| 1035 | - $e_item = array( |
|
| 1036 | - rewrite_relative_url($site_url, $e->link), |
|
| 1037 | - $e->type, $e->length, $e->title, $e->width, $e->height); |
|
| 1033 | + if (is_array($encs)) { |
|
| 1034 | + foreach ($encs as $e) { |
|
| 1035 | + $e_item = array( |
|
| 1036 | + rewrite_relative_url($site_url, $e->link), |
|
| 1037 | + $e->type, $e->length, $e->title, $e->width, $e->height); |
|
| 1038 | 1038 | |
| 1039 | - // Yet another episode of "mysql utf8_general_ci is gimped" |
|
| 1040 | - if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
| 1041 | - for ($i = 0; $i < count($e_item); $i++) { |
|
| 1042 | - if (is_string($e_item[$i])) { |
|
| 1043 | - $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]); |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1039 | + // Yet another episode of "mysql utf8_general_ci is gimped" |
|
| 1040 | + if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
| 1041 | + for ($i = 0; $i < count($e_item); $i++) { |
|
| 1042 | + if (is_string($e_item[$i])) { |
|
| 1043 | + $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]); |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | - array_push($enclosures, $e_item); |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1048 | + array_push($enclosures, $e_item); |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - if ($cache_images) |
|
| 1053 | - RSSUtils::cache_enclosures($enclosures, $site_url); |
|
| 1052 | + if ($cache_images) |
|
| 1053 | + RSSUtils::cache_enclosures($enclosures, $site_url); |
|
| 1054 | 1054 | |
| 1055 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 1056 | - Debug::log("article enclosures:", Debug::$LOG_VERBOSE); |
|
| 1057 | - print_r($enclosures); |
|
| 1058 | - } |
|
| 1055 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
| 1056 | + Debug::log("article enclosures:", Debug::$LOG_VERBOSE); |
|
| 1057 | + print_r($enclosures); |
|
| 1058 | + } |
|
| 1059 | 1059 | |
| 1060 | - $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures |
|
| 1060 | + $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures |
|
| 1061 | 1061 | WHERE content_url = ? AND content_type = ? AND post_id = ?"); |
| 1062 | 1062 | |
| 1063 | - $usth = $pdo->prepare("INSERT INTO ttrss_enclosures |
|
| 1063 | + $usth = $pdo->prepare("INSERT INTO ttrss_enclosures |
|
| 1064 | 1064 | (content_url, content_type, title, duration, post_id, width, height) VALUES |
| 1065 | 1065 | (?, ?, ?, ?, ?, ?, ?)"); |
| 1066 | 1066 | |
| 1067 | - foreach ($enclosures as $enc) { |
|
| 1068 | - $enc_url = $enc[0]; |
|
| 1069 | - $enc_type = $enc[1]; |
|
| 1070 | - $enc_dur = (int)$enc[2]; |
|
| 1071 | - $enc_title = $enc[3]; |
|
| 1072 | - $enc_width = intval($enc[4]); |
|
| 1073 | - $enc_height = intval($enc[5]); |
|
| 1067 | + foreach ($enclosures as $enc) { |
|
| 1068 | + $enc_url = $enc[0]; |
|
| 1069 | + $enc_type = $enc[1]; |
|
| 1070 | + $enc_dur = (int)$enc[2]; |
|
| 1071 | + $enc_title = $enc[3]; |
|
| 1072 | + $enc_width = intval($enc[4]); |
|
| 1073 | + $enc_height = intval($enc[5]); |
|
| 1074 | 1074 | |
| 1075 | - $esth->execute([$enc_url, $enc_type, $entry_ref_id]); |
|
| 1075 | + $esth->execute([$enc_url, $enc_type, $entry_ref_id]); |
|
| 1076 | 1076 | |
| 1077 | - if (!$esth->fetch()) { |
|
| 1078 | - $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]); |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1077 | + if (!$esth->fetch()) { |
|
| 1078 | + $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]); |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | 1081 | |
| 1082 | - // check for manual tags (we have to do it here since they're loaded from filters) |
|
| 1082 | + // check for manual tags (we have to do it here since they're loaded from filters) |
|
| 1083 | 1083 | |
| 1084 | - foreach ($article_filters as $f) { |
|
| 1085 | - if ($f["type"] == "tag") { |
|
| 1084 | + foreach ($article_filters as $f) { |
|
| 1085 | + if ($f["type"] == "tag") { |
|
| 1086 | 1086 | |
| 1087 | - $manual_tags = trim_array(explode(",", $f["param"])); |
|
| 1087 | + $manual_tags = trim_array(explode(",", $f["param"])); |
|
| 1088 | 1088 | |
| 1089 | - foreach ($manual_tags as $tag) { |
|
| 1090 | - array_push($entry_tags, $tag); |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1089 | + foreach ($manual_tags as $tag) { |
|
| 1090 | + array_push($entry_tags, $tag); |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | 1094 | |
| 1095 | - // Skip boring tags |
|
| 1095 | + // Skip boring tags |
|
| 1096 | 1096 | |
| 1097 | - $boring_tags = trim_array(explode(",", mb_strtolower(get_pref( |
|
| 1098 | - 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); |
|
| 1097 | + $boring_tags = trim_array(explode(",", mb_strtolower(get_pref( |
|
| 1098 | + 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); |
|
| 1099 | 1099 | |
| 1100 | - $filtered_tags = array(); |
|
| 1101 | - $tags_to_cache = array(); |
|
| 1100 | + $filtered_tags = array(); |
|
| 1101 | + $tags_to_cache = array(); |
|
| 1102 | 1102 | |
| 1103 | - foreach ($entry_tags as $tag) { |
|
| 1104 | - if (array_search($tag, $boring_tags) === false) { |
|
| 1105 | - array_push($filtered_tags, $tag); |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1103 | + foreach ($entry_tags as $tag) { |
|
| 1104 | + if (array_search($tag, $boring_tags) === false) { |
|
| 1105 | + array_push($filtered_tags, $tag); |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | 1108 | |
| 1109 | - $filtered_tags = array_unique($filtered_tags); |
|
| 1109 | + $filtered_tags = array_unique($filtered_tags); |
|
| 1110 | 1110 | |
| 1111 | - if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) { |
|
| 1112 | - Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); |
|
| 1111 | + if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) { |
|
| 1112 | + Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); |
|
| 1113 | 1113 | |
| 1114 | - } |
|
| 1114 | + } |
|
| 1115 | 1115 | |
| 1116 | - // Save article tags in the database |
|
| 1116 | + // Save article tags in the database |
|
| 1117 | 1117 | |
| 1118 | - if (count($filtered_tags) > 0) { |
|
| 1118 | + if (count($filtered_tags) > 0) { |
|
| 1119 | 1119 | |
| 1120 | - $tsth = $pdo->prepare("SELECT id FROM ttrss_tags |
|
| 1120 | + $tsth = $pdo->prepare("SELECT id FROM ttrss_tags |
|
| 1121 | 1121 | WHERE tag_name = ? AND post_int_id = ? AND |
| 1122 | 1122 | owner_uid = ? LIMIT 1"); |
| 1123 | 1123 | |
| 1124 | - $usth = $pdo->prepare("INSERT INTO ttrss_tags |
|
| 1124 | + $usth = $pdo->prepare("INSERT INTO ttrss_tags |
|
| 1125 | 1125 | (owner_uid,tag_name,post_int_id) |
| 1126 | 1126 | VALUES (?, ?, ?)"); |
| 1127 | 1127 | |
| 1128 | - $filtered_tags = FeedItem_Common::normalize_categories($filtered_tags); |
|
| 1128 | + $filtered_tags = FeedItem_Common::normalize_categories($filtered_tags); |
|
| 1129 | 1129 | |
| 1130 | - foreach ($filtered_tags as $tag) { |
|
| 1131 | - $tsth->execute([$tag, $entry_int_id, $owner_uid]); |
|
| 1130 | + foreach ($filtered_tags as $tag) { |
|
| 1131 | + $tsth->execute([$tag, $entry_int_id, $owner_uid]); |
|
| 1132 | 1132 | |
| 1133 | - if (!$tsth->fetch()) { |
|
| 1134 | - $usth->execute([$owner_uid, $tag, $entry_int_id]); |
|
| 1135 | - } |
|
| 1133 | + if (!$tsth->fetch()) { |
|
| 1134 | + $usth->execute([$owner_uid, $tag, $entry_int_id]); |
|
| 1135 | + } |
|
| 1136 | 1136 | |
| 1137 | - array_push($tags_to_cache, $tag); |
|
| 1138 | - } |
|
| 1137 | + array_push($tags_to_cache, $tag); |
|
| 1138 | + } |
|
| 1139 | 1139 | |
| 1140 | - /* update the cache */ |
|
| 1141 | - $tags_str = join(",", $tags_to_cache); |
|
| 1140 | + /* update the cache */ |
|
| 1141 | + $tags_str = join(",", $tags_to_cache); |
|
| 1142 | 1142 | |
| 1143 | - $tsth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1143 | + $tsth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1144 | 1144 | SET tag_cache = ? WHERE ref_id = ? |
| 1145 | 1145 | AND owner_uid = ?"); |
| 1146 | - $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]); |
|
| 1147 | - } |
|
| 1146 | + $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]); |
|
| 1147 | + } |
|
| 1148 | 1148 | |
| 1149 | - Debug::log("article processed", Debug::$LOG_VERBOSE); |
|
| 1149 | + Debug::log("article processed", Debug::$LOG_VERBOSE); |
|
| 1150 | 1150 | |
| 1151 | - $pdo->commit(); |
|
| 1152 | - } |
|
| 1151 | + $pdo->commit(); |
|
| 1152 | + } |
|
| 1153 | 1153 | |
| 1154 | - Debug::log("purging feed...", Debug::$LOG_VERBOSE); |
|
| 1154 | + Debug::log("purging feed...", Debug::$LOG_VERBOSE); |
|
| 1155 | 1155 | |
| 1156 | - Feeds::purge_feed($feed, 0); |
|
| 1156 | + Feeds::purge_feed($feed, 0); |
|
| 1157 | 1157 | |
| 1158 | - $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
| 1158 | + $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
| 1159 | 1159 | SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?"); |
| 1160 | - $sth->execute([$feed]); |
|
| 1160 | + $sth->execute([$feed]); |
|
| 1161 | 1161 | |
| 1162 | - } else { |
|
| 1162 | + } else { |
|
| 1163 | 1163 | |
| 1164 | - $error_msg = mb_substr($rss->error(), 0, 245); |
|
| 1164 | + $error_msg = mb_substr($rss->error(), 0, 245); |
|
| 1165 | 1165 | |
| 1166 | - Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE); |
|
| 1166 | + Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE); |
|
| 1167 | 1167 | |
| 1168 | - if (count($rss->errors()) > 1) { |
|
| 1169 | - foreach ($rss->errors() as $error) { |
|
| 1170 | - Debug::log("+ $error", Debug::$LOG_VERBOSE); |
|
| 1171 | - } |
|
| 1172 | - } |
|
| 1168 | + if (count($rss->errors()) > 1) { |
|
| 1169 | + foreach ($rss->errors() as $error) { |
|
| 1170 | + Debug::log("+ $error", Debug::$LOG_VERBOSE); |
|
| 1171 | + } |
|
| 1172 | + } |
|
| 1173 | 1173 | |
| 1174 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
| 1174 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
| 1175 | 1175 | last_updated = NOW(), last_unconditional = NOW() WHERE id = ?"); |
| 1176 | - $sth->execute([$error_msg, $feed]); |
|
| 1176 | + $sth->execute([$error_msg, $feed]); |
|
| 1177 | 1177 | |
| 1178 | - unset($rss); |
|
| 1178 | + unset($rss); |
|
| 1179 | 1179 | |
| 1180 | - Debug::log("update failed.", Debug::$LOG_VERBOSE); |
|
| 1181 | - return false; |
|
| 1182 | - } |
|
| 1180 | + Debug::log("update failed.", Debug::$LOG_VERBOSE); |
|
| 1181 | + return false; |
|
| 1182 | + } |
|
| 1183 | 1183 | |
| 1184 | - Debug::log("update done.", Debug::$LOG_VERBOSE); |
|
| 1184 | + Debug::log("update done.", Debug::$LOG_VERBOSE); |
|
| 1185 | 1185 | |
| 1186 | - return true; |
|
| 1187 | - } |
|
| 1186 | + return true; |
|
| 1187 | + } |
|
| 1188 | 1188 | |
| 1189 | - public static function cache_enclosures($enclosures, $site_url) { |
|
| 1190 | - $cache = new DiskCache("images"); |
|
| 1189 | + public static function cache_enclosures($enclosures, $site_url) { |
|
| 1190 | + $cache = new DiskCache("images"); |
|
| 1191 | 1191 | |
| 1192 | - if ($cache->isWritable()) { |
|
| 1193 | - foreach ($enclosures as $enc) { |
|
| 1192 | + if ($cache->isWritable()) { |
|
| 1193 | + foreach ($enclosures as $enc) { |
|
| 1194 | 1194 | |
| 1195 | - if (preg_match("/(image|audio|video)/", $enc[1])) { |
|
| 1196 | - $src = rewrite_relative_url($site_url, $enc[0]); |
|
| 1195 | + if (preg_match("/(image|audio|video)/", $enc[1])) { |
|
| 1196 | + $src = rewrite_relative_url($site_url, $enc[0]); |
|
| 1197 | 1197 | |
| 1198 | - $local_filename = sha1($src); |
|
| 1198 | + $local_filename = sha1($src); |
|
| 1199 | 1199 | |
| 1200 | - Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
| 1200 | + Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
| 1201 | 1201 | |
| 1202 | - if (!$cache->exists($local_filename)) { |
|
| 1202 | + if (!$cache->exists($local_filename)) { |
|
| 1203 | 1203 | |
| 1204 | - global $fetch_last_error_code; |
|
| 1205 | - global $fetch_last_error; |
|
| 1204 | + global $fetch_last_error_code; |
|
| 1205 | + global $fetch_last_error; |
|
| 1206 | 1206 | |
| 1207 | - $file_content = fetch_file_contents(array("url" => $src, |
|
| 1208 | - "http_referrer" => $src, |
|
| 1209 | - "max_size" => MAX_CACHE_FILE_SIZE)); |
|
| 1207 | + $file_content = fetch_file_contents(array("url" => $src, |
|
| 1208 | + "http_referrer" => $src, |
|
| 1209 | + "max_size" => MAX_CACHE_FILE_SIZE)); |
|
| 1210 | 1210 | |
| 1211 | - if ($file_content) { |
|
| 1212 | - $cache->put($local_filename, $file_content); |
|
| 1213 | - } else { |
|
| 1214 | - Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error"); |
|
| 1215 | - } |
|
| 1216 | - } else if (is_writable($local_filename)) { |
|
| 1217 | - $cache->touch($local_filename); |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1211 | + if ($file_content) { |
|
| 1212 | + $cache->put($local_filename, $file_content); |
|
| 1213 | + } else { |
|
| 1214 | + Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error"); |
|
| 1215 | + } |
|
| 1216 | + } else if (is_writable($local_filename)) { |
|
| 1217 | + $cache->touch($local_filename); |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | 1223 | |
| 1224 | - public static function cache_media($html, $site_url) { |
|
| 1225 | - $cache = new DiskCache("images"); |
|
| 1224 | + public static function cache_media($html, $site_url) { |
|
| 1225 | + $cache = new DiskCache("images"); |
|
| 1226 | 1226 | |
| 1227 | - if ($cache->isWritable()) { |
|
| 1228 | - $doc = new DOMDocument(); |
|
| 1229 | - if ($doc->loadHTML($html)) { |
|
| 1230 | - $xpath = new DOMXPath($doc); |
|
| 1227 | + if ($cache->isWritable()) { |
|
| 1228 | + $doc = new DOMDocument(); |
|
| 1229 | + if ($doc->loadHTML($html)) { |
|
| 1230 | + $xpath = new DOMXPath($doc); |
|
| 1231 | 1231 | |
| 1232 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])'); |
|
| 1232 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])'); |
|
| 1233 | 1233 | |
| 1234 | - foreach ($entries as $entry) { |
|
| 1235 | - if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
| 1236 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
| 1234 | + foreach ($entries as $entry) { |
|
| 1235 | + if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
| 1236 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
| 1237 | 1237 | |
| 1238 | - $local_filename = sha1($src); |
|
| 1238 | + $local_filename = sha1($src); |
|
| 1239 | 1239 | |
| 1240 | - Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE); |
|
| 1240 | + Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE); |
|
| 1241 | 1241 | |
| 1242 | - if (!$cache->exists($local_filename)) { |
|
| 1243 | - Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
| 1242 | + if (!$cache->exists($local_filename)) { |
|
| 1243 | + Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
| 1244 | 1244 | |
| 1245 | - global $fetch_last_error_code; |
|
| 1246 | - global $fetch_last_error; |
|
| 1245 | + global $fetch_last_error_code; |
|
| 1246 | + global $fetch_last_error; |
|
| 1247 | 1247 | |
| 1248 | - $file_content = fetch_file_contents(array("url" => $src, |
|
| 1249 | - "http_referrer" => $src, |
|
| 1250 | - "max_size" => MAX_CACHE_FILE_SIZE)); |
|
| 1248 | + $file_content = fetch_file_contents(array("url" => $src, |
|
| 1249 | + "http_referrer" => $src, |
|
| 1250 | + "max_size" => MAX_CACHE_FILE_SIZE)); |
|
| 1251 | 1251 | |
| 1252 | - if ($file_content) { |
|
| 1253 | - $cache->put($local_filename, $file_content); |
|
| 1254 | - } else { |
|
| 1255 | - Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error"); |
|
| 1256 | - } |
|
| 1257 | - } else if ($cache->isWritable($local_filename)) { |
|
| 1258 | - $cache->touch($local_filename); |
|
| 1259 | - } |
|
| 1260 | - } |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 1263 | - } |
|
| 1264 | - } |
|
| 1252 | + if ($file_content) { |
|
| 1253 | + $cache->put($local_filename, $file_content); |
|
| 1254 | + } else { |
|
| 1255 | + Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error"); |
|
| 1256 | + } |
|
| 1257 | + } else if ($cache->isWritable($local_filename)) { |
|
| 1258 | + $cache->touch($local_filename); |
|
| 1259 | + } |
|
| 1260 | + } |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | + } |
|
| 1264 | + } |
|
| 1265 | 1265 | |
| 1266 | - public static function expire_error_log() { |
|
| 1267 | - Debug::log("Removing old error log entries..."); |
|
| 1266 | + public static function expire_error_log() { |
|
| 1267 | + Debug::log("Removing old error log entries..."); |
|
| 1268 | 1268 | |
| 1269 | - $pdo = Db::pdo(); |
|
| 1269 | + $pdo = Db::pdo(); |
|
| 1270 | 1270 | |
| 1271 | - if (DB_TYPE == "pgsql") { |
|
| 1272 | - $pdo->query("DELETE FROM ttrss_error_log |
|
| 1271 | + if (DB_TYPE == "pgsql") { |
|
| 1272 | + $pdo->query("DELETE FROM ttrss_error_log |
|
| 1273 | 1273 | WHERE created_at < NOW() - INTERVAL '7 days'"); |
| 1274 | - } else { |
|
| 1275 | - $pdo->query("DELETE FROM ttrss_error_log |
|
| 1274 | + } else { |
|
| 1275 | + $pdo->query("DELETE FROM ttrss_error_log |
|
| 1276 | 1276 | WHERE created_at < DATE_SUB(NOW(), INTERVAL 7 DAY)"); |
| 1277 | - } |
|
| 1278 | - } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | 1279 | |
| 1280 | - public static function expire_feed_archive() { |
|
| 1281 | - Debug::log("Removing old archived feeds..."); |
|
| 1280 | + public static function expire_feed_archive() { |
|
| 1281 | + Debug::log("Removing old archived feeds..."); |
|
| 1282 | 1282 | |
| 1283 | - $pdo = Db::pdo(); |
|
| 1283 | + $pdo = Db::pdo(); |
|
| 1284 | 1284 | |
| 1285 | - if (DB_TYPE == "pgsql") { |
|
| 1286 | - $pdo->query("DELETE FROM ttrss_archived_feeds |
|
| 1285 | + if (DB_TYPE == "pgsql") { |
|
| 1286 | + $pdo->query("DELETE FROM ttrss_archived_feeds |
|
| 1287 | 1287 | WHERE created < NOW() - INTERVAL '1 month'"); |
| 1288 | - } else { |
|
| 1289 | - $pdo->query("DELETE FROM ttrss_archived_feeds |
|
| 1288 | + } else { |
|
| 1289 | + $pdo->query("DELETE FROM ttrss_archived_feeds |
|
| 1290 | 1290 | WHERE created < DATE_SUB(NOW(), INTERVAL 1 MONTH)"); |
| 1291 | - } |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - public static function expire_lock_files() { |
|
| 1295 | - Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE); |
|
| 1296 | - |
|
| 1297 | - $num_deleted = 0; |
|
| 1298 | - |
|
| 1299 | - if (is_writable(LOCK_DIRECTORY)) { |
|
| 1300 | - $files = glob(LOCK_DIRECTORY . "/*.lock"); |
|
| 1301 | - |
|
| 1302 | - if ($files) { |
|
| 1303 | - foreach ($files as $file) { |
|
| 1304 | - if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) { |
|
| 1305 | - unlink($file); |
|
| 1306 | - ++$num_deleted; |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - Debug::log("removed $num_deleted old lock files."); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Source: http://www.php.net/manual/en/function.parse-url.php#104527 |
|
| 1317 | - * Returns the url query as associative array |
|
| 1318 | - * |
|
| 1319 | - * @param string query |
|
| 1320 | - * @return array params |
|
| 1321 | - */ |
|
| 1322 | - public static function convertUrlQuery($query) { |
|
| 1323 | - $queryParts = explode('&', $query); |
|
| 1324 | - |
|
| 1325 | - $params = array(); |
|
| 1326 | - |
|
| 1327 | - foreach ($queryParts as $param) { |
|
| 1328 | - $item = explode('=', $param); |
|
| 1329 | - $params[$item[0]] = $item[1]; |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - return $params; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - public static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) { |
|
| 1336 | - $matches = array(); |
|
| 1337 | - |
|
| 1338 | - foreach ($filters as $filter) { |
|
| 1339 | - $match_any_rule = $filter["match_any_rule"]; |
|
| 1340 | - $inverse = $filter["inverse"]; |
|
| 1341 | - $filter_match = false; |
|
| 1342 | - |
|
| 1343 | - foreach ($filter["rules"] as $rule) { |
|
| 1344 | - $match = false; |
|
| 1345 | - $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); |
|
| 1346 | - $rule_inverse = $rule["inverse"]; |
|
| 1347 | - |
|
| 1348 | - if (!$reg_exp) |
|
| 1349 | - continue; |
|
| 1350 | - |
|
| 1351 | - switch ($rule["type"]) { |
|
| 1352 | - case "title": |
|
| 1353 | - $match = @preg_match("/$reg_exp/iu", $title); |
|
| 1354 | - break; |
|
| 1355 | - case "content": |
|
| 1356 | - // we don't need to deal with multiline regexps |
|
| 1357 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1358 | - |
|
| 1359 | - $match = @preg_match("/$reg_exp/iu", $content); |
|
| 1360 | - break; |
|
| 1361 | - case "both": |
|
| 1362 | - // we don't need to deal with multiline regexps |
|
| 1363 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1364 | - |
|
| 1365 | - $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
| 1366 | - break; |
|
| 1367 | - case "link": |
|
| 1368 | - $match = @preg_match("/$reg_exp/iu", $link); |
|
| 1369 | - break; |
|
| 1370 | - case "author": |
|
| 1371 | - $match = @preg_match("/$reg_exp/iu", $author); |
|
| 1372 | - break; |
|
| 1373 | - case "tag": |
|
| 1374 | - foreach ($tags as $tag) { |
|
| 1375 | - if (@preg_match("/$reg_exp/iu", $tag)) { |
|
| 1376 | - $match = true; |
|
| 1377 | - break; |
|
| 1378 | - } |
|
| 1379 | - } |
|
| 1380 | - break; |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - if ($rule_inverse) $match = !$match; |
|
| 1384 | - |
|
| 1385 | - if ($match_any_rule) { |
|
| 1386 | - if ($match) { |
|
| 1387 | - $filter_match = true; |
|
| 1388 | - break; |
|
| 1389 | - } |
|
| 1390 | - } else { |
|
| 1391 | - $filter_match = $match; |
|
| 1392 | - if (!$match) { |
|
| 1393 | - break; |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - if ($inverse) $filter_match = !$filter_match; |
|
| 1399 | - |
|
| 1400 | - if ($filter_match) { |
|
| 1401 | - if (is_array($matched_rules)) array_push($matched_rules, $rule); |
|
| 1402 | - if (is_array($matched_filters)) array_push($matched_filters, $filter); |
|
| 1403 | - |
|
| 1404 | - foreach ($filter["actions"] as $action) { |
|
| 1405 | - array_push($matches, $action); |
|
| 1406 | - |
|
| 1407 | - // if Stop action encountered, perform no further processing |
|
| 1408 | - if (isset($action["type"]) && $action["type"] == "stop") return $matches; |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - return $matches; |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - public static function find_article_filter($filters, $filter_name) { |
|
| 1417 | - foreach ($filters as $f) { |
|
| 1418 | - if ($f["type"] == $filter_name) { |
|
| 1419 | - return $f; |
|
| 1420 | - }; |
|
| 1421 | - } |
|
| 1422 | - return false; |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - public static function find_article_filters($filters, $filter_name) { |
|
| 1426 | - $results = array(); |
|
| 1427 | - |
|
| 1428 | - foreach ($filters as $f) { |
|
| 1429 | - if ($f["type"] == $filter_name) { |
|
| 1430 | - array_push($results, $f); |
|
| 1431 | - }; |
|
| 1432 | - } |
|
| 1433 | - return $results; |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - public static function calculate_article_score($filters) { |
|
| 1437 | - $score = 0; |
|
| 1438 | - |
|
| 1439 | - foreach ($filters as $f) { |
|
| 1440 | - if ($f["type"] == "score") { |
|
| 1441 | - $score += $f["param"]; |
|
| 1442 | - }; |
|
| 1443 | - } |
|
| 1444 | - return $score; |
|
| 1445 | - } |
|
| 1446 | - |
|
| 1447 | - public static function labels_contains_caption($labels, $caption) { |
|
| 1448 | - foreach ($labels as $label) { |
|
| 1449 | - if ($label[1] == $caption) { |
|
| 1450 | - return true; |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - return false; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - public static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) { |
|
| 1458 | - foreach ($filters as $f) { |
|
| 1459 | - if ($f["type"] == "label") { |
|
| 1460 | - if (!RSSUtils::labels_contains_caption($article_labels, $f["param"])) { |
|
| 1461 | - Labels::add_article($id, $f["param"], $owner_uid); |
|
| 1462 | - } |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - public static function make_guid_from_title($title) { |
|
| 1468 | - return preg_replace("/[ \"\',.:;]/", "-", |
|
| 1469 | - mb_strtolower(strip_tags($title), 'utf-8')); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - public static function cleanup_counters_cache() { |
|
| 1473 | - $pdo = Db::pdo(); |
|
| 1474 | - |
|
| 1475 | - $res = $pdo->query("DELETE FROM ttrss_counters_cache |
|
| 1291 | + } |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + public static function expire_lock_files() { |
|
| 1295 | + Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE); |
|
| 1296 | + |
|
| 1297 | + $num_deleted = 0; |
|
| 1298 | + |
|
| 1299 | + if (is_writable(LOCK_DIRECTORY)) { |
|
| 1300 | + $files = glob(LOCK_DIRECTORY . "/*.lock"); |
|
| 1301 | + |
|
| 1302 | + if ($files) { |
|
| 1303 | + foreach ($files as $file) { |
|
| 1304 | + if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) { |
|
| 1305 | + unlink($file); |
|
| 1306 | + ++$num_deleted; |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + Debug::log("removed $num_deleted old lock files."); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Source: http://www.php.net/manual/en/function.parse-url.php#104527 |
|
| 1317 | + * Returns the url query as associative array |
|
| 1318 | + * |
|
| 1319 | + * @param string query |
|
| 1320 | + * @return array params |
|
| 1321 | + */ |
|
| 1322 | + public static function convertUrlQuery($query) { |
|
| 1323 | + $queryParts = explode('&', $query); |
|
| 1324 | + |
|
| 1325 | + $params = array(); |
|
| 1326 | + |
|
| 1327 | + foreach ($queryParts as $param) { |
|
| 1328 | + $item = explode('=', $param); |
|
| 1329 | + $params[$item[0]] = $item[1]; |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + return $params; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + public static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) { |
|
| 1336 | + $matches = array(); |
|
| 1337 | + |
|
| 1338 | + foreach ($filters as $filter) { |
|
| 1339 | + $match_any_rule = $filter["match_any_rule"]; |
|
| 1340 | + $inverse = $filter["inverse"]; |
|
| 1341 | + $filter_match = false; |
|
| 1342 | + |
|
| 1343 | + foreach ($filter["rules"] as $rule) { |
|
| 1344 | + $match = false; |
|
| 1345 | + $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); |
|
| 1346 | + $rule_inverse = $rule["inverse"]; |
|
| 1347 | + |
|
| 1348 | + if (!$reg_exp) |
|
| 1349 | + continue; |
|
| 1350 | + |
|
| 1351 | + switch ($rule["type"]) { |
|
| 1352 | + case "title": |
|
| 1353 | + $match = @preg_match("/$reg_exp/iu", $title); |
|
| 1354 | + break; |
|
| 1355 | + case "content": |
|
| 1356 | + // we don't need to deal with multiline regexps |
|
| 1357 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1358 | + |
|
| 1359 | + $match = @preg_match("/$reg_exp/iu", $content); |
|
| 1360 | + break; |
|
| 1361 | + case "both": |
|
| 1362 | + // we don't need to deal with multiline regexps |
|
| 1363 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
| 1364 | + |
|
| 1365 | + $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
| 1366 | + break; |
|
| 1367 | + case "link": |
|
| 1368 | + $match = @preg_match("/$reg_exp/iu", $link); |
|
| 1369 | + break; |
|
| 1370 | + case "author": |
|
| 1371 | + $match = @preg_match("/$reg_exp/iu", $author); |
|
| 1372 | + break; |
|
| 1373 | + case "tag": |
|
| 1374 | + foreach ($tags as $tag) { |
|
| 1375 | + if (@preg_match("/$reg_exp/iu", $tag)) { |
|
| 1376 | + $match = true; |
|
| 1377 | + break; |
|
| 1378 | + } |
|
| 1379 | + } |
|
| 1380 | + break; |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + if ($rule_inverse) $match = !$match; |
|
| 1384 | + |
|
| 1385 | + if ($match_any_rule) { |
|
| 1386 | + if ($match) { |
|
| 1387 | + $filter_match = true; |
|
| 1388 | + break; |
|
| 1389 | + } |
|
| 1390 | + } else { |
|
| 1391 | + $filter_match = $match; |
|
| 1392 | + if (!$match) { |
|
| 1393 | + break; |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + if ($inverse) $filter_match = !$filter_match; |
|
| 1399 | + |
|
| 1400 | + if ($filter_match) { |
|
| 1401 | + if (is_array($matched_rules)) array_push($matched_rules, $rule); |
|
| 1402 | + if (is_array($matched_filters)) array_push($matched_filters, $filter); |
|
| 1403 | + |
|
| 1404 | + foreach ($filter["actions"] as $action) { |
|
| 1405 | + array_push($matches, $action); |
|
| 1406 | + |
|
| 1407 | + // if Stop action encountered, perform no further processing |
|
| 1408 | + if (isset($action["type"]) && $action["type"] == "stop") return $matches; |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + return $matches; |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + public static function find_article_filter($filters, $filter_name) { |
|
| 1417 | + foreach ($filters as $f) { |
|
| 1418 | + if ($f["type"] == $filter_name) { |
|
| 1419 | + return $f; |
|
| 1420 | + }; |
|
| 1421 | + } |
|
| 1422 | + return false; |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + public static function find_article_filters($filters, $filter_name) { |
|
| 1426 | + $results = array(); |
|
| 1427 | + |
|
| 1428 | + foreach ($filters as $f) { |
|
| 1429 | + if ($f["type"] == $filter_name) { |
|
| 1430 | + array_push($results, $f); |
|
| 1431 | + }; |
|
| 1432 | + } |
|
| 1433 | + return $results; |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + public static function calculate_article_score($filters) { |
|
| 1437 | + $score = 0; |
|
| 1438 | + |
|
| 1439 | + foreach ($filters as $f) { |
|
| 1440 | + if ($f["type"] == "score") { |
|
| 1441 | + $score += $f["param"]; |
|
| 1442 | + }; |
|
| 1443 | + } |
|
| 1444 | + return $score; |
|
| 1445 | + } |
|
| 1446 | + |
|
| 1447 | + public static function labels_contains_caption($labels, $caption) { |
|
| 1448 | + foreach ($labels as $label) { |
|
| 1449 | + if ($label[1] == $caption) { |
|
| 1450 | + return true; |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + return false; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + public static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) { |
|
| 1458 | + foreach ($filters as $f) { |
|
| 1459 | + if ($f["type"] == "label") { |
|
| 1460 | + if (!RSSUtils::labels_contains_caption($article_labels, $f["param"])) { |
|
| 1461 | + Labels::add_article($id, $f["param"], $owner_uid); |
|
| 1462 | + } |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + public static function make_guid_from_title($title) { |
|
| 1468 | + return preg_replace("/[ \"\',.:;]/", "-", |
|
| 1469 | + mb_strtolower(strip_tags($title), 'utf-8')); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + public static function cleanup_counters_cache() { |
|
| 1473 | + $pdo = Db::pdo(); |
|
| 1474 | + |
|
| 1475 | + $res = $pdo->query("DELETE FROM ttrss_counters_cache |
|
| 1476 | 1476 | WHERE feed_id > 0 AND |
| 1477 | 1477 | (SELECT COUNT(id) FROM ttrss_feeds WHERE |
| 1478 | 1478 | id = feed_id AND |
| 1479 | 1479 | ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid) = 0"); |
| 1480 | 1480 | |
| 1481 | - $frows = $res->rowCount(); |
|
| 1481 | + $frows = $res->rowCount(); |
|
| 1482 | 1482 | |
| 1483 | - $res = $pdo->query("DELETE FROM ttrss_cat_counters_cache |
|
| 1483 | + $res = $pdo->query("DELETE FROM ttrss_cat_counters_cache |
|
| 1484 | 1484 | WHERE feed_id > 0 AND |
| 1485 | 1485 | (SELECT COUNT(id) FROM ttrss_feed_categories WHERE |
| 1486 | 1486 | id = feed_id AND |
| 1487 | 1487 | ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0"); |
| 1488 | 1488 | |
| 1489 | - $crows = $res->rowCount(); |
|
| 1490 | - |
|
| 1491 | - Debug::log("removed $frows (feeds) $crows (cats) orphaned counter cache entries."); |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - public static function housekeeping_user($owner_uid) { |
|
| 1495 | - $tmph = new PluginHost(); |
|
| 1496 | - |
|
| 1497 | - load_user_plugins($owner_uid, $tmph); |
|
| 1498 | - |
|
| 1499 | - $tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - public static function housekeeping_common() { |
|
| 1503 | - DiskCache::expire(); |
|
| 1504 | - |
|
| 1505 | - RSSUtils::expire_lock_files(); |
|
| 1506 | - RSSUtils::expire_error_log(); |
|
| 1507 | - RSSUtils::expire_feed_archive(); |
|
| 1508 | - RSSUtils::cleanup_feed_browser(); |
|
| 1509 | - |
|
| 1510 | - Article::purge_orphans(); |
|
| 1511 | - RSSUtils::cleanup_counters_cache(); |
|
| 1512 | - |
|
| 1513 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - public static function check_feed_favicon($site_url, $feed) { |
|
| 1517 | - # print "FAVICON [$site_url]: $favicon_url\n"; |
|
| 1518 | - |
|
| 1519 | - $icon_file = ICONS_DIR . "/$feed.ico"; |
|
| 1520 | - |
|
| 1521 | - if (!file_exists($icon_file)) { |
|
| 1522 | - $favicon_url = RSSUtils::get_favicon_url($site_url); |
|
| 1523 | - |
|
| 1524 | - if ($favicon_url) { |
|
| 1525 | - // Limiting to "image" type misses those served with text/plain |
|
| 1526 | - $contents = fetch_file_contents($favicon_url); // , "image"); |
|
| 1527 | - |
|
| 1528 | - if ($contents) { |
|
| 1529 | - // Crude image type matching. |
|
| 1530 | - // Patterns gleaned from the file(1) source code. |
|
| 1531 | - if (preg_match('/^\x00\x00\x01\x00/', $contents)) { |
|
| 1532 | - // 0 string \000\000\001\000 MS Windows icon resource |
|
| 1533 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource"); |
|
| 1534 | - } |
|
| 1535 | - elseif (preg_match('/^GIF8/', $contents)) { |
|
| 1536 | - // 0 string GIF8 GIF image data |
|
| 1537 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image"); |
|
| 1538 | - } |
|
| 1539 | - elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) { |
|
| 1540 | - // 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data |
|
| 1541 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image"); |
|
| 1542 | - } |
|
| 1543 | - elseif (preg_match('/^\xff\xd8/', $contents)) { |
|
| 1544 | - // 0 beshort 0xffd8 JPEG image data |
|
| 1545 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image"); |
|
| 1546 | - } |
|
| 1547 | - elseif (preg_match('/^BM/', $contents)) { |
|
| 1548 | - // 0 string BM PC bitmap (OS2, Windows BMP files) |
|
| 1549 | - //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image"); |
|
| 1550 | - } |
|
| 1551 | - else { |
|
| 1552 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type"); |
|
| 1553 | - $contents = ""; |
|
| 1554 | - } |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - if ($contents) { |
|
| 1558 | - $fp = @fopen($icon_file, "w"); |
|
| 1559 | - |
|
| 1560 | - if ($fp) { |
|
| 1561 | - fwrite($fp, $contents); |
|
| 1562 | - fclose($fp); |
|
| 1563 | - chmod($icon_file, 0644); |
|
| 1564 | - } |
|
| 1565 | - } |
|
| 1566 | - } |
|
| 1567 | - return $icon_file; |
|
| 1568 | - } |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - public static function is_gzipped($feed_data) { |
|
| 1572 | - return strpos(substr($feed_data, 0, 3), |
|
| 1573 | - "\x1f" . "\x8b" . "\x08", 0) === 0; |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - public static function load_filters($feed_id, $owner_uid) { |
|
| 1577 | - $filters = array(); |
|
| 1578 | - |
|
| 1579 | - $feed_id = (int) $feed_id; |
|
| 1580 | - $cat_id = (int)Feeds::getFeedCategory($feed_id); |
|
| 1581 | - |
|
| 1582 | - if ($cat_id == 0) |
|
| 1583 | - $null_cat_qpart = "cat_id IS NULL OR"; |
|
| 1584 | - else |
|
| 1585 | - $null_cat_qpart = ""; |
|
| 1586 | - |
|
| 1587 | - $pdo = Db::pdo(); |
|
| 1588 | - |
|
| 1589 | - $sth = $pdo->prepare("SELECT * FROM ttrss_filters2 WHERE |
|
| 1489 | + $crows = $res->rowCount(); |
|
| 1490 | + |
|
| 1491 | + Debug::log("removed $frows (feeds) $crows (cats) orphaned counter cache entries."); |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + public static function housekeeping_user($owner_uid) { |
|
| 1495 | + $tmph = new PluginHost(); |
|
| 1496 | + |
|
| 1497 | + load_user_plugins($owner_uid, $tmph); |
|
| 1498 | + |
|
| 1499 | + $tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + public static function housekeeping_common() { |
|
| 1503 | + DiskCache::expire(); |
|
| 1504 | + |
|
| 1505 | + RSSUtils::expire_lock_files(); |
|
| 1506 | + RSSUtils::expire_error_log(); |
|
| 1507 | + RSSUtils::expire_feed_archive(); |
|
| 1508 | + RSSUtils::cleanup_feed_browser(); |
|
| 1509 | + |
|
| 1510 | + Article::purge_orphans(); |
|
| 1511 | + RSSUtils::cleanup_counters_cache(); |
|
| 1512 | + |
|
| 1513 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + public static function check_feed_favicon($site_url, $feed) { |
|
| 1517 | + # print "FAVICON [$site_url]: $favicon_url\n"; |
|
| 1518 | + |
|
| 1519 | + $icon_file = ICONS_DIR . "/$feed.ico"; |
|
| 1520 | + |
|
| 1521 | + if (!file_exists($icon_file)) { |
|
| 1522 | + $favicon_url = RSSUtils::get_favicon_url($site_url); |
|
| 1523 | + |
|
| 1524 | + if ($favicon_url) { |
|
| 1525 | + // Limiting to "image" type misses those served with text/plain |
|
| 1526 | + $contents = fetch_file_contents($favicon_url); // , "image"); |
|
| 1527 | + |
|
| 1528 | + if ($contents) { |
|
| 1529 | + // Crude image type matching. |
|
| 1530 | + // Patterns gleaned from the file(1) source code. |
|
| 1531 | + if (preg_match('/^\x00\x00\x01\x00/', $contents)) { |
|
| 1532 | + // 0 string \000\000\001\000 MS Windows icon resource |
|
| 1533 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource"); |
|
| 1534 | + } |
|
| 1535 | + elseif (preg_match('/^GIF8/', $contents)) { |
|
| 1536 | + // 0 string GIF8 GIF image data |
|
| 1537 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image"); |
|
| 1538 | + } |
|
| 1539 | + elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) { |
|
| 1540 | + // 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data |
|
| 1541 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image"); |
|
| 1542 | + } |
|
| 1543 | + elseif (preg_match('/^\xff\xd8/', $contents)) { |
|
| 1544 | + // 0 beshort 0xffd8 JPEG image data |
|
| 1545 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image"); |
|
| 1546 | + } |
|
| 1547 | + elseif (preg_match('/^BM/', $contents)) { |
|
| 1548 | + // 0 string BM PC bitmap (OS2, Windows BMP files) |
|
| 1549 | + //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image"); |
|
| 1550 | + } |
|
| 1551 | + else { |
|
| 1552 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type"); |
|
| 1553 | + $contents = ""; |
|
| 1554 | + } |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + if ($contents) { |
|
| 1558 | + $fp = @fopen($icon_file, "w"); |
|
| 1559 | + |
|
| 1560 | + if ($fp) { |
|
| 1561 | + fwrite($fp, $contents); |
|
| 1562 | + fclose($fp); |
|
| 1563 | + chmod($icon_file, 0644); |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1566 | + } |
|
| 1567 | + return $icon_file; |
|
| 1568 | + } |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + public static function is_gzipped($feed_data) { |
|
| 1572 | + return strpos(substr($feed_data, 0, 3), |
|
| 1573 | + "\x1f" . "\x8b" . "\x08", 0) === 0; |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + public static function load_filters($feed_id, $owner_uid) { |
|
| 1577 | + $filters = array(); |
|
| 1578 | + |
|
| 1579 | + $feed_id = (int) $feed_id; |
|
| 1580 | + $cat_id = (int)Feeds::getFeedCategory($feed_id); |
|
| 1581 | + |
|
| 1582 | + if ($cat_id == 0) |
|
| 1583 | + $null_cat_qpart = "cat_id IS NULL OR"; |
|
| 1584 | + else |
|
| 1585 | + $null_cat_qpart = ""; |
|
| 1586 | + |
|
| 1587 | + $pdo = Db::pdo(); |
|
| 1588 | + |
|
| 1589 | + $sth = $pdo->prepare("SELECT * FROM ttrss_filters2 WHERE |
|
| 1590 | 1590 | owner_uid = ? AND enabled = true ORDER BY order_id, title"); |
| 1591 | - $sth->execute([$owner_uid]); |
|
| 1591 | + $sth->execute([$owner_uid]); |
|
| 1592 | 1592 | |
| 1593 | - $check_cats = array_merge( |
|
| 1594 | - Feeds::getParentCategories($cat_id, $owner_uid), |
|
| 1595 | - [$cat_id]); |
|
| 1593 | + $check_cats = array_merge( |
|
| 1594 | + Feeds::getParentCategories($cat_id, $owner_uid), |
|
| 1595 | + [$cat_id]); |
|
| 1596 | 1596 | |
| 1597 | - $check_cats_str = join(",", $check_cats); |
|
| 1598 | - $check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats); |
|
| 1597 | + $check_cats_str = join(",", $check_cats); |
|
| 1598 | + $check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats); |
|
| 1599 | 1599 | |
| 1600 | - while ($line = $sth->fetch()) { |
|
| 1601 | - $filter_id = $line["id"]; |
|
| 1600 | + while ($line = $sth->fetch()) { |
|
| 1601 | + $filter_id = $line["id"]; |
|
| 1602 | 1602 | |
| 1603 | - $match_any_rule = sql_bool_to_bool($line["match_any_rule"]); |
|
| 1603 | + $match_any_rule = sql_bool_to_bool($line["match_any_rule"]); |
|
| 1604 | 1604 | |
| 1605 | - $sth2 = $pdo->prepare("SELECT |
|
| 1605 | + $sth2 = $pdo->prepare("SELECT |
|
| 1606 | 1606 | r.reg_exp, r.inverse, r.feed_id, r.cat_id, r.cat_filter, r.match_on, t.name AS type_name |
| 1607 | 1607 | FROM ttrss_filters2_rules AS r, |
| 1608 | 1608 | ttrss_filter_types AS t |
@@ -1611,117 +1611,117 @@ discard block |
||
| 1611 | 1611 | (($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats_str)) AND |
| 1612 | 1612 | (feed_id IS NULL OR feed_id = ?))) AND |
| 1613 | 1613 | filter_type = t.id AND filter_id = ?"); |
| 1614 | - $sth2->execute([$feed_id, $filter_id]); |
|
| 1614 | + $sth2->execute([$feed_id, $filter_id]); |
|
| 1615 | 1615 | |
| 1616 | - $rules = array(); |
|
| 1617 | - $actions = array(); |
|
| 1616 | + $rules = array(); |
|
| 1617 | + $actions = array(); |
|
| 1618 | 1618 | |
| 1619 | - while ($rule_line = $sth2->fetch()) { |
|
| 1620 | - # print_r($rule_line); |
|
| 1619 | + while ($rule_line = $sth2->fetch()) { |
|
| 1620 | + # print_r($rule_line); |
|
| 1621 | 1621 | |
| 1622 | - if ($rule_line["match_on"]) { |
|
| 1623 | - $match_on = json_decode($rule_line["match_on"], true); |
|
| 1622 | + if ($rule_line["match_on"]) { |
|
| 1623 | + $match_on = json_decode($rule_line["match_on"], true); |
|
| 1624 | 1624 | |
| 1625 | - if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) { |
|
| 1625 | + if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) { |
|
| 1626 | 1626 | |
| 1627 | - $rule = array(); |
|
| 1628 | - $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
| 1629 | - $rule["type"] = $rule_line["type_name"]; |
|
| 1630 | - $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
| 1627 | + $rule = array(); |
|
| 1628 | + $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
| 1629 | + $rule["type"] = $rule_line["type_name"]; |
|
| 1630 | + $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
| 1631 | 1631 | |
| 1632 | - array_push($rules, $rule); |
|
| 1633 | - } else if (!$match_any_rule) { |
|
| 1634 | - // this filter contains a rule that doesn't match to this feed/category combination |
|
| 1635 | - // thus filter has to be rejected |
|
| 1632 | + array_push($rules, $rule); |
|
| 1633 | + } else if (!$match_any_rule) { |
|
| 1634 | + // this filter contains a rule that doesn't match to this feed/category combination |
|
| 1635 | + // thus filter has to be rejected |
|
| 1636 | 1636 | |
| 1637 | - $rules = []; |
|
| 1638 | - break; |
|
| 1639 | - } |
|
| 1637 | + $rules = []; |
|
| 1638 | + break; |
|
| 1639 | + } |
|
| 1640 | 1640 | |
| 1641 | - } else { |
|
| 1641 | + } else { |
|
| 1642 | 1642 | |
| 1643 | - $rule = array(); |
|
| 1644 | - $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
| 1645 | - $rule["type"] = $rule_line["type_name"]; |
|
| 1646 | - $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
| 1643 | + $rule = array(); |
|
| 1644 | + $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
| 1645 | + $rule["type"] = $rule_line["type_name"]; |
|
| 1646 | + $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
| 1647 | 1647 | |
| 1648 | - array_push($rules, $rule); |
|
| 1649 | - } |
|
| 1650 | - } |
|
| 1648 | + array_push($rules, $rule); |
|
| 1649 | + } |
|
| 1650 | + } |
|
| 1651 | 1651 | |
| 1652 | - if (count($rules) > 0) { |
|
| 1653 | - $sth2 = $pdo->prepare("SELECT a.action_param,t.name AS type_name |
|
| 1652 | + if (count($rules) > 0) { |
|
| 1653 | + $sth2 = $pdo->prepare("SELECT a.action_param,t.name AS type_name |
|
| 1654 | 1654 | FROM ttrss_filters2_actions AS a, |
| 1655 | 1655 | ttrss_filter_actions AS t |
| 1656 | 1656 | WHERE |
| 1657 | 1657 | action_id = t.id AND filter_id = ?"); |
| 1658 | - $sth2->execute([$filter_id]); |
|
| 1659 | - |
|
| 1660 | - while ($action_line = $sth2->fetch()) { |
|
| 1661 | - # print_r($action_line); |
|
| 1662 | - |
|
| 1663 | - $action = array(); |
|
| 1664 | - $action["type"] = $action_line["type_name"]; |
|
| 1665 | - $action["param"] = $action_line["action_param"]; |
|
| 1666 | - |
|
| 1667 | - array_push($actions, $action); |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - |
|
| 1671 | - $filter = []; |
|
| 1672 | - $filter["id"] = $filter_id; |
|
| 1673 | - $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]); |
|
| 1674 | - $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
|
| 1675 | - $filter["rules"] = $rules; |
|
| 1676 | - $filter["actions"] = $actions; |
|
| 1677 | - |
|
| 1678 | - if (count($rules) > 0 && count($actions) > 0) { |
|
| 1679 | - array_push($filters, $filter); |
|
| 1680 | - } |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - return $filters; |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * Try to determine the favicon URL for a feed. |
|
| 1688 | - * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) |
|
| 1689 | - * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php |
|
| 1690 | - * |
|
| 1691 | - * @param string $url A feed or page URL |
|
| 1692 | - * @access public |
|
| 1693 | - * @return mixed The favicon URL, or false if none was found. |
|
| 1694 | - */ |
|
| 1695 | - public static function get_favicon_url($url) { |
|
| 1696 | - |
|
| 1697 | - $favicon_url = false; |
|
| 1698 | - |
|
| 1699 | - if ($html = @fetch_file_contents($url)) { |
|
| 1700 | - |
|
| 1701 | - $doc = new DOMDocument(); |
|
| 1702 | - if ($doc->loadHTML($html)) { |
|
| 1703 | - $xpath = new DOMXPath($doc); |
|
| 1704 | - |
|
| 1705 | - $base = $xpath->query('/html/head/base[@href]'); |
|
| 1706 | - foreach ($base as $b) { |
|
| 1707 | - $url = rewrite_relative_url($url, $b->getAttribute("href")); |
|
| 1708 | - break; |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - $entries = $xpath->query('/html/head/link[@rel="shortcut icon" or @rel="icon"]'); |
|
| 1712 | - if (count($entries) > 0) { |
|
| 1713 | - foreach ($entries as $entry) { |
|
| 1714 | - $favicon_url = rewrite_relative_url($url, $entry->getAttribute("href")); |
|
| 1715 | - break; |
|
| 1716 | - } |
|
| 1717 | - } |
|
| 1718 | - } |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - if (!$favicon_url) |
|
| 1722 | - $favicon_url = rewrite_relative_url($url, "/favicon.ico"); |
|
| 1723 | - |
|
| 1724 | - return $favicon_url; |
|
| 1725 | - } |
|
| 1658 | + $sth2->execute([$filter_id]); |
|
| 1659 | + |
|
| 1660 | + while ($action_line = $sth2->fetch()) { |
|
| 1661 | + # print_r($action_line); |
|
| 1662 | + |
|
| 1663 | + $action = array(); |
|
| 1664 | + $action["type"] = $action_line["type_name"]; |
|
| 1665 | + $action["param"] = $action_line["action_param"]; |
|
| 1666 | + |
|
| 1667 | + array_push($actions, $action); |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + |
|
| 1671 | + $filter = []; |
|
| 1672 | + $filter["id"] = $filter_id; |
|
| 1673 | + $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]); |
|
| 1674 | + $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
|
| 1675 | + $filter["rules"] = $rules; |
|
| 1676 | + $filter["actions"] = $actions; |
|
| 1677 | + |
|
| 1678 | + if (count($rules) > 0 && count($actions) > 0) { |
|
| 1679 | + array_push($filters, $filter); |
|
| 1680 | + } |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + return $filters; |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * Try to determine the favicon URL for a feed. |
|
| 1688 | + * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) |
|
| 1689 | + * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php |
|
| 1690 | + * |
|
| 1691 | + * @param string $url A feed or page URL |
|
| 1692 | + * @access public |
|
| 1693 | + * @return mixed The favicon URL, or false if none was found. |
|
| 1694 | + */ |
|
| 1695 | + public static function get_favicon_url($url) { |
|
| 1696 | + |
|
| 1697 | + $favicon_url = false; |
|
| 1698 | + |
|
| 1699 | + if ($html = @fetch_file_contents($url)) { |
|
| 1700 | + |
|
| 1701 | + $doc = new DOMDocument(); |
|
| 1702 | + if ($doc->loadHTML($html)) { |
|
| 1703 | + $xpath = new DOMXPath($doc); |
|
| 1704 | + |
|
| 1705 | + $base = $xpath->query('/html/head/base[@href]'); |
|
| 1706 | + foreach ($base as $b) { |
|
| 1707 | + $url = rewrite_relative_url($url, $b->getAttribute("href")); |
|
| 1708 | + break; |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + $entries = $xpath->query('/html/head/link[@rel="shortcut icon" or @rel="icon"]'); |
|
| 1712 | + if (count($entries) > 0) { |
|
| 1713 | + foreach ($entries as $entry) { |
|
| 1714 | + $favicon_url = rewrite_relative_url($url, $entry->getAttribute("href")); |
|
| 1715 | + break; |
|
| 1716 | + } |
|
| 1717 | + } |
|
| 1718 | + } |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + if (!$favicon_url) |
|
| 1722 | + $favicon_url = rewrite_relative_url($url, "/favicon.ico"); |
|
| 1723 | + |
|
| 1724 | + return $favicon_url; |
|
| 1725 | + } |
|
| 1726 | 1726 | |
| 1727 | 1727 | } |
@@ -760,24 +760,24 @@ |
||
| 760 | 760 | $feed_urls = false; |
| 761 | 761 | |
| 762 | 762 | switch ($rc['code']) { |
| 763 | - case 0: |
|
| 764 | - print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
| 765 | - break; |
|
| 766 | - case 1: |
|
| 767 | - print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
| 768 | - break; |
|
| 769 | - case 2: |
|
| 770 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
| 771 | - break; |
|
| 772 | - case 3: |
|
| 773 | - print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
| 774 | - break; |
|
| 775 | - case 4: |
|
| 776 | - $feed_urls = $rc["feeds"]; |
|
| 777 | - break; |
|
| 778 | - case 5: |
|
| 779 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
| 780 | - break; |
|
| 763 | + case 0: |
|
| 764 | + print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
| 765 | + break; |
|
| 766 | + case 1: |
|
| 767 | + print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
| 768 | + break; |
|
| 769 | + case 2: |
|
| 770 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
| 771 | + break; |
|
| 772 | + case 3: |
|
| 773 | + print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
| 774 | + break; |
|
| 775 | + case 4: |
|
| 776 | + $feed_urls = $rc["feeds"]; |
|
| 777 | + break; |
|
| 778 | + case 5: |
|
| 779 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
| 780 | + break; |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | if ($feed_urls) { |
@@ -1,329 +1,329 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Handler_Public extends Handler { |
| 3 | 3 | |
| 4 | - private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
|
| 5 | - $limit, $offset, $search, |
|
| 6 | - $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
|
| 4 | + private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
|
| 5 | + $limit, $offset, $search, |
|
| 6 | + $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
|
| 7 | 7 | |
| 8 | - require_once "lib/MiniTemplator.class.php"; |
|
| 8 | + require_once "lib/MiniTemplator.class.php"; |
|
| 9 | 9 | |
| 10 | - $note_style = "background-color : #fff7d5; |
|
| 10 | + $note_style = "background-color : #fff7d5; |
|
| 11 | 11 | border-width : 1px; ". |
| 12 | - "padding : 5px; border-style : dashed; border-color : #e7d796;". |
|
| 13 | - "margin-bottom : 1em; color : #9a8c59;"; |
|
| 14 | - |
|
| 15 | - if (!$limit) $limit = 60; |
|
| 16 | - |
|
| 17 | - $date_sort_field = "date_entered DESC, updated DESC"; |
|
| 18 | - |
|
| 19 | - if ($feed == -2 && !$is_cat) { |
|
| 20 | - $date_sort_field = "last_published DESC"; |
|
| 21 | - } else if ($feed == -1 && !$is_cat) { |
|
| 22 | - $date_sort_field = "last_marked DESC"; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - switch ($order) { |
|
| 26 | - case "title": |
|
| 27 | - $date_sort_field = "ttrss_entries.title, date_entered, updated"; |
|
| 28 | - break; |
|
| 29 | - case "date_reverse": |
|
| 30 | - $date_sort_field = "date_entered, updated"; |
|
| 31 | - break; |
|
| 32 | - case "feed_dates": |
|
| 33 | - $date_sort_field = "updated DESC"; |
|
| 34 | - break; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - $params = array( |
|
| 38 | - "owner_uid" => $owner_uid, |
|
| 39 | - "feed" => $feed, |
|
| 40 | - "limit" => $limit, |
|
| 41 | - "view_mode" => $view_mode, |
|
| 42 | - "cat_view" => $is_cat, |
|
| 43 | - "search" => $search, |
|
| 44 | - "override_order" => $date_sort_field, |
|
| 45 | - "include_children" => true, |
|
| 46 | - "ignore_vfeed_group" => true, |
|
| 47 | - "offset" => $offset, |
|
| 48 | - "start_ts" => $start_ts |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
| 52 | - |
|
| 53 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
| 54 | - |
|
| 55 | - $tmppluginhost = new PluginHost(); |
|
| 56 | - $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
| 57 | - $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
| 58 | - $tmppluginhost->load_data(); |
|
| 59 | - |
|
| 60 | - $handler = $tmppluginhost->get_feed_handler( |
|
| 61 | - PluginHost::feed_to_pfeed_id($feed)); |
|
| 62 | - |
|
| 63 | - if ($handler) { |
|
| 64 | - $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - } else { |
|
| 68 | - $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $result = $qfh_ret[0]; |
|
| 72 | - $feed_title = htmlspecialchars($qfh_ret[1]); |
|
| 73 | - $feed_site_url = $qfh_ret[2]; |
|
| 74 | - /* $last_error = $qfh_ret[3]; */ |
|
| 75 | - |
|
| 76 | - $feed_self_url = get_self_url_prefix() . |
|
| 77 | - "/public.php?op=rss&id=$feed&key=" . |
|
| 78 | - Feeds::get_feed_access_key($feed, false, $owner_uid); |
|
| 79 | - |
|
| 80 | - if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
| 81 | - |
|
| 82 | - if ($format == 'atom') { |
|
| 83 | - $tpl = new MiniTemplator; |
|
| 84 | - |
|
| 85 | - $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
|
| 86 | - |
|
| 87 | - $tpl->setVariable('FEED_TITLE', $feed_title, true); |
|
| 88 | - $tpl->setVariable('VERSION', get_version(), true); |
|
| 89 | - $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); |
|
| 90 | - |
|
| 91 | - $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
|
| 92 | - while ($line = $result->fetch()) { |
|
| 93 | - |
|
| 94 | - $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); |
|
| 95 | - |
|
| 96 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
| 97 | - $line = $p->hook_query_headlines($line); |
|
| 98 | - } |
|
| 12 | + "padding : 5px; border-style : dashed; border-color : #e7d796;". |
|
| 13 | + "margin-bottom : 1em; color : #9a8c59;"; |
|
| 14 | + |
|
| 15 | + if (!$limit) $limit = 60; |
|
| 16 | + |
|
| 17 | + $date_sort_field = "date_entered DESC, updated DESC"; |
|
| 18 | + |
|
| 19 | + if ($feed == -2 && !$is_cat) { |
|
| 20 | + $date_sort_field = "last_published DESC"; |
|
| 21 | + } else if ($feed == -1 && !$is_cat) { |
|
| 22 | + $date_sort_field = "last_marked DESC"; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + switch ($order) { |
|
| 26 | + case "title": |
|
| 27 | + $date_sort_field = "ttrss_entries.title, date_entered, updated"; |
|
| 28 | + break; |
|
| 29 | + case "date_reverse": |
|
| 30 | + $date_sort_field = "date_entered, updated"; |
|
| 31 | + break; |
|
| 32 | + case "feed_dates": |
|
| 33 | + $date_sort_field = "updated DESC"; |
|
| 34 | + break; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + $params = array( |
|
| 38 | + "owner_uid" => $owner_uid, |
|
| 39 | + "feed" => $feed, |
|
| 40 | + "limit" => $limit, |
|
| 41 | + "view_mode" => $view_mode, |
|
| 42 | + "cat_view" => $is_cat, |
|
| 43 | + "search" => $search, |
|
| 44 | + "override_order" => $date_sort_field, |
|
| 45 | + "include_children" => true, |
|
| 46 | + "ignore_vfeed_group" => true, |
|
| 47 | + "offset" => $offset, |
|
| 48 | + "start_ts" => $start_ts |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
| 52 | + |
|
| 53 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
| 54 | + |
|
| 55 | + $tmppluginhost = new PluginHost(); |
|
| 56 | + $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
| 57 | + $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
| 58 | + $tmppluginhost->load_data(); |
|
| 59 | + |
|
| 60 | + $handler = $tmppluginhost->get_feed_handler( |
|
| 61 | + PluginHost::feed_to_pfeed_id($feed)); |
|
| 62 | + |
|
| 63 | + if ($handler) { |
|
| 64 | + $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params); |
|
| 65 | + } |
|
| 99 | 66 | |
| 100 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
| 101 | - $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
| 102 | - } |
|
| 67 | + } else { |
|
| 68 | + $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
| 69 | + } |
|
| 103 | 70 | |
| 104 | - $tpl->setVariable('ARTICLE_ID', |
|
| 105 | - htmlspecialchars($orig_guid ? $line['link'] : |
|
| 106 | - $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
| 107 | - $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
|
| 108 | - $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
|
| 109 | - $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
|
| 71 | + $result = $qfh_ret[0]; |
|
| 72 | + $feed_title = htmlspecialchars($qfh_ret[1]); |
|
| 73 | + $feed_site_url = $qfh_ret[2]; |
|
| 74 | + /* $last_error = $qfh_ret[3]; */ |
|
| 110 | 75 | |
| 111 | - $content = sanitize($line["content"], false, $owner_uid, |
|
| 112 | - $feed_site_url, false, $line["id"]); |
|
| 76 | + $feed_self_url = get_self_url_prefix() . |
|
| 77 | + "/public.php?op=rss&id=$feed&key=" . |
|
| 78 | + Feeds::get_feed_access_key($feed, false, $owner_uid); |
|
| 113 | 79 | |
| 114 | - if ($line['note']) { |
|
| 115 | - $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
| 116 | - $content; |
|
| 117 | - $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
|
| 118 | - } |
|
| 80 | + if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
| 119 | 81 | |
| 120 | - $tpl->setVariable('ARTICLE_CONTENT', $content, true); |
|
| 82 | + if ($format == 'atom') { |
|
| 83 | + $tpl = new MiniTemplator; |
|
| 121 | 84 | |
| 122 | - $tpl->setVariable('ARTICLE_UPDATED_ATOM', |
|
| 123 | - date('c', strtotime($line["updated"])), true); |
|
| 124 | - $tpl->setVariable('ARTICLE_UPDATED_RFC822', |
|
| 125 | - date(DATE_RFC822, strtotime($line["updated"])), true); |
|
| 85 | + $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
|
| 126 | 86 | |
| 127 | - $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); |
|
| 87 | + $tpl->setVariable('FEED_TITLE', $feed_title, true); |
|
| 88 | + $tpl->setVariable('VERSION', get_version(), true); |
|
| 89 | + $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); |
|
| 128 | 90 | |
| 129 | - $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); |
|
| 130 | - $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
|
| 91 | + $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
|
| 92 | + while ($line = $result->fetch()) { |
|
| 131 | 93 | |
| 132 | - $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
| 94 | + $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); |
|
| 133 | 95 | |
| 134 | - foreach ($tags as $tag) { |
|
| 135 | - $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); |
|
| 136 | - $tpl->addBlock('category'); |
|
| 137 | - } |
|
| 96 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
| 97 | + $line = $p->hook_query_headlines($line); |
|
| 98 | + } |
|
| 138 | 99 | |
| 139 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
| 100 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
| 101 | + $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
| 102 | + } |
|
| 140 | 103 | |
| 141 | - if (count($enclosures) > 0) { |
|
| 142 | - foreach ($enclosures as $e) { |
|
| 143 | - $type = htmlspecialchars($e['content_type']); |
|
| 144 | - $url = htmlspecialchars($e['content_url']); |
|
| 145 | - $length = $e['duration'] ? $e['duration'] : 1; |
|
| 104 | + $tpl->setVariable('ARTICLE_ID', |
|
| 105 | + htmlspecialchars($orig_guid ? $line['link'] : |
|
| 106 | + $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
| 107 | + $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
|
| 108 | + $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
|
| 109 | + $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
|
| 146 | 110 | |
| 147 | - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
|
| 148 | - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); |
|
| 149 | - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); |
|
| 111 | + $content = sanitize($line["content"], false, $owner_uid, |
|
| 112 | + $feed_site_url, false, $line["id"]); |
|
| 150 | 113 | |
| 151 | - $tpl->addBlock('enclosure'); |
|
| 152 | - } |
|
| 153 | - } else { |
|
| 154 | - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); |
|
| 155 | - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); |
|
| 156 | - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); |
|
| 157 | - } |
|
| 114 | + if ($line['note']) { |
|
| 115 | + $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
| 116 | + $content; |
|
| 117 | + $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
|
| 118 | + } |
|
| 158 | 119 | |
| 159 | - list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); |
|
| 120 | + $tpl->setVariable('ARTICLE_CONTENT', $content, true); |
|
| 160 | 121 | |
| 161 | - $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); |
|
| 122 | + $tpl->setVariable('ARTICLE_UPDATED_ATOM', |
|
| 123 | + date('c', strtotime($line["updated"])), true); |
|
| 124 | + $tpl->setVariable('ARTICLE_UPDATED_RFC822', |
|
| 125 | + date(DATE_RFC822, strtotime($line["updated"])), true); |
|
| 162 | 126 | |
| 163 | - $tpl->addBlock('entry'); |
|
| 164 | - } |
|
| 127 | + $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); |
|
| 165 | 128 | |
| 166 | - $tmp = ""; |
|
| 129 | + $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); |
|
| 130 | + $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
|
| 167 | 131 | |
| 168 | - $tpl->addBlock('feed'); |
|
| 169 | - $tpl->generateOutputToString($tmp); |
|
| 132 | + $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
| 170 | 133 | |
| 171 | - if (@!clean($_REQUEST["noxml"])) { |
|
| 172 | - header("Content-Type: text/xml; charset=utf-8"); |
|
| 173 | - } else { |
|
| 174 | - header("Content-Type: text/plain; charset=utf-8"); |
|
| 175 | - } |
|
| 134 | + foreach ($tags as $tag) { |
|
| 135 | + $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); |
|
| 136 | + $tpl->addBlock('category'); |
|
| 137 | + } |
|
| 176 | 138 | |
| 177 | - print $tmp; |
|
| 178 | - } else if ($format == 'json') { |
|
| 139 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
| 179 | 140 | |
| 180 | - $feed = array(); |
|
| 141 | + if (count($enclosures) > 0) { |
|
| 142 | + foreach ($enclosures as $e) { |
|
| 143 | + $type = htmlspecialchars($e['content_type']); |
|
| 144 | + $url = htmlspecialchars($e['content_url']); |
|
| 145 | + $length = $e['duration'] ? $e['duration'] : 1; |
|
| 181 | 146 | |
| 182 | - $feed['title'] = $feed_title; |
|
| 183 | - $feed['feed_url'] = $feed_self_url; |
|
| 147 | + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
|
| 148 | + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); |
|
| 149 | + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); |
|
| 184 | 150 | |
| 185 | - $feed['self_url'] = get_self_url_prefix(); |
|
| 151 | + $tpl->addBlock('enclosure'); |
|
| 152 | + } |
|
| 153 | + } else { |
|
| 154 | + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); |
|
| 155 | + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); |
|
| 156 | + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); |
|
| 157 | + } |
|
| 186 | 158 | |
| 187 | - $feed['articles'] = array(); |
|
| 159 | + list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); |
|
| 188 | 160 | |
| 189 | - while ($line = $result->fetch()) { |
|
| 161 | + $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); |
|
| 190 | 162 | |
| 191 | - $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); |
|
| 163 | + $tpl->addBlock('entry'); |
|
| 164 | + } |
|
| 192 | 165 | |
| 193 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
| 194 | - $line = $p->hook_query_headlines($line, 100); |
|
| 195 | - } |
|
| 166 | + $tmp = ""; |
|
| 196 | 167 | |
| 197 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
| 198 | - $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
| 199 | - } |
|
| 168 | + $tpl->addBlock('feed'); |
|
| 169 | + $tpl->generateOutputToString($tmp); |
|
| 200 | 170 | |
| 201 | - $article = array(); |
|
| 171 | + if (@!clean($_REQUEST["noxml"])) { |
|
| 172 | + header("Content-Type: text/xml; charset=utf-8"); |
|
| 173 | + } else { |
|
| 174 | + header("Content-Type: text/plain; charset=utf-8"); |
|
| 175 | + } |
|
| 202 | 176 | |
| 203 | - $article['id'] = $line['link']; |
|
| 204 | - $article['link'] = $line['link']; |
|
| 205 | - $article['title'] = $line['title']; |
|
| 206 | - $article['excerpt'] = $line["content_preview"]; |
|
| 207 | - $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
|
| 208 | - $article['updated'] = date('c', strtotime($line["updated"])); |
|
| 177 | + print $tmp; |
|
| 178 | + } else if ($format == 'json') { |
|
| 209 | 179 | |
| 210 | - if ($line['note']) $article['note'] = $line['note']; |
|
| 211 | - if ($article['author']) $article['author'] = $line['author']; |
|
| 180 | + $feed = array(); |
|
| 212 | 181 | |
| 213 | - $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
| 182 | + $feed['title'] = $feed_title; |
|
| 183 | + $feed['feed_url'] = $feed_self_url; |
|
| 214 | 184 | |
| 215 | - if (count($tags) > 0) { |
|
| 216 | - $article['tags'] = array(); |
|
| 185 | + $feed['self_url'] = get_self_url_prefix(); |
|
| 217 | 186 | |
| 218 | - foreach ($tags as $tag) { |
|
| 219 | - array_push($article['tags'], $tag); |
|
| 220 | - } |
|
| 221 | - } |
|
| 187 | + $feed['articles'] = array(); |
|
| 222 | 188 | |
| 223 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
| 189 | + while ($line = $result->fetch()) { |
|
| 224 | 190 | |
| 225 | - if (count($enclosures) > 0) { |
|
| 226 | - $article['enclosures'] = array(); |
|
| 191 | + $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); |
|
| 227 | 192 | |
| 228 | - foreach ($enclosures as $e) { |
|
| 229 | - $type = $e['content_type']; |
|
| 230 | - $url = $e['content_url']; |
|
| 231 | - $length = $e['duration']; |
|
| 193 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
| 194 | + $line = $p->hook_query_headlines($line, 100); |
|
| 195 | + } |
|
| 232 | 196 | |
| 233 | - array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); |
|
| 234 | - } |
|
| 235 | - } |
|
| 197 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
| 198 | + $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $article = array(); |
|
| 202 | + |
|
| 203 | + $article['id'] = $line['link']; |
|
| 204 | + $article['link'] = $line['link']; |
|
| 205 | + $article['title'] = $line['title']; |
|
| 206 | + $article['excerpt'] = $line["content_preview"]; |
|
| 207 | + $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
|
| 208 | + $article['updated'] = date('c', strtotime($line["updated"])); |
|
| 209 | + |
|
| 210 | + if ($line['note']) $article['note'] = $line['note']; |
|
| 211 | + if ($article['author']) $article['author'] = $line['author']; |
|
| 212 | + |
|
| 213 | + $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
| 214 | + |
|
| 215 | + if (count($tags) > 0) { |
|
| 216 | + $article['tags'] = array(); |
|
| 236 | 217 | |
| 237 | - array_push($feed['articles'], $article); |
|
| 238 | - } |
|
| 218 | + foreach ($tags as $tag) { |
|
| 219 | + array_push($article['tags'], $tag); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
| 239 | 224 | |
| 240 | - header("Content-Type: text/json; charset=utf-8"); |
|
| 241 | - print json_encode($feed); |
|
| 225 | + if (count($enclosures) > 0) { |
|
| 226 | + $article['enclosures'] = array(); |
|
| 242 | 227 | |
| 243 | - } else { |
|
| 244 | - header("Content-Type: text/plain; charset=utf-8"); |
|
| 245 | - print json_encode(array("error" => array("message" => "Unknown format"))); |
|
| 246 | - } |
|
| 247 | - } |
|
| 228 | + foreach ($enclosures as $e) { |
|
| 229 | + $type = $e['content_type']; |
|
| 230 | + $url = $e['content_url']; |
|
| 231 | + $length = $e['duration']; |
|
| 248 | 232 | |
| 249 | - public function getUnread() { |
|
| 250 | - $login = clean($_REQUEST["login"]); |
|
| 251 | - $fresh = clean($_REQUEST["fresh"]) == "1"; |
|
| 233 | + array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + array_push($feed['articles'], $article); |
|
| 238 | + } |
|
| 252 | 239 | |
| 253 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
| 254 | - $sth->execute([$login]); |
|
| 240 | + header("Content-Type: text/json; charset=utf-8"); |
|
| 241 | + print json_encode($feed); |
|
| 255 | 242 | |
| 256 | - if ($row = $sth->fetch()) { |
|
| 257 | - $uid = $row["id"]; |
|
| 243 | + } else { |
|
| 244 | + header("Content-Type: text/plain; charset=utf-8"); |
|
| 245 | + print json_encode(array("error" => array("message" => "Unknown format"))); |
|
| 246 | + } |
|
| 247 | + } |
|
| 258 | 248 | |
| 259 | - print Feeds::getGlobalUnread($uid); |
|
| 249 | + public function getUnread() { |
|
| 250 | + $login = clean($_REQUEST["login"]); |
|
| 251 | + $fresh = clean($_REQUEST["fresh"]) == "1"; |
|
| 260 | 252 | |
| 261 | - if ($fresh) { |
|
| 262 | - print ";"; |
|
| 263 | - print Feeds::getFeedArticles(-3, false, true, $uid); |
|
| 264 | - } |
|
| 253 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
| 254 | + $sth->execute([$login]); |
|
| 255 | + |
|
| 256 | + if ($row = $sth->fetch()) { |
|
| 257 | + $uid = $row["id"]; |
|
| 258 | + |
|
| 259 | + print Feeds::getGlobalUnread($uid); |
|
| 260 | + |
|
| 261 | + if ($fresh) { |
|
| 262 | + print ";"; |
|
| 263 | + print Feeds::getFeedArticles(-3, false, true, $uid); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - } else { |
|
| 267 | - print "-1;User not found"; |
|
| 268 | - } |
|
| 269 | - } |
|
| 266 | + } else { |
|
| 267 | + print "-1;User not found"; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - public function getProfiles() { |
|
| 272 | - $login = clean($_REQUEST["login"]); |
|
| 273 | - $rv = []; |
|
| 271 | + public function getProfiles() { |
|
| 272 | + $login = clean($_REQUEST["login"]); |
|
| 273 | + $rv = []; |
|
| 274 | 274 | |
| 275 | - if ($login) { |
|
| 276 | - $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
|
| 275 | + if ($login) { |
|
| 276 | + $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
|
| 277 | 277 | WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title"); |
| 278 | - $sth->execute([$login]); |
|
| 278 | + $sth->execute([$login]); |
|
| 279 | 279 | |
| 280 | - $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
| 280 | + $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
| 281 | 281 | |
| 282 | - while ($line = $sth->fetch()) { |
|
| 283 | - $id = $line["id"]; |
|
| 284 | - $title = $line["title"]; |
|
| 282 | + while ($line = $sth->fetch()) { |
|
| 283 | + $id = $line["id"]; |
|
| 284 | + $title = $line["title"]; |
|
| 285 | 285 | |
| 286 | - array_push($rv, [ "label" => $title, "value" => $id ]); |
|
| 287 | - } |
|
| 288 | - } |
|
| 286 | + array_push($rv, [ "label" => $title, "value" => $id ]); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - print json_encode($rv); |
|
| 291 | - } |
|
| 290 | + print json_encode($rv); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - public function logout() { |
|
| 294 | - logout_user(); |
|
| 295 | - header("Location: index.php"); |
|
| 296 | - } |
|
| 293 | + public function logout() { |
|
| 294 | + logout_user(); |
|
| 295 | + header("Location: index.php"); |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - public function share() { |
|
| 299 | - $uuid = clean($_REQUEST["key"]); |
|
| 298 | + public function share() { |
|
| 299 | + $uuid = clean($_REQUEST["key"]); |
|
| 300 | 300 | |
| 301 | - if ($uuid) { |
|
| 302 | - $sth = $this->pdo->prepare("SELECT ref_id, owner_uid |
|
| 301 | + if ($uuid) { |
|
| 302 | + $sth = $this->pdo->prepare("SELECT ref_id, owner_uid |
|
| 303 | 303 | FROM ttrss_user_entries WHERE uuid = ?"); |
| 304 | - $sth->execute([$uuid]); |
|
| 304 | + $sth->execute([$uuid]); |
|
| 305 | 305 | |
| 306 | - if ($row = $sth->fetch()) { |
|
| 307 | - header("Content-Type: text/html"); |
|
| 306 | + if ($row = $sth->fetch()) { |
|
| 307 | + header("Content-Type: text/html"); |
|
| 308 | 308 | |
| 309 | - $id = $row["ref_id"]; |
|
| 310 | - $owner_uid = $row["owner_uid"]; |
|
| 309 | + $id = $row["ref_id"]; |
|
| 310 | + $owner_uid = $row["owner_uid"]; |
|
| 311 | 311 | |
| 312 | - print $this->format_article($id, $owner_uid); |
|
| 312 | + print $this->format_article($id, $owner_uid); |
|
| 313 | 313 | |
| 314 | - return; |
|
| 315 | - } |
|
| 316 | - } |
|
| 314 | + return; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
| 319 | - print "Article not found."; |
|
| 320 | - } |
|
| 318 | + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
| 319 | + print "Article not found."; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - private function format_article($id, $owner_uid) { |
|
| 322 | + private function format_article($id, $owner_uid) { |
|
| 323 | 323 | |
| 324 | - $pdo = Db::pdo(); |
|
| 324 | + $pdo = Db::pdo(); |
|
| 325 | 325 | |
| 326 | - $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
|
| 326 | + $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
|
| 327 | 327 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
| 328 | 328 | (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url, |
| 329 | 329 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title, |
@@ -337,26 +337,26 @@ discard block |
||
| 337 | 337 | note |
| 338 | 338 | FROM ttrss_entries,ttrss_user_entries |
| 339 | 339 | WHERE id = ? AND ref_id = id AND owner_uid = ?"); |
| 340 | - $sth->execute([$id, $owner_uid]); |
|
| 340 | + $sth->execute([$id, $owner_uid]); |
|
| 341 | 341 | |
| 342 | - $rv = ''; |
|
| 342 | + $rv = ''; |
|
| 343 | 343 | |
| 344 | - if ($line = $sth->fetch()) { |
|
| 344 | + if ($line = $sth->fetch()) { |
|
| 345 | 345 | |
| 346 | - $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); |
|
| 347 | - unset($line["tag_cache"]); |
|
| 346 | + $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); |
|
| 347 | + unset($line["tag_cache"]); |
|
| 348 | 348 | |
| 349 | - $line["content"] = sanitize($line["content"], |
|
| 350 | - $line['hide_images'], |
|
| 351 | - $owner_uid, $line["site_url"], false, $line["id"]); |
|
| 349 | + $line["content"] = sanitize($line["content"], |
|
| 350 | + $line['hide_images'], |
|
| 351 | + $owner_uid, $line["site_url"], false, $line["id"]); |
|
| 352 | 352 | |
| 353 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { |
|
| 354 | - $line = $p->hook_render_article($line); |
|
| 355 | - } |
|
| 353 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { |
|
| 354 | + $line = $p->hook_render_article($line); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
| 357 | + $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
| 358 | 358 | |
| 359 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
| 359 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
| 360 | 360 | |
| 361 | 361 | header("Content-Type: text/html"); |
| 362 | 362 | |
@@ -371,13 +371,13 @@ discard block |
||
| 371 | 371 | $rv .= "<meta property='og:title' content=\"".htmlspecialchars(html_entity_decode($line["title"], ENT_NOQUOTES | ENT_HTML401))."\"/>\n"; |
| 372 | 372 | $rv .= "<meta property='og:description' content=\"". |
| 373 | 373 | htmlspecialchars( |
| 374 | - truncate_string( |
|
| 375 | - preg_replace("/[\r\n\t]/", "", |
|
| 376 | - preg_replace("/ {1,}/", " ", |
|
| 377 | - strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401)) |
|
| 378 | - ) |
|
| 379 | - ), 500, "...") |
|
| 380 | - )."\"/>\n"; |
|
| 374 | + truncate_string( |
|
| 375 | + preg_replace("/[\r\n\t]/", "", |
|
| 376 | + preg_replace("/ {1,}/", " ", |
|
| 377 | + strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401)) |
|
| 378 | + ) |
|
| 379 | + ), 500, "...") |
|
| 380 | + )."\"/>\n"; |
|
| 381 | 381 | |
| 382 | 382 | $rv .= "</head>"; |
| 383 | 383 | |
@@ -390,132 +390,132 @@ discard block |
||
| 390 | 390 | $rv .= "<body class='flat ttrss_utility ttrss_zoom'>"; |
| 391 | 391 | $rv .= "<div class='container'>"; |
| 392 | 392 | |
| 393 | - if ($line["link"]) { |
|
| 394 | - $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
|
| 393 | + if ($line["link"]) { |
|
| 394 | + $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
|
| 395 | 395 | title=\"".htmlspecialchars($line['title'])."\" |
| 396 | 396 | href=\"" .htmlspecialchars($line["link"]) . "\">" . $line["title"] . "</a></h1>"; |
| 397 | - } else { |
|
| 398 | - $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
| 399 | - } |
|
| 397 | + } else { |
|
| 398 | + $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - $rv .= "<div class='content post'>"; |
|
| 401 | + $rv .= "<div class='content post'>"; |
|
| 402 | 402 | |
| 403 | - /* header */ |
|
| 403 | + /* header */ |
|
| 404 | 404 | |
| 405 | - $rv .= "<div class='header'>"; |
|
| 406 | - $rv .= "<div class='row'>"; # row |
|
| 405 | + $rv .= "<div class='header'>"; |
|
| 406 | + $rv .= "<div class='row'>"; # row |
|
| 407 | 407 | |
| 408 | - //$entry_author = $line["author"] ? " - " . $line["author"] : ""; |
|
| 409 | - $parsed_updated = make_local_datetime($line["updated"], true, |
|
| 410 | - $owner_uid, true); |
|
| 408 | + //$entry_author = $line["author"] ? " - " . $line["author"] : ""; |
|
| 409 | + $parsed_updated = make_local_datetime($line["updated"], true, |
|
| 410 | + $owner_uid, true); |
|
| 411 | 411 | |
| 412 | - $rv .= "<div>".$line['author']."</div>"; |
|
| 412 | + $rv .= "<div>".$line['author']."</div>"; |
|
| 413 | 413 | $rv .= "<div>$parsed_updated</div>"; |
| 414 | 414 | |
| 415 | - $rv .= "</div>"; # row |
|
| 415 | + $rv .= "</div>"; # row |
|
| 416 | 416 | |
| 417 | - $rv .= "</div>"; # header |
|
| 417 | + $rv .= "</div>"; # header |
|
| 418 | 418 | |
| 419 | - /* content */ |
|
| 419 | + /* content */ |
|
| 420 | 420 | |
| 421 | - $lang = $line['lang'] ? $line['lang'] : "en"; |
|
| 422 | - $rv .= "<div class='content' lang='$lang'>"; |
|
| 421 | + $lang = $line['lang'] ? $line['lang'] : "en"; |
|
| 422 | + $rv .= "<div class='content' lang='$lang'>"; |
|
| 423 | 423 | |
| 424 | - /* content body */ |
|
| 424 | + /* content body */ |
|
| 425 | 425 | |
| 426 | - $rv .= $line["content"]; |
|
| 426 | + $rv .= $line["content"]; |
|
| 427 | 427 | |
| 428 | 428 | $rv .= Article::format_article_enclosures($id, |
| 429 | 429 | $line["always_display_enclosures"], |
| 430 | 430 | $line["content"], |
| 431 | 431 | $line["hide_images"]); |
| 432 | 432 | |
| 433 | - $rv .= "</div>"; # content |
|
| 433 | + $rv .= "</div>"; # content |
|
| 434 | 434 | |
| 435 | - $rv .= "</div>"; # post |
|
| 435 | + $rv .= "</div>"; # post |
|
| 436 | 436 | |
| 437 | - } |
|
| 437 | + } |
|
| 438 | 438 | |
| 439 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
|
| 440 | - $rv = $p->hook_format_article($rv, $line, true); |
|
| 441 | - } |
|
| 439 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
|
| 440 | + $rv = $p->hook_format_article($rv, $line, true); |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | - return $rv; |
|
| 443 | + return $rv; |
|
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - public function rss() { |
|
| 448 | - $feed = clean($_REQUEST["id"]); |
|
| 449 | - $key = clean($_REQUEST["key"]); |
|
| 450 | - $is_cat = clean($_REQUEST["is_cat"]); |
|
| 451 | - $limit = (int)clean($_REQUEST["limit"]); |
|
| 452 | - $offset = (int)clean($_REQUEST["offset"]); |
|
| 447 | + public function rss() { |
|
| 448 | + $feed = clean($_REQUEST["id"]); |
|
| 449 | + $key = clean($_REQUEST["key"]); |
|
| 450 | + $is_cat = clean($_REQUEST["is_cat"]); |
|
| 451 | + $limit = (int)clean($_REQUEST["limit"]); |
|
| 452 | + $offset = (int)clean($_REQUEST["offset"]); |
|
| 453 | 453 | |
| 454 | - $search = clean($_REQUEST["q"]); |
|
| 455 | - $view_mode = clean($_REQUEST["view-mode"]); |
|
| 456 | - $order = clean($_REQUEST["order"]); |
|
| 457 | - $start_ts = clean($_REQUEST["ts"]); |
|
| 454 | + $search = clean($_REQUEST["q"]); |
|
| 455 | + $view_mode = clean($_REQUEST["view-mode"]); |
|
| 456 | + $order = clean($_REQUEST["order"]); |
|
| 457 | + $start_ts = clean($_REQUEST["ts"]); |
|
| 458 | 458 | |
| 459 | - $format = clean($_REQUEST['format']); |
|
| 460 | - $orig_guid = clean($_REQUEST["orig_guid"]); |
|
| 459 | + $format = clean($_REQUEST['format']); |
|
| 460 | + $orig_guid = clean($_REQUEST["orig_guid"]); |
|
| 461 | 461 | |
| 462 | - if (!$format) $format = 'atom'; |
|
| 462 | + if (!$format) $format = 'atom'; |
|
| 463 | 463 | |
| 464 | - if (SINGLE_USER_MODE) { |
|
| 465 | - authenticate_user("admin", null); |
|
| 466 | - } |
|
| 464 | + if (SINGLE_USER_MODE) { |
|
| 465 | + authenticate_user("admin", null); |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | - $owner_id = false; |
|
| 468 | + $owner_id = false; |
|
| 469 | 469 | |
| 470 | - if ($key) { |
|
| 471 | - $sth = $this->pdo->prepare("SELECT owner_uid FROM |
|
| 470 | + if ($key) { |
|
| 471 | + $sth = $this->pdo->prepare("SELECT owner_uid FROM |
|
| 472 | 472 | ttrss_access_keys WHERE access_key = ? AND feed_id = ?"); |
| 473 | - $sth->execute([$key, $feed]); |
|
| 473 | + $sth->execute([$key, $feed]); |
|
| 474 | 474 | |
| 475 | - if ($row = $sth->fetch()) |
|
| 476 | - $owner_id = $row["owner_uid"]; |
|
| 477 | - } |
|
| 475 | + if ($row = $sth->fetch()) |
|
| 476 | + $owner_id = $row["owner_uid"]; |
|
| 477 | + } |
|
| 478 | 478 | |
| 479 | - if ($owner_id) { |
|
| 480 | - $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
|
| 481 | - $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts); |
|
| 482 | - } else { |
|
| 483 | - header('HTTP/1.1 403 Forbidden'); |
|
| 484 | - } |
|
| 485 | - } |
|
| 479 | + if ($owner_id) { |
|
| 480 | + $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
|
| 481 | + $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts); |
|
| 482 | + } else { |
|
| 483 | + header('HTTP/1.1 403 Forbidden'); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | 486 | |
| 487 | - public function updateTask() { |
|
| 488 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
| 489 | - } |
|
| 487 | + public function updateTask() { |
|
| 488 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - public function housekeepingTask() { |
|
| 492 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
|
| 493 | - } |
|
| 491 | + public function housekeepingTask() { |
|
| 492 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - public function globalUpdateFeeds() { |
|
| 496 | - RPC::updaterandomfeed_real(); |
|
| 495 | + public function globalUpdateFeeds() { |
|
| 496 | + RPC::updaterandomfeed_real(); |
|
| 497 | 497 | |
| 498 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
| 499 | - } |
|
| 498 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - public function sharepopup() { |
|
| 502 | - if (SINGLE_USER_MODE) { |
|
| 503 | - login_sequence(); |
|
| 504 | - } |
|
| 501 | + public function sharepopup() { |
|
| 502 | + if (SINGLE_USER_MODE) { |
|
| 503 | + login_sequence(); |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 507 | - ?> |
|
| 506 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 507 | + ?> |
|
| 508 | 508 | <!DOCTYPE html> |
| 509 | 509 | <html> |
| 510 | 510 | <head> |
| 511 | 511 | <title><?php echo __("Share with Tiny Tiny RSS") ?></title> |
| 512 | 512 | <?php |
| 513 | - echo stylesheet_tag("css/default.css"); |
|
| 514 | - echo javascript_tag("lib/prototype.js"); |
|
| 515 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
| 516 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 517 | - echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") |
|
| 518 | - ?> |
|
| 513 | + echo stylesheet_tag("css/default.css"); |
|
| 514 | + echo javascript_tag("lib/prototype.js"); |
|
| 515 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
| 516 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 517 | + echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") |
|
| 518 | + ?> |
|
| 519 | 519 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| 520 | 520 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
| 521 | 521 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
@@ -537,29 +537,29 @@ discard block |
||
| 537 | 537 | |
| 538 | 538 | <?php |
| 539 | 539 | |
| 540 | - $action = clean($_REQUEST["action"]); |
|
| 540 | + $action = clean($_REQUEST["action"]); |
|
| 541 | 541 | |
| 542 | - if ($_SESSION["uid"]) { |
|
| 542 | + if ($_SESSION["uid"]) { |
|
| 543 | 543 | |
| 544 | - if ($action == 'share') { |
|
| 544 | + if ($action == 'share') { |
|
| 545 | 545 | |
| 546 | - $title = strip_tags(clean($_REQUEST["title"])); |
|
| 547 | - $url = strip_tags(clean($_REQUEST["url"])); |
|
| 548 | - $content = strip_tags(clean($_REQUEST["content"])); |
|
| 549 | - $labels = strip_tags(clean($_REQUEST["labels"])); |
|
| 546 | + $title = strip_tags(clean($_REQUEST["title"])); |
|
| 547 | + $url = strip_tags(clean($_REQUEST["url"])); |
|
| 548 | + $content = strip_tags(clean($_REQUEST["content"])); |
|
| 549 | + $labels = strip_tags(clean($_REQUEST["labels"])); |
|
| 550 | 550 | |
| 551 | - Article::create_published_article($title, $url, $content, $labels, |
|
| 552 | - $_SESSION["uid"]); |
|
| 551 | + Article::create_published_article($title, $url, $content, $labels, |
|
| 552 | + $_SESSION["uid"]); |
|
| 553 | 553 | |
| 554 | - print "<script type='text/javascript'>"; |
|
| 555 | - print "window.close();"; |
|
| 556 | - print "</script>"; |
|
| 554 | + print "<script type='text/javascript'>"; |
|
| 555 | + print "window.close();"; |
|
| 556 | + print "</script>"; |
|
| 557 | 557 | |
| 558 | - } else { |
|
| 559 | - $title = htmlspecialchars(clean($_REQUEST["title"])); |
|
| 560 | - $url = htmlspecialchars(clean($_REQUEST["url"])); |
|
| 558 | + } else { |
|
| 559 | + $title = htmlspecialchars(clean($_REQUEST["title"])); |
|
| 560 | + $url = htmlspecialchars(clean($_REQUEST["url"])); |
|
| 561 | 561 | |
| 562 | - ?> |
|
| 562 | + ?> |
|
| 563 | 563 | <form id='share_form' name='share_form'> |
| 564 | 564 | |
| 565 | 565 | <input type="hidden" name="op" value="sharepopup"> |
@@ -599,12 +599,12 @@ discard block |
||
| 599 | 599 | </form> |
| 600 | 600 | <?php |
| 601 | 601 | |
| 602 | - } |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - } else { |
|
| 604 | + } else { |
|
| 605 | 605 | |
| 606 | - $return = urlencode(make_self_url()); |
|
| 607 | - print_error("Not logged in"); ?> |
|
| 606 | + $return = urlencode(make_self_url()); |
|
| 607 | + print_error("Not logged in"); ?> |
|
| 608 | 608 | |
| 609 | 609 | <form action="public.php?return=<?php echo $return ?>" method="post"> |
| 610 | 610 | |
@@ -636,90 +636,90 @@ discard block |
||
| 636 | 636 | |
| 637 | 637 | </form> |
| 638 | 638 | <?php |
| 639 | - } |
|
| 639 | + } |
|
| 640 | 640 | |
| 641 | - print "</div></body></html>"; |
|
| 642 | - } |
|
| 641 | + print "</div></body></html>"; |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | - public function login() { |
|
| 645 | - if (!SINGLE_USER_MODE) { |
|
| 644 | + public function login() { |
|
| 645 | + if (!SINGLE_USER_MODE) { |
|
| 646 | 646 | |
| 647 | - $login = clean($_POST["login"]); |
|
| 648 | - $password = clean($_POST["password"]); |
|
| 649 | - $remember_me = clean($_POST["remember_me"]); |
|
| 647 | + $login = clean($_POST["login"]); |
|
| 648 | + $password = clean($_POST["password"]); |
|
| 649 | + $remember_me = clean($_POST["remember_me"]); |
|
| 650 | 650 | |
| 651 | - if ($remember_me) { |
|
| 652 | - session_set_cookie_params(SESSION_COOKIE_LIFETIME); |
|
| 653 | - } else { |
|
| 654 | - session_set_cookie_params(0); |
|
| 655 | - } |
|
| 651 | + if ($remember_me) { |
|
| 652 | + session_set_cookie_params(SESSION_COOKIE_LIFETIME); |
|
| 653 | + } else { |
|
| 654 | + session_set_cookie_params(0); |
|
| 655 | + } |
|
| 656 | 656 | |
| 657 | - if (authenticate_user($login, $password)) { |
|
| 658 | - $_POST["password"] = ""; |
|
| 657 | + if (authenticate_user($login, $password)) { |
|
| 658 | + $_POST["password"] = ""; |
|
| 659 | 659 | |
| 660 | - if (get_schema_version() >= 120) { |
|
| 661 | - $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); |
|
| 662 | - } |
|
| 660 | + if (get_schema_version() >= 120) { |
|
| 661 | + $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); |
|
| 662 | + } |
|
| 663 | 663 | |
| 664 | - $_SESSION["ref_schema_version"] = get_schema_version(true); |
|
| 665 | - $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]); |
|
| 664 | + $_SESSION["ref_schema_version"] = get_schema_version(true); |
|
| 665 | + $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]); |
|
| 666 | 666 | |
| 667 | - if (clean($_POST["profile"])) { |
|
| 667 | + if (clean($_POST["profile"])) { |
|
| 668 | 668 | |
| 669 | - $profile = (int) clean($_POST["profile"]); |
|
| 669 | + $profile = (int) clean($_POST["profile"]); |
|
| 670 | 670 | |
| 671 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
| 671 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
| 672 | 672 | WHERE id = ? AND owner_uid = ?"); |
| 673 | - $sth->execute([$profile, $_SESSION['uid']]); |
|
| 673 | + $sth->execute([$profile, $_SESSION['uid']]); |
|
| 674 | 674 | |
| 675 | - if ($sth->fetch()) { |
|
| 676 | - $_SESSION["profile"] = $profile; |
|
| 677 | - } else { |
|
| 678 | - $_SESSION["profile"] = null; |
|
| 675 | + if ($sth->fetch()) { |
|
| 676 | + $_SESSION["profile"] = $profile; |
|
| 677 | + } else { |
|
| 678 | + $_SESSION["profile"] = null; |
|
| 679 | 679 | } |
| 680 | - } |
|
| 681 | - } else { |
|
| 680 | + } |
|
| 681 | + } else { |
|
| 682 | 682 | |
| 683 | - // start an empty session to deliver login error message |
|
| 684 | - @session_start(); |
|
| 683 | + // start an empty session to deliver login error message |
|
| 684 | + @session_start(); |
|
| 685 | 685 | |
| 686 | - if (!isset($_SESSION["login_error_msg"])) |
|
| 687 | - $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
| 686 | + if (!isset($_SESSION["login_error_msg"])) |
|
| 687 | + $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
| 688 | 688 | |
| 689 | - user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
| 690 | - } |
|
| 689 | + user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | - $return = clean($_REQUEST['return']); |
|
| 692 | + $return = clean($_REQUEST['return']); |
|
| 693 | 693 | |
| 694 | - if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
|
| 695 | - header("Location: " . clean($_REQUEST['return'])); |
|
| 696 | - } else { |
|
| 697 | - header("Location: " . get_self_url_prefix()); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - } |
|
| 694 | + if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
|
| 695 | + header("Location: " . clean($_REQUEST['return'])); |
|
| 696 | + } else { |
|
| 697 | + header("Location: " . get_self_url_prefix()); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | 701 | |
| 702 | - public function subscribe() { |
|
| 703 | - if (SINGLE_USER_MODE) { |
|
| 704 | - login_sequence(); |
|
| 705 | - } |
|
| 702 | + public function subscribe() { |
|
| 703 | + if (SINGLE_USER_MODE) { |
|
| 704 | + login_sequence(); |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - if ($_SESSION["uid"]) { |
|
| 707 | + if ($_SESSION["uid"]) { |
|
| 708 | 708 | |
| 709 | - $feed_url = trim(clean($_REQUEST["feed_url"])); |
|
| 709 | + $feed_url = trim(clean($_REQUEST["feed_url"])); |
|
| 710 | 710 | |
| 711 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 712 | - ?> |
|
| 711 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 712 | + ?> |
|
| 713 | 713 | <!DOCTYPE html> |
| 714 | 714 | <html> |
| 715 | 715 | <head> |
| 716 | 716 | <title>Tiny Tiny RSS</title> |
| 717 | 717 | <?php |
| 718 | - echo stylesheet_tag("css/default.css"); |
|
| 719 | - echo javascript_tag("lib/prototype.js"); |
|
| 720 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
| 721 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 722 | - ?> |
|
| 718 | + echo stylesheet_tag("css/default.css"); |
|
| 719 | + echo javascript_tag("lib/prototype.js"); |
|
| 720 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
| 721 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 722 | + ?> |
|
| 723 | 723 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| 724 | 724 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
| 725 | 725 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
@@ -738,8 +738,8 @@ discard block |
||
| 738 | 738 | <div class='content'> |
| 739 | 739 | <?php |
| 740 | 740 | |
| 741 | - if (!$feed_url) { |
|
| 742 | - ?> |
|
| 741 | + if (!$feed_url) { |
|
| 742 | + ?> |
|
| 743 | 743 | <form method="post"> |
| 744 | 744 | <input type="hidden" name="op" value="subscribe"> |
| 745 | 745 | <fieldset> |
@@ -754,101 +754,101 @@ discard block |
||
| 754 | 754 | <a href="index.php"><?php echo __("Return to Tiny Tiny RSS") ?></a> |
| 755 | 755 | </form> |
| 756 | 756 | <?php |
| 757 | - } else { |
|
| 758 | - |
|
| 759 | - $rc = Feeds::subscribe_to_feed($feed_url); |
|
| 760 | - $feed_urls = false; |
|
| 761 | - |
|
| 762 | - switch ($rc['code']) { |
|
| 763 | - case 0: |
|
| 764 | - print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
| 765 | - break; |
|
| 766 | - case 1: |
|
| 767 | - print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
| 768 | - break; |
|
| 769 | - case 2: |
|
| 770 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
| 771 | - break; |
|
| 772 | - case 3: |
|
| 773 | - print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
| 774 | - break; |
|
| 775 | - case 4: |
|
| 776 | - $feed_urls = $rc["feeds"]; |
|
| 777 | - break; |
|
| 778 | - case 5: |
|
| 779 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
| 780 | - break; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - if ($feed_urls) { |
|
| 784 | - |
|
| 785 | - print "<form action='public.php'>"; |
|
| 786 | - print "<input type='hidden' name='op' value='subscribe'>"; |
|
| 787 | - |
|
| 788 | - print "<fieldset>"; |
|
| 789 | - print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
| 790 | - print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
|
| 791 | - |
|
| 792 | - foreach ($feed_urls as $url => $name) { |
|
| 793 | - $url = htmlspecialchars($url); |
|
| 794 | - $name = htmlspecialchars($name); |
|
| 795 | - |
|
| 796 | - print "<option value=\"$url\">$name</option>"; |
|
| 797 | - } |
|
| 757 | + } else { |
|
| 758 | + |
|
| 759 | + $rc = Feeds::subscribe_to_feed($feed_url); |
|
| 760 | + $feed_urls = false; |
|
| 761 | + |
|
| 762 | + switch ($rc['code']) { |
|
| 763 | + case 0: |
|
| 764 | + print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
| 765 | + break; |
|
| 766 | + case 1: |
|
| 767 | + print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
| 768 | + break; |
|
| 769 | + case 2: |
|
| 770 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
| 771 | + break; |
|
| 772 | + case 3: |
|
| 773 | + print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
| 774 | + break; |
|
| 775 | + case 4: |
|
| 776 | + $feed_urls = $rc["feeds"]; |
|
| 777 | + break; |
|
| 778 | + case 5: |
|
| 779 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
| 780 | + break; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + if ($feed_urls) { |
|
| 784 | + |
|
| 785 | + print "<form action='public.php'>"; |
|
| 786 | + print "<input type='hidden' name='op' value='subscribe'>"; |
|
| 787 | + |
|
| 788 | + print "<fieldset>"; |
|
| 789 | + print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
| 790 | + print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
|
| 791 | + |
|
| 792 | + foreach ($feed_urls as $url => $name) { |
|
| 793 | + $url = htmlspecialchars($url); |
|
| 794 | + $name = htmlspecialchars($name); |
|
| 795 | + |
|
| 796 | + print "<option value=\"$url\">$name</option>"; |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - print "</select>"; |
|
| 800 | - print "</fieldset>"; |
|
| 799 | + print "</select>"; |
|
| 800 | + print "</fieldset>"; |
|
| 801 | 801 | |
| 802 | - print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>"; |
|
| 803 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 802 | + print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>"; |
|
| 803 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 804 | 804 | |
| 805 | - print "</form>"; |
|
| 806 | - } |
|
| 805 | + print "</form>"; |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | - $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
| 808 | + $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
| 809 | 809 | |
| 810 | - if ($rc['code'] <= 2){ |
|
| 811 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 810 | + if ($rc['code'] <= 2){ |
|
| 811 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 812 | 812 | feed_url = ? AND owner_uid = ?"); |
| 813 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 814 | - $row = $sth->fetch(); |
|
| 813 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 814 | + $row = $sth->fetch(); |
|
| 815 | 815 | |
| 816 | - $feed_id = $row["id"]; |
|
| 817 | - } else { |
|
| 818 | - $feed_id = 0; |
|
| 819 | - } |
|
| 816 | + $feed_id = $row["id"]; |
|
| 817 | + } else { |
|
| 818 | + $feed_id = 0; |
|
| 819 | + } |
|
| 820 | 820 | |
| 821 | - if ($feed_id) { |
|
| 822 | - print "<form method='GET' action=\"$tp_uri\"> |
|
| 821 | + if ($feed_id) { |
|
| 822 | + print "<form method='GET' action=\"$tp_uri\"> |
|
| 823 | 823 | <input type='hidden' name='tab' value='feedConfig'> |
| 824 | 824 | <input type='hidden' name='method' value='editfeed'> |
| 825 | 825 | <input type='hidden' name='methodparam' value='$feed_id'> |
| 826 | 826 | <button dojoType='dijit.form.Button' class='alt-info' type='submit'>".__("Edit subscription options")."</button> |
| 827 | 827 | <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a> |
| 828 | 828 | </form>"; |
| 829 | - } |
|
| 830 | - } |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | 831 | |
| 832 | - print "</div></div></body></html>"; |
|
| 832 | + print "</div></div></body></html>"; |
|
| 833 | 833 | |
| 834 | - } else { |
|
| 835 | - render_login_form(); |
|
| 836 | - } |
|
| 837 | - } |
|
| 834 | + } else { |
|
| 835 | + render_login_form(); |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | - public function index() { |
|
| 840 | - header("Content-Type: text/plain"); |
|
| 841 | - print error_json(13); |
|
| 842 | - } |
|
| 839 | + public function index() { |
|
| 840 | + header("Content-Type: text/plain"); |
|
| 841 | + print error_json(13); |
|
| 842 | + } |
|
| 843 | 843 | |
| 844 | - public function forgotpass() { |
|
| 845 | - startup_gettext(); |
|
| 846 | - session_start(); |
|
| 844 | + public function forgotpass() { |
|
| 845 | + startup_gettext(); |
|
| 846 | + session_start(); |
|
| 847 | 847 | |
| 848 | - @$hash = clean($_REQUEST["hash"]); |
|
| 848 | + @$hash = clean($_REQUEST["hash"]); |
|
| 849 | 849 | |
| 850 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 851 | - ?> |
|
| 850 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 851 | + ?> |
|
| 852 | 852 | <!DOCTYPE html> |
| 853 | 853 | <html> |
| 854 | 854 | <head> |
@@ -857,11 +857,11 @@ discard block |
||
| 857 | 857 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
| 858 | 858 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| 859 | 859 | <?php |
| 860 | - echo stylesheet_tag("css/default.css"); |
|
| 861 | - echo javascript_tag("lib/prototype.js"); |
|
| 862 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
| 863 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 864 | - ?> |
|
| 860 | + echo stylesheet_tag("css/default.css"); |
|
| 861 | + echo javascript_tag("lib/prototype.js"); |
|
| 862 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
| 863 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 864 | + ?> |
|
| 865 | 865 | </head> |
| 866 | 866 | <body class='flat ttrss_utility'> |
| 867 | 867 | <div class='container'> |
@@ -876,52 +876,52 @@ discard block |
||
| 876 | 876 | </script> |
| 877 | 877 | <?php |
| 878 | 878 | |
| 879 | - print "<h1>".__("Password recovery")."</h1>"; |
|
| 880 | - print "<div class='content'>"; |
|
| 879 | + print "<h1>".__("Password recovery")."</h1>"; |
|
| 880 | + print "<div class='content'>"; |
|
| 881 | 881 | |
| 882 | - @$method = clean($_POST['method']); |
|
| 882 | + @$method = clean($_POST['method']); |
|
| 883 | 883 | |
| 884 | - if ($hash) { |
|
| 885 | - $login = clean($_REQUEST["login"]); |
|
| 884 | + if ($hash) { |
|
| 885 | + $login = clean($_REQUEST["login"]); |
|
| 886 | 886 | |
| 887 | - if ($login) { |
|
| 888 | - $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users |
|
| 887 | + if ($login) { |
|
| 888 | + $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users |
|
| 889 | 889 | WHERE login = ?"); |
| 890 | - $sth->execute([$login]); |
|
| 890 | + $sth->execute([$login]); |
|
| 891 | 891 | |
| 892 | - if ($row = $sth->fetch()) { |
|
| 893 | - $id = $row["id"]; |
|
| 894 | - $resetpass_token_full = $row["resetpass_token"]; |
|
| 895 | - list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
|
| 892 | + if ($row = $sth->fetch()) { |
|
| 893 | + $id = $row["id"]; |
|
| 894 | + $resetpass_token_full = $row["resetpass_token"]; |
|
| 895 | + list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
|
| 896 | 896 | |
| 897 | - if ($timestamp && $resetpass_token && |
|
| 898 | - $timestamp >= time() - 15*60*60 && |
|
| 899 | - $resetpass_token == $hash) { |
|
| 897 | + if ($timestamp && $resetpass_token && |
|
| 898 | + $timestamp >= time() - 15*60*60 && |
|
| 899 | + $resetpass_token == $hash) { |
|
| 900 | 900 | |
| 901 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
|
| 901 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
|
| 902 | 902 | WHERE id = ?"); |
| 903 | - $sth->execute([$id]); |
|
| 903 | + $sth->execute([$id]); |
|
| 904 | 904 | |
| 905 | - Pref_Users::resetUserPassword($id, true); |
|
| 905 | + Pref_Users::resetUserPassword($id, true); |
|
| 906 | 906 | |
| 907 | - print "<p>"."Completed."."</p>"; |
|
| 907 | + print "<p>"."Completed."."</p>"; |
|
| 908 | 908 | |
| 909 | - } else { |
|
| 910 | - print_error("Some of the information provided is missing or incorrect."); |
|
| 911 | - } |
|
| 912 | - } else { |
|
| 913 | - print_error("Some of the information provided is missing or incorrect."); |
|
| 914 | - } |
|
| 915 | - } else { |
|
| 916 | - print_error("Some of the information provided is missing or incorrect."); |
|
| 917 | - } |
|
| 909 | + } else { |
|
| 910 | + print_error("Some of the information provided is missing or incorrect."); |
|
| 911 | + } |
|
| 912 | + } else { |
|
| 913 | + print_error("Some of the information provided is missing or incorrect."); |
|
| 914 | + } |
|
| 915 | + } else { |
|
| 916 | + print_error("Some of the information provided is missing or incorrect."); |
|
| 917 | + } |
|
| 918 | 918 | |
| 919 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 919 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 920 | 920 | |
| 921 | - } else if (!$method) { |
|
| 922 | - print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address.")); |
|
| 921 | + } else if (!$method) { |
|
| 922 | + print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address.")); |
|
| 923 | 923 | |
| 924 | - print "<form method='POST' action='public.php'> |
|
| 924 | + print "<form method='POST' action='public.php'> |
|
| 925 | 925 | <input type='hidden' name='method' value='do'> |
| 926 | 926 | <input type='hidden' name='op' value='forgotpass'> |
| 927 | 927 | |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | <input dojoType='dijit.form.TextBox' type='email' name='email' value='' required> |
| 936 | 936 | </fieldset>"; |
| 937 | 937 | |
| 938 | - $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
| 939 | - $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
| 938 | + $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
| 939 | + $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
| 940 | 940 | |
| 941 | - print "<fieldset> |
|
| 941 | + print "<fieldset> |
|
| 942 | 942 | <label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label> |
| 943 | 943 | <input dojoType='dijit.form.TextBox' type='text' name='test' value='' required> |
| 944 | 944 | </fieldset> |
@@ -950,109 +950,109 @@ discard block |
||
| 950 | 950 | </fieldset> |
| 951 | 951 | |
| 952 | 952 | </form>"; |
| 953 | - } else if ($method == 'do') { |
|
| 953 | + } else if ($method == 'do') { |
|
| 954 | 954 | |
| 955 | - $login = clean($_POST["login"]); |
|
| 956 | - $email = clean($_POST["email"]); |
|
| 957 | - $test = clean($_POST["test"]); |
|
| 955 | + $login = clean($_POST["login"]); |
|
| 956 | + $email = clean($_POST["email"]); |
|
| 957 | + $test = clean($_POST["test"]); |
|
| 958 | 958 | |
| 959 | - if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) { |
|
| 960 | - print_error(__('Some of the required form parameters are missing or incorrect.')); |
|
| 959 | + if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) { |
|
| 960 | + print_error(__('Some of the required form parameters are missing or incorrect.')); |
|
| 961 | 961 | |
| 962 | - print "<form method='GET' action='public.php'> |
|
| 962 | + print "<form method='GET' action='public.php'> |
|
| 963 | 963 | <input type='hidden' name='op' value='forgotpass'> |
| 964 | 964 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__("Go back")."</button> |
| 965 | 965 | </form>"; |
| 966 | 966 | |
| 967 | - } else { |
|
| 967 | + } else { |
|
| 968 | 968 | |
| 969 | - // prevent submitting this form multiple times |
|
| 970 | - $_SESSION["pwdreset:testvalue1"] = rand(1, 1000); |
|
| 971 | - $_SESSION["pwdreset:testvalue2"] = rand(1, 1000); |
|
| 969 | + // prevent submitting this form multiple times |
|
| 970 | + $_SESSION["pwdreset:testvalue1"] = rand(1, 1000); |
|
| 971 | + $_SESSION["pwdreset:testvalue2"] = rand(1, 1000); |
|
| 972 | 972 | |
| 973 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users |
|
| 973 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users |
|
| 974 | 974 | WHERE login = ? AND email = ?"); |
| 975 | - $sth->execute([$login, $email]); |
|
| 975 | + $sth->execute([$login, $email]); |
|
| 976 | 976 | |
| 977 | - if ($row = $sth->fetch()) { |
|
| 978 | - print_notice("Password reset instructions are being sent to your email address."); |
|
| 977 | + if ($row = $sth->fetch()) { |
|
| 978 | + print_notice("Password reset instructions are being sent to your email address."); |
|
| 979 | 979 | |
| 980 | - $id = $row["id"]; |
|
| 980 | + $id = $row["id"]; |
|
| 981 | 981 | |
| 982 | - if ($id) { |
|
| 983 | - $resetpass_token = sha1(get_random_bytes(128)); |
|
| 984 | - $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
| 985 | - "&login=" . urlencode($login); |
|
| 982 | + if ($id) { |
|
| 983 | + $resetpass_token = sha1(get_random_bytes(128)); |
|
| 984 | + $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
| 985 | + "&login=" . urlencode($login); |
|
| 986 | 986 | |
| 987 | - require_once "lib/MiniTemplator.class.php"; |
|
| 987 | + require_once "lib/MiniTemplator.class.php"; |
|
| 988 | 988 | |
| 989 | - $tpl = new MiniTemplator; |
|
| 989 | + $tpl = new MiniTemplator; |
|
| 990 | 990 | |
| 991 | - $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); |
|
| 991 | + $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); |
|
| 992 | 992 | |
| 993 | - $tpl->setVariable('LOGIN', $login); |
|
| 994 | - $tpl->setVariable('RESETPASS_LINK', $resetpass_link); |
|
| 995 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
| 993 | + $tpl->setVariable('LOGIN', $login); |
|
| 994 | + $tpl->setVariable('RESETPASS_LINK', $resetpass_link); |
|
| 995 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
| 996 | 996 | |
| 997 | - $tpl->addBlock('message'); |
|
| 997 | + $tpl->addBlock('message'); |
|
| 998 | 998 | |
| 999 | - $message = ""; |
|
| 999 | + $message = ""; |
|
| 1000 | 1000 | |
| 1001 | - $tpl->generateOutputToString($message); |
|
| 1001 | + $tpl->generateOutputToString($message); |
|
| 1002 | 1002 | |
| 1003 | - $mailer = new Mailer(); |
|
| 1003 | + $mailer = new Mailer(); |
|
| 1004 | 1004 | |
| 1005 | - $rc = $mailer->mail(["to_name" => $login, |
|
| 1006 | - "to_address" => $email, |
|
| 1007 | - "subject" => __("[tt-rss] Password reset request"), |
|
| 1008 | - "message" => $message]); |
|
| 1005 | + $rc = $mailer->mail(["to_name" => $login, |
|
| 1006 | + "to_address" => $email, |
|
| 1007 | + "subject" => __("[tt-rss] Password reset request"), |
|
| 1008 | + "message" => $message]); |
|
| 1009 | 1009 | |
| 1010 | - if (!$rc) print_error($mailer->error()); |
|
| 1010 | + if (!$rc) print_error($mailer->error()); |
|
| 1011 | 1011 | |
| 1012 | - $resetpass_token_full = time() . ":" . $resetpass_token; |
|
| 1012 | + $resetpass_token_full = time() . ":" . $resetpass_token; |
|
| 1013 | 1013 | |
| 1014 | - $sth = $this->pdo->prepare("UPDATE ttrss_users |
|
| 1014 | + $sth = $this->pdo->prepare("UPDATE ttrss_users |
|
| 1015 | 1015 | SET resetpass_token = ? |
| 1016 | 1016 | WHERE login = ? AND email = ?"); |
| 1017 | 1017 | |
| 1018 | - $sth->execute([$resetpass_token_full, $login, $email]); |
|
| 1018 | + $sth->execute([$resetpass_token_full, $login, $email]); |
|
| 1019 | 1019 | |
| 1020 | - } else { |
|
| 1021 | - print_error("User ID not found."); |
|
| 1022 | - } |
|
| 1020 | + } else { |
|
| 1021 | + print_error("User ID not found."); |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1024 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1025 | 1025 | |
| 1026 | - } else { |
|
| 1027 | - print_error(__("Sorry, login and email combination not found.")); |
|
| 1026 | + } else { |
|
| 1027 | + print_error(__("Sorry, login and email combination not found.")); |
|
| 1028 | 1028 | |
| 1029 | - print "<form method='GET' action='public.php'> |
|
| 1029 | + print "<form method='GET' action='public.php'> |
|
| 1030 | 1030 | <input type='hidden' name='op' value='forgotpass'> |
| 1031 | 1031 | <button dojoType='dijit.form.Button' type='submit'>".__("Go back")."</button> |
| 1032 | 1032 | </form>"; |
| 1033 | 1033 | |
| 1034 | - } |
|
| 1035 | - } |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | 1036 | |
| 1037 | - } |
|
| 1037 | + } |
|
| 1038 | 1038 | |
| 1039 | - print "</div>"; |
|
| 1040 | - print "</div>"; |
|
| 1041 | - print "</body>"; |
|
| 1042 | - print "</html>"; |
|
| 1039 | + print "</div>"; |
|
| 1040 | + print "</div>"; |
|
| 1041 | + print "</body>"; |
|
| 1042 | + print "</html>"; |
|
| 1043 | 1043 | |
| 1044 | - } |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | - public function dbupdate() { |
|
| 1047 | - startup_gettext(); |
|
| 1046 | + public function dbupdate() { |
|
| 1047 | + startup_gettext(); |
|
| 1048 | 1048 | |
| 1049 | - if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
|
| 1050 | - $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
|
| 1051 | - render_login_form(); |
|
| 1052 | - exit; |
|
| 1053 | - } |
|
| 1049 | + if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
|
| 1050 | + $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
|
| 1051 | + render_login_form(); |
|
| 1052 | + exit; |
|
| 1053 | + } |
|
| 1054 | 1054 | |
| 1055 | - ?> |
|
| 1055 | + ?> |
|
| 1056 | 1056 | <!DOCTYPE html> |
| 1057 | 1057 | <html> |
| 1058 | 1058 | <head> |
@@ -1062,11 +1062,11 @@ discard block |
||
| 1062 | 1062 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
| 1063 | 1063 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
| 1064 | 1064 | <?php |
| 1065 | - echo stylesheet_tag("css/default.css"); |
|
| 1066 | - echo javascript_tag("lib/prototype.js"); |
|
| 1067 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
| 1068 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 1069 | - ?> |
|
| 1065 | + echo stylesheet_tag("css/default.css"); |
|
| 1066 | + echo javascript_tag("lib/prototype.js"); |
|
| 1067 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
| 1068 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 1069 | + ?> |
|
| 1070 | 1070 | <style type="text/css"> |
| 1071 | 1071 | span.ok { color : #009000; font-weight : bold; } |
| 1072 | 1072 | span.err { color : #ff0000; font-weight : bold; } |
@@ -1093,139 +1093,139 @@ discard block |
||
| 1093 | 1093 | <div class="content"> |
| 1094 | 1094 | |
| 1095 | 1095 | <?php |
| 1096 | - @$op = clean($_REQUEST["subop"]); |
|
| 1097 | - $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION); |
|
| 1096 | + @$op = clean($_REQUEST["subop"]); |
|
| 1097 | + $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION); |
|
| 1098 | 1098 | |
| 1099 | - if ($op == "performupdate") { |
|
| 1100 | - if ($updater->isUpdateRequired()) { |
|
| 1099 | + if ($op == "performupdate") { |
|
| 1100 | + if ($updater->isUpdateRequired()) { |
|
| 1101 | 1101 | |
| 1102 | - print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
| 1102 | + print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
| 1103 | 1103 | |
| 1104 | - for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
|
| 1105 | - print "<ul>"; |
|
| 1104 | + for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
|
| 1105 | + print "<ul>"; |
|
| 1106 | 1106 | |
| 1107 | - print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
| 1107 | + print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
| 1108 | 1108 | |
| 1109 | - print "<li>"; |
|
| 1110 | - $result = $updater->performUpdateTo($i, true); |
|
| 1111 | - print "</li>"; |
|
| 1109 | + print "<li>"; |
|
| 1110 | + $result = $updater->performUpdateTo($i, true); |
|
| 1111 | + print "</li>"; |
|
| 1112 | 1112 | |
| 1113 | - if (!$result) { |
|
| 1114 | - print "</ul>"; |
|
| 1113 | + if (!$result) { |
|
| 1114 | + print "</ul>"; |
|
| 1115 | 1115 | |
| 1116 | - print_error("One of the updates failed. Either retry the process or perform updates manually."); |
|
| 1116 | + print_error("One of the updates failed. Either retry the process or perform updates manually."); |
|
| 1117 | 1117 | |
| 1118 | - print "<form method='POST'> |
|
| 1118 | + print "<form method='POST'> |
|
| 1119 | 1119 | <input type='hidden' name='subop' value='performupdate'> |
| 1120 | 1120 | <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Try again")."</button> |
| 1121 | 1121 | <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a> |
| 1122 | 1122 | </form>"; |
| 1123 | 1123 | |
| 1124 | - return; |
|
| 1125 | - } else { |
|
| 1126 | - print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
| 1127 | - print "</ul>"; |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1124 | + return; |
|
| 1125 | + } else { |
|
| 1126 | + print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
| 1127 | + print "</ul>"; |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
|
| 1131 | + print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
|
| 1132 | 1132 | |
| 1133 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1133 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1134 | 1134 | |
| 1135 | - } else { |
|
| 1136 | - print_notice("Tiny Tiny RSS database is up to date."); |
|
| 1135 | + } else { |
|
| 1136 | + print_notice("Tiny Tiny RSS database is up to date."); |
|
| 1137 | 1137 | |
| 1138 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1139 | - } |
|
| 1140 | - } else { |
|
| 1141 | - if ($updater->isUpdateRequired()) { |
|
| 1138 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1139 | + } |
|
| 1140 | + } else { |
|
| 1141 | + if ($updater->isUpdateRequired()) { |
|
| 1142 | 1142 | |
| 1143 | - print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", |
|
| 1144 | - $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>"; |
|
| 1143 | + print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", |
|
| 1144 | + $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>"; |
|
| 1145 | 1145 | |
| 1146 | - if (DB_TYPE == "mysql") { |
|
| 1147 | - print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ". |
|
| 1148 | - "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>"); |
|
| 1149 | - } else { |
|
| 1150 | - print_warning("Please backup your database before proceeding."); |
|
| 1151 | - } |
|
| 1146 | + if (DB_TYPE == "mysql") { |
|
| 1147 | + print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ". |
|
| 1148 | + "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>"); |
|
| 1149 | + } else { |
|
| 1150 | + print_warning("Please backup your database before proceeding."); |
|
| 1151 | + } |
|
| 1152 | 1152 | |
| 1153 | - print "<form method='POST'> |
|
| 1153 | + print "<form method='POST'> |
|
| 1154 | 1154 | <input type='hidden' name='subop' value='performupdate'> |
| 1155 | 1155 | <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Perform updates")."</button> |
| 1156 | 1156 | </form>"; |
| 1157 | 1157 | |
| 1158 | - } else { |
|
| 1158 | + } else { |
|
| 1159 | 1159 | |
| 1160 | - print_notice("Tiny Tiny RSS database is up to date."); |
|
| 1160 | + print_notice("Tiny Tiny RSS database is up to date."); |
|
| 1161 | 1161 | |
| 1162 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1163 | - } |
|
| 1164 | - } |
|
| 1165 | - ?> |
|
| 1162 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
| 1163 | + } |
|
| 1164 | + } |
|
| 1165 | + ?> |
|
| 1166 | 1166 | |
| 1167 | 1167 | </div> |
| 1168 | 1168 | </div> |
| 1169 | 1169 | </body> |
| 1170 | 1170 | </html> |
| 1171 | 1171 | <?php |
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - public function cached_url() { |
|
| 1175 | - list ($cache_dir, $filename) = explode("/", $_GET["file"], 2); |
|
| 1176 | - |
|
| 1177 | - // we do not allow files with extensions at the moment |
|
| 1178 | - $filename = str_replace(".", "", $filename); |
|
| 1179 | - |
|
| 1180 | - $cache = new DiskCache($cache_dir); |
|
| 1181 | - |
|
| 1182 | - if ($cache->exists($filename)) { |
|
| 1183 | - $cache->send($filename); |
|
| 1184 | - } else { |
|
| 1185 | - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
| 1186 | - echo "File not found."; |
|
| 1187 | - } |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - private function make_article_tag_uri($id, $timestamp) { |
|
| 1191 | - |
|
| 1192 | - $timestamp = date("Y-m-d", strtotime($timestamp)); |
|
| 1193 | - |
|
| 1194 | - return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - // this should be used very carefully because this endpoint is exposed to unauthenticated users |
|
| 1198 | - // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available |
|
| 1199 | - // in general, don't do anything user-related in here and do not modify $_SESSION |
|
| 1200 | - public function pluginhandler() { |
|
| 1201 | - $host = new PluginHost(); |
|
| 1202 | - |
|
| 1203 | - $plugin_name = clean_filename($_REQUEST["plugin"]); |
|
| 1204 | - $method = clean($_REQUEST["pmethod"]); |
|
| 1205 | - |
|
| 1206 | - $host->load($plugin_name, PluginHost::KIND_USER, 0); |
|
| 1207 | - $host->load_data(); |
|
| 1208 | - |
|
| 1209 | - $plugin = $host->get_plugin($plugin_name); |
|
| 1210 | - |
|
| 1211 | - if ($plugin) { |
|
| 1212 | - if (method_exists($plugin, $method)) { |
|
| 1213 | - if ($plugin->is_public_method($method)) { |
|
| 1214 | - $plugin->$method(); |
|
| 1215 | - } else { |
|
| 1216 | - user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
| 1217 | - header("Content-Type: text/json"); |
|
| 1218 | - print error_json(6); |
|
| 1219 | - } |
|
| 1220 | - } else { |
|
| 1221 | - user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
| 1222 | - header("Content-Type: text/json"); |
|
| 1223 | - print error_json(13); |
|
| 1224 | - } |
|
| 1225 | - } else { |
|
| 1226 | - user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); |
|
| 1227 | - header("Content-Type: text/json"); |
|
| 1228 | - print error_json(14); |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + public function cached_url() { |
|
| 1175 | + list ($cache_dir, $filename) = explode("/", $_GET["file"], 2); |
|
| 1176 | + |
|
| 1177 | + // we do not allow files with extensions at the moment |
|
| 1178 | + $filename = str_replace(".", "", $filename); |
|
| 1179 | + |
|
| 1180 | + $cache = new DiskCache($cache_dir); |
|
| 1181 | + |
|
| 1182 | + if ($cache->exists($filename)) { |
|
| 1183 | + $cache->send($filename); |
|
| 1184 | + } else { |
|
| 1185 | + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
| 1186 | + echo "File not found."; |
|
| 1187 | + } |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + private function make_article_tag_uri($id, $timestamp) { |
|
| 1191 | + |
|
| 1192 | + $timestamp = date("Y-m-d", strtotime($timestamp)); |
|
| 1193 | + |
|
| 1194 | + return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + // this should be used very carefully because this endpoint is exposed to unauthenticated users |
|
| 1198 | + // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available |
|
| 1199 | + // in general, don't do anything user-related in here and do not modify $_SESSION |
|
| 1200 | + public function pluginhandler() { |
|
| 1201 | + $host = new PluginHost(); |
|
| 1202 | + |
|
| 1203 | + $plugin_name = clean_filename($_REQUEST["plugin"]); |
|
| 1204 | + $method = clean($_REQUEST["pmethod"]); |
|
| 1205 | + |
|
| 1206 | + $host->load($plugin_name, PluginHost::KIND_USER, 0); |
|
| 1207 | + $host->load_data(); |
|
| 1208 | + |
|
| 1209 | + $plugin = $host->get_plugin($plugin_name); |
|
| 1210 | + |
|
| 1211 | + if ($plugin) { |
|
| 1212 | + if (method_exists($plugin, $method)) { |
|
| 1213 | + if ($plugin->is_public_method($method)) { |
|
| 1214 | + $plugin->$method(); |
|
| 1215 | + } else { |
|
| 1216 | + user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
| 1217 | + header("Content-Type: text/json"); |
|
| 1218 | + print error_json(6); |
|
| 1219 | + } |
|
| 1220 | + } else { |
|
| 1221 | + user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
| 1222 | + header("Content-Type: text/json"); |
|
| 1223 | + print error_json(13); |
|
| 1224 | + } |
|
| 1225 | + } else { |
|
| 1226 | + user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); |
|
| 1227 | + header("Content-Type: text/json"); |
|
| 1228 | + print error_json(14); |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | 1231 | } |