@@ -34,17 +34,21 @@ private static function loadRedis(){
3434 * Nextcloud share loader
3535 */
3636 private static function loadFromNextcloud ( string $ url ) : array {
37- $ server = substr ( $ url , 0 , strrpos ( $ url , '/s/ ' )+1 );
38- $ share = substr ( $ url , strlen ($ server )+2 );
39- $ share = preg_replace ( '/[^0-9A-Za-z]/ ' , '' , $ share );
37+ // "<server base path> / <possibly index.php> /s/ <token>"
38+ if (preg_match ('/^(https?\:\/\/.*)(?<!index\.php)(\/index\.php)?\/s\/([0-9A-Za-z]+)/ ' , $ url , $ matches ) !== 1 ){
39+ return array ();
40+ }
41+ $ server = $ matches [1 ]; // the base path to nextcloud
42+ $ useindex = !empty ($ matches [2 ]); // used index.php to access files?
43+ $ share = $ matches [3 ]; // the token/ name of share
4044
4145 $ cont = stream_context_create ( array (
4246 "http " => array (
4347 'method ' => "PROPFIND " ,
4448 "header " => "Authorization: Basic " . base64_encode ($ share . ': ' )
4549 )
4650 ));
47- $ data = file_get_contents ( $ server . 'public.php/webdav/ ' , false , $ cont );
51+ $ data = file_get_contents ( $ server . '/ public.php/webdav/ ' , false , $ cont );
4852 $ data = explode ( '<d:href> ' , $ data );
4953
5054 $ poddata = array (
@@ -63,7 +67,7 @@ private static function loadFromNextcloud( string $url ) : array {
6367 $ poddata ['episodes ' ][$ eid ] = array (
6468 'title ' => $ fina ,
6569 'desc ' => '' ,
66- 'url ' => $ server . ' s/ ' . $ share .'/download?path=%2F&files= ' . rawurlencode ( $ fina )
70+ 'url ' => $ server . ( $ useindex ? ' /index.php ' : '' ) . ' / s/ ' . $ share .'/download?path=%2F&files= ' . rawurlencode ( $ fina )
6771 );
6872 $ eid ++;
6973 }
0 commit comments