|
@@ -1,5 +1,5 @@
|
1
|
1
|
<?php
|
2
|
|
-if(!defined('entry') || !entry) die('Not a valid page');
|
|
2
|
+if(!defined('entry') || !entry) die('Not a valid page');
|
3
|
3
|
/* ===========================
|
4
|
4
|
|
5
|
5
|
gelato CMS - A PHP based tumblelog CMS
|
|
@@ -15,32 +15,32 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
15
|
15
|
function version() {
|
16
|
16
|
return "1.0";
|
17
|
17
|
}
|
18
|
|
-
|
|
18
|
+
|
19
|
19
|
function codeName() {
|
20
|
20
|
return "vaniglia RC1";
|
21
|
21
|
}
|
22
|
|
-
|
|
22
|
+
|
23
|
23
|
function beginsWith($str, $sub) {
|
24
|
24
|
return (strpos($str, $sub) === 0);
|
25
|
25
|
}
|
26
|
|
-
|
|
26
|
+
|
27
|
27
|
function endsWith($str, $sub) {
|
28
|
28
|
return (substr($str, strlen($str) - strlen($sub)) == $sub);
|
29
|
29
|
}
|
30
|
|
-
|
|
30
|
+
|
31
|
31
|
function getFileName($fileUrl) {
|
32
|
32
|
$path = explode('/', $fileUrl);
|
33
|
33
|
return $path[count($path)-1];
|
34
|
34
|
}
|
35
|
|
-
|
|
35
|
+
|
36
|
36
|
function isMP3($fileUrl) {
|
37
|
37
|
if (endsWith($fileUrl, ".mp3")) {
|
38
|
38
|
return true;
|
39
|
39
|
} else {
|
40
|
40
|
return false;
|
41
|
41
|
}
|
42
|
|
- }
|
43
|
|
-
|
|
42
|
+ }
|
|
43
|
+
|
44
|
44
|
function getMP3File($remoteFileName) {
|
45
|
45
|
if (isMP3($remoteFileName)) {
|
46
|
46
|
if (getFile($remoteFileName)) {
|
|
@@ -51,48 +51,48 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
51
|
51
|
} elseif (isGoEar($remoteFileName)) {
|
52
|
52
|
return true;
|
53
|
53
|
} elseif (isOdeo($remoteFileName)) {
|
54
|
|
- return true;
|
|
54
|
+ return true;
|
55
|
55
|
} else {
|
56
|
56
|
return false;
|
57
|
57
|
}
|
58
|
58
|
}
|
59
|
|
-
|
|
59
|
+
|
60
|
60
|
function getGoEarCode($songUrl) {
|
61
|
61
|
$pos = strpos($songUrl, "?v=");
|
62
|
62
|
$lon = strlen($songUrl);
|
63
|
63
|
$str = substr($songUrl, $pos + 3, $lon);
|
64
|
64
|
return $str;
|
65
|
65
|
}
|
66
|
|
-
|
|
66
|
+
|
67
|
67
|
function isGoEar($songUrl) {
|
68
|
68
|
if (beginsWith($songUrl, "http://www.goear.com/listen.php?v=") || beginsWith($songUrl, "http://goear.com/listen.php?v="))
|
69
|
69
|
return true;
|
70
|
70
|
else
|
71
|
71
|
return false;
|
72
|
72
|
}
|
73
|
|
-
|
|
73
|
+
|
74
|
74
|
function isOdeo($songUrl){
|
75
|
75
|
if (beginsWith($songUrl, "http://odeo.com/audio/") || beginsWith($songUrl, "http://www.odeo.com/audio/"))
|
76
|
76
|
return true;
|
77
|
77
|
else
|
78
|
78
|
return false;
|
79
|
79
|
}
|
80
|
|
-
|
|
80
|
+
|
81
|
81
|
function getOdeoCode($songUrl) {
|
82
|
82
|
$params = explode("audio/", $songUrl);
|
83
|
83
|
$params2 = explode("/",$params[1]);
|
84
|
84
|
return $params2[0];
|
85
|
85
|
}
|
86
|
|
-
|
|
86
|
+
|
87
|
87
|
function isImageFile($photoUrl) {
|
88
|
88
|
if (endsWith($photoUrl, ".jpg")) { return true; }
|
89
|
89
|
elseif (endsWith($photoUrl, ".gif")) { return true; }
|
90
|
90
|
elseif (endsWith($photoUrl, ".png")) { return true; }
|
91
|
91
|
else { return false; }
|
92
|
92
|
}
|
93
|
|
-
|
|
93
|
+
|
94
|
94
|
function getPhotoFile($remoteFileName) {
|
95
|
|
- if (isImageFile($remoteFileName)) {
|
|
95
|
+ if (isImageFile($remoteFileName)) {
|
96
|
96
|
if (getFile($remoteFileName)) {
|
97
|
97
|
return true;
|
98
|
98
|
} else {
|
|
@@ -102,37 +102,37 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
102
|
102
|
return false;
|
103
|
103
|
}
|
104
|
104
|
}
|
105
|
|
-
|
|
105
|
+
|
106
|
106
|
function getFile($remoteFileName) {
|
107
|
|
- $fileName = "../uploads/".sanitizeName(getFileName($remoteFileName));
|
|
107
|
+ $fileName = "../uploads/".sanitizeName(getFileName($remoteFileName));
|
108
|
108
|
$str = _file_get_contents($remoteFileName);
|
109
|
109
|
if (!$handle = fopen($fileName, 'w')) {
|
110
|
110
|
//die("no se abrio de escritura");
|
111
|
111
|
return false;
|
112
|
112
|
}
|
113
|
|
-
|
|
113
|
+
|
114
|
114
|
if (fwrite($handle, $str) === FALSE) {
|
115
|
115
|
//die("no se escribio");
|
116
|
116
|
return false;
|
117
|
117
|
}
|
118
|
118
|
fclose($handle);
|
119
|
|
- return true;
|
|
119
|
+ return true;
|
120
|
120
|
}
|
121
|
|
-
|
|
121
|
+
|
122
|
122
|
function isVimeoVideo($videoUrl) {
|
123
|
123
|
if (beginsWith($videoUrl, "http://vimeo.com/") || beginsWith($videoUrl, "http://www.vimeo.com/"))
|
124
|
124
|
return true;
|
125
|
125
|
else
|
126
|
126
|
return false;
|
127
|
127
|
}
|
128
|
|
-
|
|
128
|
+
|
129
|
129
|
function getVimeoVideoUrl($videoUrl) {
|
130
|
130
|
if(substr_count($videoUrl,"clip:")==1)
|
131
|
131
|
return array_pop(explode("clip:",$videoUrl));
|
132
|
132
|
else
|
133
|
133
|
return array_pop(explode("/",$videoUrl));
|
134
|
134
|
}
|
135
|
|
-
|
|
135
|
+
|
136
|
136
|
function isYoutubeVideo($videoUrl) {
|
137
|
137
|
$url = explode("?", $videoUrl);
|
138
|
138
|
if((beginsWith($url[0], "http://") && endsWith($url[0], ".youtube.com/watch")) || beginsWith($url[0], "http://youtube.com/watch"))
|
|
@@ -140,14 +140,14 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
140
|
140
|
else
|
141
|
141
|
return false;
|
142
|
142
|
}
|
143
|
|
-
|
|
143
|
+
|
144
|
144
|
function isYahooVideo($videoUrl){
|
145
|
145
|
if (beginsWith($videoUrl, "http://video.yahoo.com/watch/") || beginsWith($videoUrl, "http://www.video.yahoo.com/watch/"))
|
146
|
146
|
return true;
|
147
|
147
|
else
|
148
|
148
|
return false;
|
149
|
149
|
}
|
150
|
|
-
|
|
150
|
+
|
151
|
151
|
function getYahooVideoCode($videoUrl){
|
152
|
152
|
$params = explode("http://video.yahoo.com/watch/", $videoUrl);
|
153
|
153
|
$params2 = explode("/",$params[1]);
|
|
@@ -160,7 +160,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
160
|
160
|
$params2 = explode("&",$params[1]);
|
161
|
161
|
return $params2[0];
|
162
|
162
|
}
|
163
|
|
-
|
|
163
|
+
|
164
|
164
|
function isGoogleVideoUrl($videoUrl){
|
165
|
165
|
if (beginsWith($videoUrl, "http://video.google.com/videoplay?")){
|
166
|
166
|
return true;
|
|
@@ -168,13 +168,13 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
168
|
168
|
return false;
|
169
|
169
|
}
|
170
|
170
|
}
|
171
|
|
-
|
|
171
|
+
|
172
|
172
|
function getGoogleVideoCode($videoUrl){
|
173
|
173
|
$params = explode("?docid=", $videoUrl);
|
174
|
174
|
$params2 = explode("&",$params[1]);
|
175
|
175
|
return $params2[0];
|
176
|
176
|
}
|
177
|
|
-
|
|
177
|
+
|
178
|
178
|
function isDailymotionVideo($videoUrl) {
|
179
|
179
|
if (beginsWith($videoUrl, "http://www.dailymotion.com/video/") || beginsWith($videoUrl, "http://dailymotion.com/video/"))
|
180
|
180
|
return true;
|
|
@@ -187,21 +187,21 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
187
|
187
|
$params2 = explode("_",$params[1]);
|
188
|
188
|
return $params2[0];
|
189
|
189
|
}
|
190
|
|
-
|
|
190
|
+
|
191
|
191
|
function isSlideSharePresentation($videoUrl) {
|
192
|
192
|
if (beginsWith($videoUrl, "[slideshare id="))
|
193
|
193
|
return true;
|
194
|
194
|
else
|
195
|
195
|
return false;
|
196
|
196
|
}
|
197
|
|
-
|
|
197
|
+
|
198
|
198
|
function getSlideSharePresentationCode($videoUrl) {
|
199
|
199
|
$videoUrl = str_replace("[slideshare id=", "", $videoUrl);
|
200
|
200
|
$videoUrl = str_replace("&doc=", " ", $videoUrl);
|
201
|
201
|
$videoUrl = str_replace("&w=", " ", $videoUrl);
|
202
|
202
|
return explode(" ",$videoUrl);
|
203
|
203
|
}
|
204
|
|
-
|
|
204
|
+
|
205
|
205
|
function isVideo($url) {
|
206
|
206
|
if (isYoutubeVideo($url)) { return true; }
|
207
|
207
|
elseif (isVimeoVideo($url)) { return true; }
|
|
@@ -211,12 +211,12 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
211
|
211
|
elseif (isGoogleVideoUrl($url)) { return true; }
|
212
|
212
|
else { return false; }
|
213
|
213
|
}
|
214
|
|
-
|
215
|
|
- function sendMail($to, $title, $body, $from) {
|
|
214
|
+
|
|
215
|
+ function sendMail($to, $title, $body, $from) {
|
216
|
216
|
$rp = trim($from);
|
217
|
217
|
$org = "gelato CMS";
|
218
|
218
|
$mailer = "gelato CMS Mailer";
|
219
|
|
-
|
|
219
|
+
|
220
|
220
|
$head = '';
|
221
|
221
|
$head .= "Content-Type: text/html \r\n";
|
222
|
222
|
$head .= "Date: ". date('r'). " \r\n";
|
|
@@ -228,13 +228,13 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
228
|
228
|
$head .= "X-Sender: $from \r\n";
|
229
|
229
|
$head .= "X-Priority: 3 \r\n";
|
230
|
230
|
$head .= "X-Mailer: $mailer \r\n";
|
231
|
|
-
|
|
231
|
+
|
232
|
232
|
$body = str_replace("\r\n", "\n", $body);
|
233
|
233
|
$body = str_replace("\n", "\r\n", $body);
|
234
|
|
-
|
235
|
|
- return @mail($to, $title, $body, $head);
|
|
234
|
+
|
|
235
|
+ return @mail($to, $title, $body, $head);
|
236
|
236
|
}
|
237
|
|
-
|
|
237
|
+
|
238
|
238
|
function getThemes() {
|
239
|
239
|
$themes_dir = "themes";
|
240
|
240
|
$dirs = array();
|
|
@@ -262,20 +262,20 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
262
|
262
|
//HACK: We need to rework the regular expression to allow the dot
|
263
|
263
|
$ext = substr($name, strlen($name)-3, strlen($name));
|
264
|
264
|
$body = substr($name, 0, strlen($name)-4);
|
265
|
|
-
|
|
265
|
+
|
266
|
266
|
$name = $body.".".$ext;
|
267
|
|
-
|
|
267
|
+
|
268
|
268
|
return $name;
|
269
|
269
|
}
|
270
|
|
-
|
|
270
|
+
|
271
|
271
|
function _file_get_contents($path) {
|
272
|
|
- // Modified function from:
|
|
272
|
+ // Modified function from:
|
273
|
273
|
// http://work.dokoku.net/Anieto2k/_file_get_contents.phps
|
274
|
274
|
// http://www.anieto2k.com/2007/02/09/file_get_contents-y-dreamhost/
|
275
|
275
|
if (!preg_match('/^http/i', $path)) {
|
276
|
276
|
if ($fp = fopen($path, 'r')) {
|
277
|
277
|
return fread($fp, 1024);
|
278
|
|
- } else {
|
|
278
|
+ } else {
|
279
|
279
|
return false;
|
280
|
280
|
}
|
281
|
281
|
} else {
|
|
@@ -297,7 +297,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
297
|
297
|
if (!$data['host'] || $data['scheme'] != "http") {
|
298
|
298
|
return false;
|
299
|
299
|
}
|
300
|
|
-
|
|
300
|
+
|
301
|
301
|
$f = @fsockopen($data['host'], ($data['port']) ? $data['port'] : 80, $e1, $e2, 3);
|
302
|
302
|
if (!$f) {
|
303
|
303
|
return false;
|
|
@@ -307,17 +307,17 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
307
|
307
|
$q .= "Host: " . $data['host'] . "\r\n";
|
308
|
308
|
$q .= "Connection: close\r\n";
|
309
|
309
|
$q .= "Referer: http://www.gelatocms.com/\r\n\r\n";
|
310
|
|
-
|
|
310
|
+
|
311
|
311
|
$recv = "";
|
312
|
312
|
fwrite($f, $q);
|
313
|
313
|
while (!feof($f)) {
|
314
|
314
|
$recv .= fread($f, 1024);
|
315
|
315
|
}
|
316
|
|
-
|
|
316
|
+
|
317
|
317
|
$request = $q;
|
318
|
318
|
$response = substr($recv, 0, strpos($recv, "\r\n\r\n"));
|
319
|
319
|
$body = substr($recv, strpos($recv, "\r\n\r\n") + 4);
|
320
|
|
-
|
|
320
|
+
|
321
|
321
|
if (preg_match('/http\/1\\.[0|1] ([0-9]{3})/i', $response, $res)) {
|
322
|
322
|
if ($res[1][0] != "2") {
|
323
|
323
|
return false;
|
|
@@ -325,7 +325,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
325
|
325
|
} else {
|
326
|
326
|
return false;
|
327
|
327
|
}
|
328
|
|
-
|
|
328
|
+
|
329
|
329
|
if (preg_match('/transfer-encoding:\s*chunked/i', $response)) {
|
330
|
330
|
$tmp_body = $body;
|
331
|
331
|
$new = "";
|
|
@@ -344,12 +344,12 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
344
|
344
|
}
|
345
|
345
|
}
|
346
|
346
|
$body = $new;
|
347
|
|
- }
|
|
347
|
+ }
|
348
|
348
|
return $body;
|
349
|
349
|
}
|
350
|
350
|
}
|
351
|
351
|
}
|
352
|
|
-
|
|
352
|
+
|
353
|
353
|
function get_curl_version() {
|
354
|
354
|
$curl = 0;
|
355
|
355
|
if (is_array(curl_version())) {
|
|
@@ -363,7 +363,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
363
|
363
|
}
|
364
|
364
|
return $curl;
|
365
|
365
|
}
|
366
|
|
-
|
|
366
|
+
|
367
|
367
|
function transform_offset($offset){
|
368
|
368
|
$sp = strpos($offset , ".")? explode("." , $offset) : false;
|
369
|
369
|
if(is_array($sp)){
|
|
@@ -376,7 +376,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
376
|
376
|
}
|
377
|
377
|
return $off;
|
378
|
378
|
}
|
379
|
|
-
|
|
379
|
+
|
380
|
380
|
function getLangs() {
|
381
|
381
|
$langs_dir = "languages";
|
382
|
382
|
$dirs = array();
|
|
@@ -388,7 +388,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
388
|
388
|
$cls_lang_dir = @ dir($dir);
|
389
|
389
|
while (($directory = $cls_lang_dir->read()) !== false) {
|
390
|
390
|
if($directory != "." && $directory != "..") {
|
391
|
|
-
|
|
391
|
+
|
392
|
392
|
$dir2 = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$langs_dir."\\".$directory : $path."/".$langs_dir."/".$directory;
|
393
|
393
|
$dir2 = str_replace("admin\\", "", $dir2);
|
394
|
394
|
$dir2 = str_replace("admin/", "", $dir2);
|
|
@@ -423,14 +423,14 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
423
|
423
|
$source = strip_tags($source, $validTags);
|
424
|
424
|
return preg_replace('/<(.*?)>/ie', "'<'.removeBadAtributes('\\1').'>'", $source);
|
425
|
425
|
}
|
426
|
|
-
|
|
426
|
+
|
427
|
427
|
function removeBadAtributes($sourceTag) {
|
428
|
428
|
$badAtributes = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';
|
429
|
429
|
$sourceTag = stripslashes($sourceTag);
|
430
|
430
|
$sourceTag = preg_replace("/$badAtributes/i", "niceTry", $sourceTag);
|
431
|
431
|
return $sourceTag;
|
432
|
432
|
}
|
433
|
|
-
|
|
433
|
+
|
434
|
434
|
function type2Text($number) {
|
435
|
435
|
$tmpStr = "";
|
436
|
436
|
switch ($number) {
|
|
@@ -438,7 +438,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
438
|
438
|
$tmpStr = "post";
|
439
|
439
|
break;
|
440
|
440
|
case "2":
|
441
|
|
- $tmpStr = "photo";
|
|
441
|
+ $tmpStr = "photo";
|
442
|
442
|
break;
|
443
|
443
|
case "3":
|
444
|
444
|
$tmpStr = "quote";
|
|
@@ -454,11 +454,11 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
454
|
454
|
break;
|
455
|
455
|
case "7":
|
456
|
456
|
$tmpStr = "mp3";
|
457
|
|
- break;
|
|
457
|
+ break;
|
458
|
458
|
}
|
459
|
459
|
return $tmpStr;
|
460
|
460
|
}
|
461
|
|
-
|
|
461
|
+
|
462
|
462
|
function type2Number($string) {
|
463
|
463
|
$tmpStr = "";
|
464
|
464
|
switch ($string) {
|
|
@@ -466,7 +466,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
466
|
466
|
$tmpStr = "1";
|
467
|
467
|
break;
|
468
|
468
|
case "photo":
|
469
|
|
- $tmpStr = "2";
|
|
469
|
+ $tmpStr = "2";
|
470
|
470
|
break;
|
471
|
471
|
case "quote":
|
472
|
472
|
$tmpStr = "3";
|
|
@@ -482,14 +482,16 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
482
|
482
|
break;
|
483
|
483
|
case "mp3":
|
484
|
484
|
$tmpStr = "7";
|
485
|
|
- break;
|
|
485
|
+ break;
|
486
|
486
|
}
|
487
|
487
|
return $tmpStr;
|
488
|
488
|
}
|
489
|
|
-
|
|
489
|
+
|
490
|
490
|
function trimString($string, $len = "") {
|
|
491
|
+ if($len>strlen($string) or $len<1)
|
|
492
|
+ return $string;
|
491
|
493
|
$string = strip_tags($string);
|
492
|
|
- $len = (empty($len)) ? "50" : $len ;
|
|
494
|
+ $len = (empty($len)) ? "50" : $len ;
|
493
|
495
|
return ( strpos($string, " ", $len) ) ? substr_replace($string, "...", $len) : $string ;
|
494
|
496
|
}
|
495
|
497
|
?>
|