44
55// strip away extra parameters text/html; charset=UTF-8
66function clean_content_type ($ content_type ){
7- return preg_replace ('@;.*@ ' , '' , $ content_type );
7+ return trim ( preg_replace ('@;.*@ ' , '' , $ content_type) );
88}
99
1010function is_html ($ content_type ){
11-
12- $ content_type = clean_content_type ($ content_type );
13-
14- $ text = array (
15- //'text/cmd',
16- //'text/css',
17- //'text/csv',
18- //'text/example',
19- 'text/html '
20- //'text/javascript',
21- //'text/plain',
22- //'text/rtf',
23- //'text/vcard',
24- //'text/vnd.abc',
25- //'text/xml'
26- );
27-
28- return in_array ($ content_type , $ text );
11+ return clean_content_type ($ content_type ) == 'text/html ' ;
2912}
3013
31- function base64_url_encode ($ input ){
32- // = at the end is just padding to make the length of the str divisible by 4
33- return rtrim (strtr (base64_encode ($ input ), '+/ ' , '-_ ' ), '= ' );
34- }
35-
36- function base64_url_decode ($ input ){
37- return base64_decode (str_pad (strtr ($ input , '-_ ' , '+/ ' ), strlen ($ input ) % 4 , '= ' , STR_PAD_RIGHT ));
14+ function contains ($ haystack , $ needle ){
15+ return strpos ($ haystack , $ needle ) !== false ;
3816}
3917
4018function in_arrayi ($ needle , $ haystack ){
@@ -130,32 +108,37 @@ function time_ms(){
130108 return round (microtime (true ) * 1000 );
131109}
132110
133- function contains ($ haystack , $ needle ){
134- return strpos ($ haystack , $ needle ) !== false ;
111+ function base64_url_encode ($ input ){
112+ // = at the end is just padding to make the length of the str divisible by 4
113+ return rtrim (strtr (base64_encode ($ input ), '+/ ' , '-_ ' ), '= ' );
135114}
136115
137- function base64_encrypt ($ data , $ key = false ){
116+ function base64_url_decode ($ input ){
117+ return base64_decode (str_pad (strtr ($ input , '-_ ' , '+/ ' ), strlen ($ input ) % 4 , '= ' , STR_PAD_RIGHT ));
118+ }
119+
120+ function url_encrypt ($ url , $ key = false ){
138121
139122 if ($ key ){
140- $ data = str_rot_pass ($ data , $ key );
123+ $ url = str_rot_pass ($ url , $ key );
141124 } else if (Config::get ('encryption_key ' )){
142- $ data = str_rot_pass ($ data , Config::get ('encryption_key ' ));
125+ $ url = str_rot_pass ($ url , Config::get ('encryption_key ' ));
143126 }
144127
145- return base64_url_encode ($ data );
128+ return Config:: get ( ' url_mode ' ) ? base64_url_encode ($ url ) : rawurlencode ( $ url );
146129}
147130
148- function base64_decrypt ( $ data , $ key = false ){
131+ function url_decrypt ( $ url , $ key = false ){
149132
150- $ data = base64_url_decode ($ data );
133+ $ url = Config:: get ( ' url_mode ' ) ? base64_url_decode ($ url ) : rawurldecode ( $ url );
151134
152135 if ($ key ){
153- $ data = str_rot_pass ($ data , $ key , true );
136+ $ url = str_rot_pass ($ url , $ key , true );
154137 } else if (Config::get ('encryption_key ' )){
155- $ data = str_rot_pass ($ data , Config::get ('encryption_key ' ), true );
138+ $ url = str_rot_pass ($ url , Config::get ('encryption_key ' ), true );
156139 }
157140
158- return $ data ;
141+ return $ url ;
159142}
160143
161144// www.youtube.com TO proxy-app.com/index.php?q=encrypt_url(www.youtube.com)
@@ -164,10 +147,11 @@ function proxify_url($url, $base_url = ''){
164147 $ url = htmlspecialchars_decode ($ url );
165148
166149 if ($ base_url ){
150+ $ base_url = add_http ($ base_url );
167151 $ url = rel2abs ($ url , $ base_url );
168152 }
169153
170- return app_url ().'?q= ' .base64_encrypt ($ url );
154+ return app_url ().'?q= ' .url_encrypt ($ url );
171155}
172156
173157function vid_player ($ url , $ width , $ height , $ extension = false ){
0 commit comments