verbalbrew /wordpress/wp-content/plugins/podpress/podpress_class.php

Language PHP Lines 1712
MD5 Hash 12984c8d59d3c7aff9f5236de6b85b2a
Repository https://github.com/bill742/verbalbrew.git View Raw File
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
<?php
/*
License:
 ==============================================================================

    Copyright 2006  Dan Kuykendall  (email : dan@kuykendall.org)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-107  USA
*/
	class podPress_class {
		var $settings = array();

		// Global hardcoded settings
		var $podcasttag_regexp = "/\[podcast:([^]]+)]/";
		var $podcasttag = '[display_podcast]';
		var $podtrac_url = 'http://www.podtrac.com/pts/redirect.mp3?';
		var $blubrry_url = 'http://media.blubrry.com/';
		var $requiredadminrights = 'manage_categories';//'level_7';
		var $realm = 'Premium Subscribers Content';
		var $justposted = false;
		var $uploadurl = '';
		var $uploadpath = '';
		var $tempfilesystempath = '';
		var $tempfileurlpath = '';
		var $tempcontentaddedto = array();
		var $podangoapi;
		var $isexcerpt = FALSE;
		
		/*************************************************************/
		/* Load up the plugin values and get ready to action         */
		/*************************************************************/
		
		function podPress_class() {
			//$this->feed_getCategory();
			// this is not workin in WP 3.0: //$this->uploadpath = get_option('upload_path');  
			
			$wp_upload_dir = wp_upload_dir(); // since WP 2.0.0 but the return values were different back than
			if (FALSE == isset($wp_upload_dir['basedir']) OR FALSE == isset($wp_upload_dir['baseurl'])) {
				$wp_upload_dir = $this->upload_dir();
			}
			$this->uploadpath = $wp_upload_dir['basedir'];
			$this->uploadurl = $wp_upload_dir['baseurl'];
			$this->tempfilesystempath = $this->uploadpath.'/podpress_temp';
			$this->tempfileurlpath = $wp_upload_dir['baseurl'].'/podpress_temp';
			
			// load up podPress general config
			$this->settings = podPress_get_option('podPress_config');
			
			// make sure things look current, if not run the settings checker
			if(!is_array($this->settings) OR TRUE == version_compare(PODPRESS_VERSION, $this->settings['lastChecked'], '>') ) {
				$this->checkSettings();
			}
			
			if(is_object($GLOBALS['wp_rewrite'])
				&& is_array($GLOBALS['wp_object_cache']) 
				&& is_array($GLOBALS['wp_object_cache']['cache']) 
				&& is_array($GLOBALS['wp_object_cache']['cache']['options']) 
				&& is_array($GLOBALS['wp_object_cache']['cache']['options']['alloptions']) 
				&& is_array($GLOBALS['wp_object_cache']['cache']['options']['alloptions']['rewrite_rules'])
				&& !strpos($GLOBALS['wp_object_cache']['cache']['options']['alloptions']['rewrite_rules'], 'playlist.xspf')
				) {
					$GLOBALS['wp_rewrite']->flush_rules();
			}
		}

		// taken from wp_upload_dir() of WP 2.8.4 to keep up the compatibility of this podPress version with older WP version
		// new in podPress since 8.8.5 beta 9
		function upload_dir() {
			$siteurl = get_option( 'siteurl' );
			$upload_path = get_option( 'upload_path' );
			$upload_path = trim($upload_path);
			if ( empty($upload_path) ) {
				$dir = WP_CONTENT_DIR . '/uploads';
			} else {
				$dir = $upload_path;
			}
			// $dir is absolute, $path is (maybe) relative to ABSPATH
			$dir = $this->path_join( ABSPATH, $dir );
			  
			if ( !$url = get_option( 'upload_url_path' ) ) {
				if ( empty($upload_path) or ( $upload_path == $dir ) ) {
					$url = WP_CONTENT_URL . '/uploads';
				} else {
					$url = trailingslashit( $siteurl ) . $upload_path;
				}
			}
			if ( defined('UPLOADS') ) {
				$dir = ABSPATH . UPLOADS;
				$url = trailingslashit( $siteurl ) . UPLOADS;
			}
			return array( 'basedir' => $dir, 'baseurl' => $url);
		}
		// taken from WP 2.8.4 to keep up the compatibility of this podPress version with older WP version (new in WP since 2.5)
		// new in podPress since 8.8.5 beta 9
		function path_join( $base, $path ) {
			if ( $this->path_is_absolute($path) ) { return $path; }
			return rtrim($base, '/') . '/' . ltrim($path, '/');
		}
		// taken from WP 2.8.4 to keep up the compatibility of this podPress version with older WP version (new in WP since 2.5)
		// new in podPress since 8.8.5 beta 9
		function path_is_absolute( $path ) {
			// this is definitive if true but fails if $path does not exist or contains a symbolic link
			if ( realpath($path) == $path ) { return true;}
			if ( strlen($path) == 0 || $path{0} == '.' ) { return false; }
			// windows allows absolute paths like this
			if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) { return true; }
			// a path starting with / or \ is absolute; anything else is relative
			return (bool) preg_match('#^[/\\\\]#', $path);
		}

		
		/*************************************************************/
		// Handles all the default values for a new installation of the plugin
		// activate() is called only from podpress_upgrade_class.php during
		// the version check and upgrade routine which runs also after the plugin activation
		/*************************************************************/
		function activate() {
			GLOBAL $wpdb;
			if (function_exists('get_role') AND function_exists('is_role')) {
				if (FALSE === is_role('premium_subscriber')) {
					add_role('premium_subscriber', 'Premium Subscriber', $caps);
				}
				if (TRUE === is_role('premium_subscriber')) {
					$ps_role = get_role('premium_subscriber');
					if (Null !== $ps_role AND !$ps_role->has_cap('premium_content')) {
						$ps_role->add_cap('premium_content');
					}
					if(Null !== $ps_role AND !$ps_role->has_cap('read')) {
						$ps_role->add_cap('read');
					}
				}
				if (TRUE === is_role('administrator')) {
					$role = get_role('administrator');
					if (Null !== $role AND !$role->has_cap('premium_content')) {
						$role->add_cap('premium_content');
					}
				}
			}
			
			$this->createstatistictables();

			if(function_exists('wp_cache_flush')) {
				wp_cache_flush();
			}

			$current = get_option('podPress_version');
			if ( FALSE === $current ) {
				$current = constant('PODPRESS_VERSION');
				update_option('podPress_version', $current);
			}

			//$this->checkSettings();
		}

		/**
		* createstatistictables - creates the db tables for the statistics
		*
		* @package podPress
		* @since 8.8.10.3 beta 5
		*
		*/
		function createstatistictables() {
			GLOBAL $wpdb;
			// ntm: create the table with the collation or db_charset (since 8.8.5 beta 4)
			if ( TRUE == defined('DB_COLLATE') AND '' !== DB_COLLATE ) {
				$db_charset = ' COLLATE ' . DB_COLLATE;
			} elseif ( (FALSE == defined('DB_COLLATE') OR '' == DB_COLLATE) AND TRUE == defined('DB_CHARSET') AND '' !== DB_CHARSET ) {
				$db_charset = ' DEFAULT CHARACTER SET ' . DB_CHARSET;
			} else {
				$db_charset = '';
			}
			
			// Create stats table
			$create_table = "CREATE TABLE ".$wpdb->prefix."podpress_statcounts (".
			                "postID int(11) NOT NULL default '0',".
			                "media varchar(255) NOT NULL,".
			                "total int(11) default '1',".
			                "feed int(11) default '0',".
			                "web int(11) default '0',".
			                "play int(11) default '0',".
			                "PRIMARY KEY (media)) " . $db_charset;
			podPress_maybe_create_table($wpdb->prefix."podpress_statcounts", $create_table);
			
			// Create stats table
			$create_table = "CREATE TABLE ".$wpdb->prefix."podpress_stats (".
			                "id int(11) unsigned NOT NULL auto_increment,".
			                "postID int(11) NOT NULL default '0',".
			                "media varchar(255) NOT NULL default '',".
			                "method varchar(50) NOT NULL default '',".
			                "remote_ip varchar(15) NOT NULL default '',".
			                "country varchar(50) NOT NULL default '',".
			                "language VARCHAR(5) NOT NULL default '',".
			                "domain varchar(255) NOT NULL default '',".
			                "referer varchar(255) NOT NULL default '',".
			                "resource varchar(255) NOT NULL default '',".
			                "user_agent varchar(255) NOT NULL default '',".
			                "platform varchar(50) NOT NULL default '',".
			                "browser varchar(50) NOT NULL default '',".
			                "version varchar(15) NOT NULL default '',".
			                "dt int(10) unsigned NOT NULL default '0',".
					"completed TINYINT(1) UNSIGNED DEFAULT '0',".
			                "UNIQUE KEY id (id)) " . $db_charset;
			podPress_maybe_create_table($wpdb->prefix."podpress_stats", $create_table);
		}
		
		
		/**
		* checkLocalPathToMediaFiles - checks whether the "Local path to media files directory" exists or not. (This procedure is simply taken from the checkSettings() function earlier versions.)
		*
		* @package podPress
		* @since 8.8.5 beta 4
		*
		*/
		function checkLocalPathToMediaFiles() {
			unset($this->settings['autoDetectedMediaFilePath']);

			$mediaFilePath = stripslashes($this->settings['mediaFilePath']);
			
			if ( FALSE == isset($this->settings['mediaFilePath']) OR FALSE == file_exists( $mediaFilePath ) ) {
				$this->settings['autoDetectedMediaFilePath'] = $this->uploadpath;
				if (!file_exists($this->settings['autoDetectedMediaFilePath'])) {
					$this->settings['autoDetectedMediaFilePath'] .= ' ('.__('Auto Detection Failed.', 'podpress').') '.strval($this->uploadpath);
				} 
			}
		}

		function checkSettings() {
			GLOBAL $wp_object_cache, $wp_rewrite, $wp_version;
			if ( !is_array($this->settings) ) {
				$this->settings = podPress_get_option('podPress_config');
				if(!is_array($this->settings)) {
					$this->settings = array();
				}
			}

			$this->settings['lastChecked'] = PODPRESS_VERSION;

			// Make sure some standard values are set.
			$x = get_option('rss_language');
			if(!$x || empty($x))
			{
				add_option('rss_language', 'en');
			}

			$x = get_option('rss_image');
			if(!$x || empty($x))
			{
				podPress_update_option('rss_image', podPress_url().'images/powered_by_podpress.jpg');
			}

			// ntm: these settings are for the theme compatibility check resp. message. It seems to me that this checker was not in place at least since 8.8.
			// I could not find the routine which searches through the theme files for the wp_head and get_header etc. calls. Until there is such a test, I will set these values to TRUE.
			//~ if($this->settings['compatibilityChecks']['themeTested'] !== true) {
				//~ $this->settings['compatibilityChecks']['themeTested'] = false;
			//~ }
			//~ if($this->settings['compatibilityChecks']['wp_head'] !== true) {
				//~ $this->settings['compatibilityChecks']['wp_head'] = false;
			//~ }
			//~ if($this->settings['compatibilityChecks']['wp_footer'] !== true) {
				//~ $this->settings['compatibilityChecks']['wp_footer'] = false;
			//~ }
			$this->settings['compatibilityChecks']['themeTested'] = TRUE;
			$this->settings['compatibilityChecks']['wp_head'] = TRUE;
			$this->settings['compatibilityChecks']['wp_footer'] = TRUE;

			if(!is_bool($this->settings['enableStats'])) {
				if($this->settings['enableStats']== 'true') {
					$this->settings['enableStats'] = true;
				} else {
					$this->settings['enableStats'] = false;
				}
			}
			
			// no dashboardwidget support for WP 2.5.x and WP 2.6.x
			if ( TRUE == isset($this->settings['disabledashboardwidget']) AND TRUE === $this->settings['disabledashboardwidget'] OR (TRUE == version_compare($wp_version, '2.5', '>=') AND TRUE == version_compare($wp_version, '2.7', '<')) ) {
				$this->settings['disabledashboardwidget'] = TRUE;
			} else {
				$this->settings['disabledashboardwidget'] = FALSE;
			}
			
			if(!$this->settings['statMethod'] || empty($this->settings['statMethod']) || $this->settings['statMethod'] == 'htaccess')
			{
				$this->settings['statMethod'] = 'permalinks';
			}

			if(!$this->settings['statLogging'] || empty($this->settings['statLogging']))
			{
				$this->settings['statLogging'] = 'Counts';
			}

			if(empty($this->settings['enable3rdPartyStats'])) {
				$this->settings['enable3rdPartyStats'] = 'No';
			}

			if(!is_bool($this->settings['enableBlubrryStats'])) {
				if($this->settings['enableBlubrryStats']== 'true') {
					$this->settings['enableBlubrryStats'] = true;
				} else {
					$this->settings['enableBlubrryStats'] = false;
				}
			}

			if(!$this->settings['rss_copyright'] || empty($this->settings['rss_copyright']))
			{
				$this->settings['rss_copyright'] = __('Copyright', 'podpress').' &#xA9; '.get_bloginfo('blogname').' '. date('Y',time());
			}

			if(podPress_WPVersionCheck('2.0.0')) {
				if(!is_bool($this->settings['enablePremiumContent'])) {
					if($this->settings['enablePremiumContent']== 'true') {
						$this->settings['enablePremiumContent'] = true;
					} else {
						$this->settings['enablePremiumContent'] = false;
					}
				}
			} else {
				$this->settings['enablePremiumContent'] = false;
			}

			if(empty($this->settings['premiumMethod'])) {
				$this->settings['premiumMethod'] = 'Digest';
			}
			if(!defined('PODPRESS_PREMIUM_METHOD')) {
				define('PODPRESS_PREMIUM_METHOD', $this->settings['premiumMethod']);
			}

			if(!is_bool($this->settings['enableTorrentCasting'])) {
				if($this->settings['enableTorrentCasting']== 'true') {
					$this->settings['enableTorrentCasting'] = true;
				} else {
					$this->settings['enableTorrentCasting'] = false;
				}
			}

			if(empty($this->settings['podcastFeedURL'])) {
				if(podPress_WPVersionCheck('2.1')) {
					//~ $this->settings['podcastFeedURL'] = get_option('siteurl').'/?feed=podcast';
					$this->settings['podcastFeedURL'] = get_feed_link('podcast');
				} else {
					$this->settings['podcastFeedURL'] = get_option('siteurl').'/?feed=rss2';
				}
			}

			if ( FALSE == isset($this->settings['mediaWebPath']) OR TRUE == empty($this->settings['mediaWebPath']) ) {
				$this->settings['mediaWebPath'] = $this->uploadurl;
			}
			
			$this->checkLocalPathToMediaFiles();

			if(empty($this->settings['maxMediaFiles']) || $this->settings['maxMediaFiles'] < 1) {
				$this->settings['maxMediaFiles'] = 10;
			}

			if(!$this->settings['contentBeforeMore'] || empty($this->settings['contentBeforeMore']))
			{
				$this->settings['contentBeforeMore'] = 'yes';
			}

			if(!$this->settings['contentLocation'] || empty($this->settings['contentLocation']))
			{
				$this->settings['contentLocation'] = 'end';
			}

			if(!$this->settings['contentImage'] || empty($this->settings['contentImage']))
			{
				$this->settings['contentImage'] = 'button';
			}

			if(!$this->settings['contentPlayer'] || empty($this->settings['contentPlayer']))
			{
				$this->settings['contentPlayer'] = 'both';
			}
			
			if(!$this->settings['contentHidePlayerPlayNow'] || empty($this->settings['contentHidePlayerPlayNow']))
			{
				$this->settings['contentHidePlayerPlayNow'] = 'enabled';
			}

			if(FALSE == isset($this->settings['videoPreviewImage']) OR empty($this->settings['videoPreviewImage'])) {
				$this->settings['videoPreviewImage'] = PODPRESS_URL.'/images/vpreview_center.png';
			}

			if(!is_bool($this->settings['disableVideoPreview'])) {
				if($this->settings['disableVideoPreview']== 'true') {
					$this->settings['disableVideoPreview'] = true;
				} else {
					$this->settings['disableVideoPreview'] = false;
				}
			}

			if(!$this->settings['contentDownload'] || empty($this->settings['contentDownload']))
			{
				$this->settings['contentDownload'] = 'enabled';
			}

			if(!$this->settings['contentDownloadText'] || empty($this->settings['contentDownloadText']))
			{
				$this->settings['contentDownloadText'] = 'enabled';
			}

			if(!$this->settings['contentDownloadStats'] || empty($this->settings['contentDownloadStats']))
			{
				$this->settings['contentDownloadStats'] = 'enabled';
			}

			if(!$this->settings['contentDuration'] || empty($this->settings['contentDuration']))
			{
				$this->settings['contentDuration'] = 'enabled';
			}

			if ( FALSE == isset($this->settings['contentfilesize']) OR TRUE == empty($this->settings['contentfilesize'])) {
				$this->settings['contentfilesize'] = 'disabled';
			}
			
			if ( FALSE == isset($this->settings['incontentandexcerpt']) ) {
				$this->settings['incontentandexcerpt'] = 'in_content_and_excerpt';
			}

			if(!is_bool($this->settings['contentAutoDisplayPlayer'])) {
				if($this->settings['contentAutoDisplayPlayer'] == 'false') {
					$this->settings['contentAutoDisplayPlayer'] = false;
				} else {
					$this->settings['contentAutoDisplayPlayer'] = true;
				}
			}
			
			if ( FALSE == is_bool($this->settings['enableFooter']) ) {
				$this->settings['enableFooter'] = false;
			}
			
			if ( FALSE == isset($this->settings['mp3Player']) ) {
				$this->settings['mp3Player'] = '1pixelout';
			}
			
			if($this->settings['player']['bg'] == '') {
				$this->resetPlayerSettings();
			}

			if(empty($this->settings['iTunes']['summary'])) {
				$this->settings['iTunes']['summary'] = stripslashes(get_option('blogdescription'));
			} else {
				$this->settings['iTunes']['summary'] = stripslashes($this->settings['iTunes']['summary']);
			}
			$this->settings['iTunes']['keywords'] = stripslashes($this->settings['iTunes']['keywords']);
			$this->settings['iTunes']['subtitle'] = stripslashes($this->settings['iTunes']['subtitle']);
			$this->settings['iTunes']['author'] = stripslashes($this->settings['iTunes']['author']);

			$this->settings['iTunes']['FeedID'] = stripslashes($this->settings['iTunes']['FeedID']);
			$this->settings['iTunes']['FeedID'] = str_replace(' ', '', $this->settings['iTunes']['FeedID']);
			if(!empty($this->settings['iTunes']['FeedID']) && !is_numeric($this->settings['iTunes']['FeedID'])) {
				$this->settings['iTunes']['FeedID'] = settype($this->settings['iTunes']['FeedID'], 'double');
			}

			if(empty($this->settings['iTunes']['explicit'])) {
				$this->settings['iTunes']['explicit'] = 'No';
			}

			if(empty($this->settings['iTunes']['image'])) {
				$x = get_option('rss_image');
				if ( FALSE !== $x && $x != podPress_url().'images/powered_by_podpress.jpg') {
					$this->settings['iTunes']['image'] = $x;
				} else {
					$this->settings['iTunes']['image'] = podPress_url().'images/powered_by_podpress_large.jpg';
				}
			}

			if ( FALSE == isset($this->settings['iTunes']['new-feed-url']) OR ('Enable' != $this->settings['iTunes']['new-feed-url'] AND 'Disable' != $this->settings['iTunes']['new-feed-url']) ) {
				$this->settings['iTunes']['new-feed-url'] = 'Disable';
			}
			if ( FALSE == isset($this->settings['iTunes']['block']) OR ('Yes' != $this->settings['iTunes']['block'] AND 'No' != $this->settings['iTunes']['block']) ) {
				$this->settings['iTunes']['block'] = 'No';
			}
			if ( FALSE == isset($this->settings['rss_license_url']) ) {
				$this->settings['rss_license_url'] = '';
			}
			
			// since 8.8.8: default settings for the fully customizable feeds
			if ( FALSE == is_array($this->settings['podpress_feeds']) OR empty($this->settings['podpress_feeds']) ) {
				$email = get_option('admin_email');
				if ( FALSE === $email ) {
					$email = '';
				}
				$tagline = $this->settings['iTunes']['subtitle'];
				if ( FALSE === $tagline ) {
					$tagline = '';
				}
				$blog_charset = get_bloginfo('charset');
				$rss_language = get_option('rss_language');
				if ( FALSE === $rss_language ) { $rss_language = 'en'; }
				$rss_image = get_option('rss_image');
				if ( FALSE === $rss_image OR TRUE == empty($rss_image) ) {
					$rss_image = PODPRESS_URL.'/images/powered_by_podpress.jpg';
				}
				$ttl = get_option('rss_ttl');
				if ( FALSE === $ttl  OR (!empty($ttl) && $ttl < 1440) ) {
					$ttl  = 1440;
				}
				//~ if ( defined('PODPRESS_TAKEOVER_OLD_SETTINGS') AND TRUE === constant('PODPRESS_TAKEOVER_OLD_SETTINGS') ) {
					if ( FALSE == is_array($this->settings['iTunes']['category']) ) {
						$itunescategory = Array();
					}
					$this->settings['podpress_feeds'][0] = array(
						'use' => TRUE, 
						'premium' => FALSE,
						'name' => __('Podcast Feed', 'podpress'),
						'slug' => 'podcast',
						'feedtitle' => 'append',
						'subtitle' => $tagline,
						'itunes-newfeedurl' => 'Disable',
						'descr' => $this->settings['iTunes']['summary'],
						'itunes-category' => $itunescategory,
						'rss_category' => $this->settings['rss_category'],
						'itunes-keywords' => $this->settings['iTunes']['keywords'],
						'itunes-author' => $this->settings['iTunes']['author'],
						'email' => $email,
						'itunes-image' => $this->settings['iTunes']['image'],
						'rss_image' => $rss_image,
						'copyright' => $this->settings['rss_copyright'],
						'license_url' => $this->settings['rss_license_url'],
						'language' => $rss_language,
						'charset' => $blog_charset,
						'FileTypes' => Array(),
						'inclCategories' => Array(),
						'show_only_podPress_podcasts' => TRUE,
						'bypass_incl_selection' => FALSE,
						'itunes-explicit' => $this->settings['iTunes']['explicit'],
						'feedtype' => 'rss',
						'ttl' => $ttl,
						'itunes-feedid' => $this->settings['iTunes']['FeedID'],
						'itunes-block' => $this->settings['iTunes']['block'],
						'use_headerlink' => FALSE
					);
					$this->settings['podpress_feeds'][1] = array(
						'use' => FALSE, 
						'premium' => FALSE,
						'name' => __('Enhanced Podcast Feed', 'podpress'),
						'slug' => 'enhancedpodcast',
						'feedtitle' => 'append',
						'subtitle' => $tagline,
						'itunes-newfeedurl' => 'Disable',
						'descr' => $this->settings['iTunes']['summary'],
						'itunes-category' => $itunescategory,
						'rss_category' => $this->settings['rss_category'],
						'itunes-keywords' => $this->settings['iTunes']['keywords'],
						'itunes-author' => $this->settings['iTunes']['author'],
						'email' => $email,
						'itunes-image' => $this->settings['iTunes']['image'],
						'rss_image' => $rss_image,
						'copyright' => $this->settings['rss_copyright'],
						'license_url' => $this->settings['rss_license_url'],
						'language' => $rss_language,
						'charset' => $blog_charset,
						'FileTypes' => Array('audio_m4a', 'video_m4v'),
						'inclCategories' => Array(),
						'show_only_podPress_podcasts' => TRUE,
						'bypass_incl_selection' => FALSE,
						'itunes-explicit' => $this->settings['iTunes']['explicit'],
						'feedtype' => 'atom',
						'ttl' => $ttl,
						'itunes-feedid' => $this->settings['iTunes']['FeedID'],
						'itunes-block' => $this->settings['iTunes']['block'],
						'use_headerlink' => FALSE
					);
					$this->settings['podpress_feeds'][2] = array(
						'use' => FALSE, 
						'premium' => FALSE,
						'name' => __('Torrent Feed', 'podpress'),
						'slug' => 'torrent',
						'feedtitle' => 'append',
						'subtitle' => $tagline,
						'itunes-newfeedurl' => 'Disable',
						'descr' => $this->settings['iTunes']['summary'],
						'itunes-category' => $itunescategory,
						'rss_category' => $this->settings['rss_category'],
						'itunes-keywords' => $this->settings['iTunes']['keywords'],
						'itunes-author' => $this->settings['iTunes']['author'],
						'email' => $email,
						'itunes-image' => $this->settings['iTunes']['image'],
						'rss_image' => $rss_image,
						'copyright' => $this->settings['rss_copyright'],
						'license_url' => $this->settings['rss_license_url'],
						'language' => $rss_language,
						'charset' => $blog_charset,
						'FileTypes' => Array('torrent'),
						'inclCategories' => Array(),
						'show_only_podPress_podcasts' => TRUE,
						'bypass_incl_selection' => FALSE,
						'itunes-explicit' => $this->settings['iTunes']['explicit'],
						'feedtype' => 'atom',
						'ttl' => $ttl,
						'itunes-feedid' => $this->settings['iTunes']['FeedID'],
						'itunes-block' => $this->settings['iTunes']['block'],
						'use_headerlink' => FALSE
					);
					
					if ( FALSE == defined('PODPRESS_DEACTIVATE_PREMIUM') OR FALSE === constant('PODPRESS_DEACTIVATE_PREMIUM') ) {
						$this->settings['podpress_feeds'][3] = array(
							'use' => FALSE, 
							'premium' => TRUE,
							'name' => __('Premium Feed', 'podpress'),
							'slug' => 'premium',
							'feedtitle' => 'append',
							'subtitle' => $tagline,
							'itunes-newfeedurl' => 'Disable',
							'descr' => $this->settings['iTunes']['summary'],
							'itunes-category' => $itunescategory,
							'rss_category' => $this->settings['rss_category'],
							'itunes-keywords' => $this->settings['iTunes']['keywords'],
							'itunes-author' => $this->settings['iTunes']['author'],
							'email' => $email,
							'itunes-image' => $this->settings['iTunes']['image'],
							'rss_image' => $rss_image,
							'copyright' => $this->settings['rss_copyright'],
							'license_url' => $this->settings['rss_license_url'],
							'language' => $rss_language,
							'charset' => $blog_charset,
							'FileTypes' => Array(),
							'inclCategories' => Array(),
							'show_only_podPress_podcasts' => TRUE,
							'bypass_incl_selection' => FALSE,
							'itunes-explicit' => $this->settings['iTunes']['explicit'],
							'feedtype' => 'rss',
							'ttl' => $ttl,
							'itunes-feedid' => $this->settings['iTunes']['FeedID'],
							'itunes-block' => $this->settings['iTunes']['block'],
							'use_headerlink' => FALSE
						);
					}
				//~ } else {
					//~ // in case it is a first time installation
					//~ $this->settings['podpress_feeds'][0] = array(
						//~ 'use' => TRUE, 
						//~ 'premium' => FALSE,
						//~ 'name' => __('Podcast Feed', 'podpress'),
						//~ 'slug' => 'podcast',
						//~ 'feedtitle' => 'append',
						//~ 'subtitle' => '',
						//~ 'itunes-newfeedurl' => 'Disable',
						//~ 'descr' => '',
						//~ 'itunes-category' => Array(),
						//~ 'rss_category' => '',
						//~ 'itunes-keywords' => '',
						//~ 'itunes-author' => '',
						//~ 'email' => '',
						//~ 'itunes-image' => $this->settings['iTunes']['image'],
						//~ 'rss_image' => $rss_image,
						//~ 'copyright' => $this->settings['rss_copyright'],
						//~ 'license_url' => '',
						//~ 'language' => $rss_langauge,
						//~ 'charset' => $blog_charset,
						//~ 'FileTypes' => Array(),
						//~ 'itunes-explicit' => 'No',
						//~ 'feedtype' => 'rss',
						//~ 'ttl' => $ttl,
						//~ 'itunes-feedid' => '',
						//~ 'itunes-block' => 'No'
					//~ );
				//~ }
			}
			
			podPress_update_option('podPress_config', $this->settings);
			
			if (
				is_object($wp_rewrite)
				&& is_array($wp_object_cache) 
				&& is_array($wp_object_cache['cache']) 
				&& is_array($wp_object_cache['cache']['options']) 
				&& is_array($wp_object_cache['cache']['options']['alloptions']) 
				&& is_array($wp_object_cache['cache']['options']['alloptions']['rewrite_rules'])
				&& !strpos($wp_object_cache['cache']['options']['alloptions']['rewrite_rules'], 'playlist.xspf')
			) {
				$wp_rewrite->flush_rules();
			}
		}

		function deactivate() {
			// at the moment I have nothing I would want to clean up
		}
		
		/**
		* make_upgrade - helps to update the current settings
		*
		* @package podPress
		* @since 8.8.8 beta 5
		*
		*/
		function update_podpress_class($podpress_version_from_db = '0') {
			if (class_exists('podPressUpgrade_class')) {
				$u = new podPressUpgrade_class($podpress_version_from_db);
				$this->settings = $u->settings;
			}
			return $this;
		}

		function iTunesLink() {
			return '<a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id='.$this->settings['iTunes']['FeedID'].'"><img src="'.podPress_url().'images/itunes.png" border="0" alt="View in iTunes"/></a>';
		}

		function PlayerDefaultSettings() {
			// ntm: these colors are from the recent audio-player plugin
			// The new colors should make it clear that the 1PixelOut player was also updated in 8.8.5
			$result['bg'] = '#E5E5E5';
			$result['text'] = '#333333';
			$result['leftbg'] = '#CCCCCC';
			$result['lefticon'] = '#333333';
			$result['volslider'] = '#666666';
			$result['voltrack'] = '#FFFFFF';
			$result['rightbg'] = '#B4B4B4';
			$result['rightbghover'] = '#999999';
			$result['righticon'] = '#333333';
			$result['righticonhover'] = '#FFFFFF';
			$result['loader'] = '#009900';
			$result['track'] = '#FFFFFF';
			$result['border'] = '#CCCCCC';
			$result['tracker'] = '#DDDDDD';
			$result['skip'] = '#666666';
			
			$result['slider'] = '#666666'; // this is only for the Podango player
			
			$result['initialvolume'] = 70; // for 1Pixelout player (since podPress 8.8.5.2)
			$result['buffer'] = 5; // for 1Pixelout player (since podPress 8.8.5.2)
			$result['checkpolicy'] = 'no'; // for 1Pixelout player (since podPress 8.8.5.2)
			
			// player settings which are no direct resp. JS parameters of the players
			$result['overwriteTitleandArtist'] = 'no'; // for 1Pixelout player (since podPress 8.8.5.2)
			$result['listenWrapper'] = false;
			return $result;
		}
		
		function resetPlayerSettings() {
			$result = $this->PlayerDefaultSettings();
			$this->settings['player'] = $result;
			return $result;
		}

		function convertPodcastFileNameToValidWebPath($filename) {
			if ( strpos(substr($filename, 0, 10), '://') ) {
				$url = $filename;
			} else {
				if ( substr($filename, 0,1) == '/' ) {
					$baseurl = strtolower(strtok($_SERVER['SERVER_PROTOCOL'], '/')).'://'.$_SERVER['HTTP_HOST'].$this->settings['mediaWebPath'];
				} elseif ( strpos(substr($this->settings['mediaWebPath'], 0, 10), '://') ) {
					$baseurl = $this->settings['mediaWebPath'];
				} else {
					$baseurl = get_option('siteurl').$this->settings['mediaWebPath'];
				}
				if ( substr($filename, -1, 1) != '/' ) {
					$baseurl .= '/';
				}
				$url = $baseurl.$filename;
			}
			return $url;
		}

		function convertPodcastFileNameToWebPath($postID, $mediaNum, $filename = '', $method = false){
			$url = $this->convertPodcastFileNameToValidWebPath($filename);
			if($method != false) {
				if($this->settings['enableStats']) {
					$filename_part = podPress_getFileName($url);
					if($this->settings['statMethod'] == 'download.mp3') {
						$url = podPress_url().'download.mp3?'.$method.'='.$postID.'/'.$mediaNum.'/'.$filename_part;
					} else {
						$url = get_bloginfo('home').'/podpress_trac/'.$method.'/'.$postID.'/'.$mediaNum.'/'.$filename_part;
					}
				} elseif($this->settings['enable3rdPartyStats'] == 'Podtrac') {
					$url = str_replace(array('ftp://', 'http://', 'https://'), '', $url);
					$url = $this->podtrac_url.$url;
				} elseif($this->settings['enable3rdPartyStats'] == 'BluBrry' && !empty($this->settings['statBluBrryProgramKeyword'])) {
					$url = $this->blubrry_url.$this->settings['statBluBrryProgramKeyword'].'/'.$url;
				}
			}
			$url = str_replace(' ', '%20', $url);
			return $url;
		}
		
		function convertPodcastFileNameToSystemPath($filename = ''){
			if( FALSE === strpos(substr($filename, 0, 10), '://') ) {
				//if ( FALSE === empty($this->settings['mediaFilePath']) ) {
					$filename = $this->settings['mediaFilePath'].'/'.$filename;
					if(file_exists($filename))
					{
						return $filename;
					}
				//} 
			}
			return false;
		}
		
		/**
		* TryToFindAbsFileName - tries to build a absolute path for the given URL and checks whether the build path exists and is local or not. This inetended deal with the (real) URLs of the media files
		*
		* @package podPress
		* @since 8.8.6 beta 1
		*
		* @param str $url - The (real) URL of a media file. (real URL means the URL of a media file and not the URLs masked for statistics)
		*
		* @return mixed the abspath to the file or FALSE
		*/
		function TryToFindAbsFileName($url = '') {
			if (FALSE == empty($url)) {
				$uploadpath = $this->uploadpath;
				// remove drive letter
				$uploadpath_WL = end(explode(':', $uploadpath));
				// remove doubled backslashes
				$uploadpath_san1 = str_replace("\\\\", "\\", $uploadpath_WL);
				// replace backslash with slashes
				$uploadpath_san2 = str_replace("\\", "/", $uploadpath_san1);
				$uploadpath_parts = explode('/', $uploadpath_san2);
				
				//$result= parse_url($url);
				$home= get_bloginfo('home');
				$result['path'] = str_replace($home, '', $url);
				$urlpath_parts = explode('/', $result['path']);
				$diff = array_diff($urlpath_parts, $uploadpath_parts);
				$filename = $uploadpath.'/'.implode('/', $diff);
				if (TRUE === file_exists($filename)) {
					return $filename;
				} else {
					return false;
				}
			} else {
				return false;
			}
		}

		/**
		* checkWritableTempFileDir - (return values different since 8.8.6) controls whether the podPress temp/-folder is exists, or can be created and is writeable. This folder is e.g. uploads/podpress_temp/
		*
		* @package podPress
		* @since 8.8.6 beta 5
		*
		* @param bool $returnMessages - If it is true then the function returns in case of an error instead of false a string.
		*
		* @return mixed - TRUE if the folder exists and is writeable / FALSE or a string if there is a problem
		*/
		function checkWritableTempFileDir($returnMessages = FALSE) {
			$siteurl = get_option('siteurl');
			if (file_exists($this->tempfilesystempath)) {
				if(is_writable($this->tempfilesystempath)) {
					if ($returnMessages) {
						return __('(The folder is writeable.)', 'podpress');
					} else {
						return true;
					}
				} else {
					if ($returnMessages) {
						return '<p class="message error">'.sprintf(__('Your uploads/podpress_temp directory is not writable. Please set permissions as needed, and make sure <a href="%1$s/wp-admin/options-misc.php">configuration</a> is correct.', 'podpress'), $siteurl).'<br />'.__('Currently set to:', 'podpress').'<code>'.$this->tempfilesystempath."</code></p>\n";
					} else {
						return false;
					}
				}
			} elseif (!file_exists($this->uploadpath)) {
				if ($returnMessages) {
					return '<p class="message error">'.sprintf(__('Your WordPress upload directory does not exist. Please create it and make sure <a href="%1$s/wp-admin/options-misc.php">configuration</a> is correct.', 'podpress'), $siteurl).'<br />'.__('Currently set to:', 'podpress').'<code>'.$this->uploadpath."</code></p>\n";
				} else {
					return false;
				}
			} elseif (!is_writable($this->uploadpath)) {
				if ($returnMessages) {
					return '<p class="message error">'.sprintf(__('Your WordPress upload directory is not writable. Please set permissions as needed, and make sure <a href="%1$s/wp-admin/options-misc.php">configuration</a> is correct.', 'podpress'), $siteurl).'<br />'.__('Currently set to:', 'podpress').'<code>'.$this->uploadpath."</code></p>\n";
				} else {
					return false;
				}
			} else {
				$mkdir = @mkdir($this->tempfilesystempath);
				if (!$mkdir) {
					if ($returnMessages) {
						return '<p class="message error">'.__('Could not create uploads/podpress_temp directory. Please set permission of the following directory to 755 or 777:', 'podpress').'<br /><code>'.$this->tempfilesystempath."</code></p>\n";
					} else {
						return false;
					}
				} else {
					if ($returnMessages) {
						return __('(The folder is writeable.)', 'podpress');
					} else {
						return true;
					}
				}
			}
		}


		/*************************************************************/
		/* Load up the plugin values and get ready to action         */
		/*************************************************************/
		function addPostData($input, $forEdit = false) {
			$input->podPressMedia = podPress_get_post_meta($input->ID, '_podPressMedia', true);
			if(!is_array($input->podPressMedia)) {
				$x = maybe_unserialize($input->podPressMedia);
				if(is_array($x)) {
					$input->podPressMedia = $x;
				}
				if(!is_array($input->podPressMedia)) {
					$x = maybe_unserialize($input->podPressMedia, true);
					if(is_array($x)) {
						$input->podPressMedia = $x;
					}
				}
			}
			if(is_array($input->podPressMedia)) {
				reset($input->podPressMedia);
				while (list($key) = each($input->podPressMedia)) {
					if( !empty($input->podPressMedia[$key]['URI']) ) {
						if ( TRUE == isset($input->podPressMedia[$key]['premium_only']) AND ($input->podPressMedia[$key]['premium_only'] == 'on' || $input->podPressMedia[$key]['premium_only'] == true) ) {
							$input->podPressMedia[$key]['content_level'] = 'premium_content';
						} elseif ( !isset($input->podPressMedia[$key]['content_level']) ) {
							$input->podPressMedia[$key]['content_level'] = 'free';
						}

						if(!isset($input->podPressMedia[$key]['type'])) {
							$input->podPressMedia[$key]['type'] = '';
						}
						settype($input->podPressMedia[$key]['size'], 'int');
						if(0 >= $input->podPressMedia[$key]['size']) {
							$filepath = $this->convertPodcastFileNameToSystemPath($input->podPressMedia[$key]['URI']);
							if($filepath) {
								$input->podPressMedia[$key]['size'] = filesize ($filepath);
							} else {
								$input->podPressMedia[$key]['size'] = 1;
							}
						}

						$input->podPressMedia[$key]['ext'] = podPress_getFileExt($input->podPressMedia[$key]['URI']);
						$input->podPressMedia[$key]['mimetype'] = podPress_mimetypes($input->podPressMedia[$key]['ext']);

						if(!$forEdit && $this->settings['enablePremiumContent'] && $input->podPressMedia[$key]['content_level'] != 'free' && @$GLOBALS['current_user']->allcaps[$input->podPressMedia[$key]['content_level']] != 1) {
							$input->podPressMedia[$key]['authorized'] = false;
							$input->podPressMedia[$key]['URI'] = '';
							$input->podPressMedia[$key]['URI_torrent'] = '';
						} else {
							$input->podPressMedia[$key]['authorized'] = true;
						}
					}
				}
			}

			$input->podPressPostSpecific = podPress_get_post_meta($input->ID, '_podPressPostSpecific', true);
			if(!is_array($input->podPressPostSpecific)) {
				$input->podPressPostSpecific = array();
			}

			if(empty($input->podPressPostSpecific['itunes:subtitle'])) {
				$input->podPressPostSpecific['itunes:subtitle'] = '##PostExcerpt##';
			}
			if(empty($input->podPressPostSpecific['itunes:summary'])) {
				$input->podPressPostSpecific['itunes:summary'] = '##PostExcerpt##';
			}
			if(empty($input->podPressPostSpecific['itunes:keywords'])) {
				$input->podPressPostSpecific['itunes:keywords'] = '##WordPressCats##';
			}
			if(empty($input->podPressPostSpecific['itunes:author'])) {
				$input->podPressPostSpecific['itunes:author'] = '##Global##';
			}
			if(empty($input->podPressPostSpecific['itunes:explicit'])) {
				$input->podPressPostSpecific['itunes:explicit'] = 'Default';
			}
			if(empty($input->podPressPostSpecific['itunes:block'])) {
				$input->podPressPostSpecific['itunes:block'] = 'Default';
			}
			return $input;
		}

		function the_posts($input) {
			if ( FALSE === is_admin() && !$this->settings['compatibilityChecks']['themeTested'] ) {
				$this->settings['compatibilityChecks']['themeTested'] = true;
				podPress_update_option('podPress_config', $this->settings);
			}
			if(!is_array($input)) {
				return $input;
			}
			foreach($input as $key=>$value) {
				$input[$key] = $this->addPostData($value);
			}
			return $input;
		}
		
		/**
		* posts_distinct - filter function which return 'DISTINCT' while it is a search query. because joining the postmeta data leads to duplicate posts in the result list.
		*
		* @package podPress
		* @since 8.8.10 beta 2
		*
		* @param str $input 
		*
		* @return str $input - is 'DISTINCT' or an empty string
		*/
		function posts_distinct($input) {
			if ( is_search() AND isset($this->settings['activate_podpressmedia_search']) AND TRUE === $this->settings['activate_podpressmedia_search'] ) {
				$input = "DISTINCT";
			}
			return apply_filters('podpress_posts_distinct', $input);
		}
		
		function posts_join($input) {
			GLOBAL $wpdb;
			if ( is_search() AND isset($this->settings['activate_podpressmedia_search']) AND TRUE === $this->settings['activate_podpressmedia_search'] ) {
				$input .= " JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."posts.ID=".$wpdb->prefix."postmeta.post_id ";
			} else {
				if ( defined('PODPRESS_PODCASTSONLY') AND FALSE !== constant('PODPRESS_PODCASTSONLY') ) {
					$input .= " JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."posts.ID=".$wpdb->prefix."postmeta.post_id ";
				}
			}
			return apply_filters('podpress_posts_join', $input);
		}

		function posts_where($input) {
			GLOBAL $wpdb, $wp;
			if ( is_search() AND isset($this->settings['activate_podpressmedia_search']) AND TRUE === $this->settings['activate_podpressmedia_search'] ) {
				// search in the URI and title for the term
				$input .= " OR (".$wpdb->prefix."postmeta.meta_key='_podPressMedia' AND ( 1 = (".$wpdb->prefix."postmeta.meta_value REGEXP 's:5:\"title\";s:[0-9]+:\".*".$wpdb->escape($wp->query_vars['s'])."') OR 1 = (".$wpdb->prefix."postmeta.meta_value REGEXP 's:3:\"URI\";s:[0-9]+:\".*".$wp->query_vars['s']."')) )";
			} else {
				if ( defined('PODPRESS_PODCASTSONLY') AND FALSE !== constant('PODPRESS_PODCASTSONLY') ) {
					$input .= " AND ".$wpdb->prefix."postmeta.meta_key='_podPressMedia' ";
				}
			}
			return apply_filters('podpress_posts_where', $input);
		}

		function insert_the_excerpt($content = '') {
			GLOBAL $post;
			if ( FALSE == !empty($post->post_excerpt) ) {
				$this->tempcontentaddedto[$post->ID] = true;
			}
			$this->isexcerpt = true;
			return $content;
		}

		function insert_the_excerptplayer($content = '') {
			GLOBAL $post;
			$this->isexcerpt = true;
			$content = $this->insert_content($content, TRUE);
			return $content;
		}

		function insert_content($content = '', $is_the_excerpt = FALSE) {
			GLOBAL $post, $podPressTemplateData, $podPressTemplateUnauthorizedData, $wpdb;
			if ( !empty($post->post_password) ) { // if there's a password
				if ( stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password ) {	// and it doesn't match the cookie
					return $content;
				}
			}
			
			if ( $this->isexcerpt === $is_the_excerpt  ) {
				unset($this->tempcontentaddedto[$post->ID]);
			}
			$this->isexcerpt = FALSE;
			if ( isset($this->tempcontentaddedto[$post->ID]) ) {
				if ( is_feed() ) {
					return str_replace($this->podcasttag,'',$content);
				} else {
					return $content;
				}
			} else {
				$this->tempcontentaddedto[$post->ID] = true;
			}
			
			if ( is_feed() ) {
				return str_replace($this->podcasttag, '', $content);
			}

			if(!is_array($post->podPressMedia)) {
				return str_replace($this->podcasttag,'',$content);
			}

			if ( FALSE === stristr($content, $this->podcasttag) ) {
				if($this->settings['contentBeforeMore'] == 'no') {
					if (is_home() or is_archive()) {
						if ( FALSE !== strpos($post->post_content, '<!--more-->') ) {
							return $content;
						}
					}
				}
				if($this->settings['contentLocation'] == 'start') {
					$content = $this->podcasttag.$content;
				} else {
					$content .= $this->podcasttag;
				}
			}
		
			$podpressTag_in_the_content = '<p>'.$this->podcasttag.'</p>';
			
			// add the player and the other elements not if the related setting has been set 
			if ( TRUE == isset($this->settings['incontentandexcerpt']) ) {
				if ( $is_the_excerpt === TRUE ) {
					switch ( $this->settings['incontentandexcerpt'] ) {
						default :
						case 'in_content_and_excerpt' :
						case 'in_excerpt_only' :
						break;
						case 'in_content_only' :
							if ( FALSE !== stripos($content, $podpressTag_in_the_content) ) {
								return str_replace($podpressTag_in_the_content, '', $content);
							} else {
								return str_replace($this->podcasttag,'',$content);
							}
						break;
					}
				} else {
					switch ( $this->settings['incontentandexcerpt'] ) {
						default :
						case 'in_content_and_excerpt' :
						case 'in_content_only' :
						break;
						case 'in_excerpt_only' :
							if ( FALSE !== stripos($content, $podpressTag_in_the_content) ) {
								return str_replace($podpressTag_in_the_content, '', $content);
							} else {
								return str_replace($this->podcasttag,'',$content);
							}
						break;
					}
				}
			}

			//~ $podPressRSSContent = '';
			$showmp3player = false;
			$showvideopreview = false;
			$showvideoplayer = false;
			$podPressTemplateData = array();

			$podPressTemplateData['showDownloadText'] = $this->settings['contentDownloadText'];
			$podPressTemplateData['showDownloadStats'] = $this->settings['contentDownloadStats'];
			$podPressTemplateData['showDuration'] = $this->settings['contentDuration'];
			$podPressTemplateData['showfilesize'] = $this->settings['contentfilesize'];
			$this->playerCount++;
			$podPressTemplateData['files'] = array();
			$podPressTemplateData['player'] = array();
			reset($post->podPressMedia);
			while (list($key) = each($post->podPressMedia)) {
				if(empty($post->podPressMedia[$key]['previewImage'])) {
					$post->podPressMedia[$key]['previewImage'] = $this->settings['videoPreviewImage'];
				}

				$supportedVideoTypes = array('video_mp4', 'video_m4v', 'video_mov', 'video_qt', 'video_avi', 'video_mpg', 'video_asf', 'video_wmv', 'video_flv', 'video_swf', 'video_ogv');
				if (TRUE == $this->settings['disableVideoPreview'] AND TRUE == in_array($post->podPressMedia[$key]['type'], $supportedVideoTypes)) {
					$post->podPressMedia[$key]['disablePreview'] = true;
				} 
				
				if ( TRUE == isset($post->podPressMedia[$key]['feedonly']) AND 'on' == $post->podPressMedia[$key]['feedonly'] ) {
					continue;
				}
				$post->podPressMedia[$key]['title'] = htmlentities(stripslashes($post->podPressMedia[$key]['title']), ENT_QUOTES, get_option('blog_charset'));
				$post->podPressMedia[$key]['stats'] = false;
				if($this->settings['enableStats']) {
					$pos = strrpos($post->podPressMedia[$key]['URI'], '/');
					//$len = strlen($post->podPressMedia[$key]['URI']);
					while(substr($post->podPressMedia[$key]['URI'], $pos, 1) == '/') {
						$pos++;
					}
					$filename = substr($post->podPressMedia[$key]['URI'], $pos);
					if($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
						$where = $this->wherestr_to_exclude_bots('', 'AND');
						$query_string="SELECT method, COUNT(DISTINCT id) as downloads FROM ".$wpdb->prefix."podpress_stats WHERE postID='".$post->ID."' AND media='".rawurlencode($filename)."' ".$where."GROUP BY method ORDER BY method ASC";
						$stats = $wpdb->get_results($query_string);
						if (0 < count($stats)) {
							$feed = intval($stats[0]->downloads);
							$play = intval($stats[1]->downloads);
							$web = intval($stats[2]->downloads);
							$post->podPressMedia[$key]['stats'] = array('feed'=>$feed, 'web'=>$web, 'play'=>$play, 'total'=>($feed+$play+$web));
						}
					} else {
						$sql = "SELECT * FROM ".$wpdb->prefix."podpress_statcounts WHERE media = '".rawurlencode($filename)."'";
						$stats = $wpdb->get_results($sql);
						if($stats) {
							$post->podPressMedia[$key]['stats'] = array('feed'=>intval($stats[0]->feed), 'web'=>intval($stats[0]->web), 'play'=>intval($stats[0]->play), 'total'=>intval($stats[0]->total));
						}
					}
				}
				$supportedMediaTypes = array('audio_mp3', 'audio_ogg', 'audio_m4a', 'audio_mp4', 'audio_m3u', 'video_mp4', 'video_m4v', 'video_mov', 'video_qt', 'video_avi', 'video_mpg', 'video_asf', 'video_wmv', 'audio_wma', 'video_flv', 'video_swf', 'video_ogv', 'ebook_pdf', 'ebook_epub', 'embed_youtube', 'misc_torrent');
				if(!in_array($post->podPressMedia[$key]['type'], $supportedMediaTypes)) {
					$post->podPressMedia[$key]['type'] = 'misc_other';
				}
				
				// this loop is for the basics. After this the unauthorized content will stop
				if(empty($post->podPressMedia[$key]['title'])) {
					$post->podPressMedia[$key]['title'] = podPress_defaultTitles($post->podPressMedia[$key]['type']);
				}
				
				if ( '##Global##' == $post->podPressPostSpecific['itunes:author'] ) {
					Global $podPress;
					if (empty($podPress->settings['iTunes']['author'])) {
						$post->podPressMedia[$key]['artist'] = get_bloginfo('blogname');
					} else {
						$post->podPressMedia[$key]['artist'] = $podPress->settings['iTunes']['author'];
					}
				} else {
					$post->podPressMedia[$key]['artist'] = $post->podPressPostSpecific['itunes:author'];
				}
				
				if($this->settings['contentImage'] != 'none') {
					$post->podPressMedia[$key]['image'] = $post->podPressMedia[$key]['type'].'_'.$this->settings['contentImage'].'.png';
				}

				if($post->podPressMedia[$key]['authorized']) {
					$post->podPressMedia[$key]['URI_orig'] = $post->podPressMedia[$key]['URI'];
					$post->podPressMedia[$key]['URI'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI'], 'web');
					$post->podPressMedia[$key]['URI_Player'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI_orig'], 'play');
					if(!empty($post->podPressMedia[$key]['URI_torrent'])) {
						$post->podPressMedia[$key]['URI_torrent'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI_torrent'], 'web');
					}

					if($this->settings['contentDownload'] == 'disabled') {
						$post->podPressMedia[$key]['enableDownload'] = false;
						$post->podPressMedia[$key]['enableTorrentDownload'] = false;
					} else {
						$post->podPressMedia[$key]['enableDownload'] = true;
						//~ $podPressRSSContent .= '<a href="'.$post->podPressMedia[$key]['URI'].'">'.__('Download', 'podpress').' '.__($post->podPressMedia[$key]['title'], 'podpress').'</a><br/>';
						if($this->settings['enableTorrentCasting'] && !empty($post->podPressMedia[$key]['URI_torrent'])) {
							$post->podPressMedia[$key]['enableTorrentDownload'] = true;
						}
					}
					switch($this->settings['contentPlayer']) {
						case 'disabled':
							$post->podPressMedia[$key]['enablePlayer'] = false;
							$post->podPressMedia[$key]['enablePopup'] = false;
							break;
						case 'inline':
							$post->podPressMedia[$key]['enablePlayer'] = true;
							$post->podPressMedia[$key]['enablePopup'] = false;
							break;
						case 'popup':
							$post->podPressMedia[$key]['enablePlayer'] = false;
							$post->podPressMedia[$key]['enablePopup'] = true;
							break;
						case 'both':
							$post->podPressMedia[$key]['enablePlayer'] = true;
							$post->podPressMedia[$key]['enablePopup'] = true;
						default:
					}
					if($this->settings['contentHidePlayerPlayNow'] == 'disabled') {
						$post->podPressMedia[$key]['enablePlaylink'] = FALSE;
					} else {
						$post->podPressMedia[$key]['enablePlaylink'] = TRUE;
					}
					
					if($post->podPressMedia[$key]['enablePlayer']) {
						// This loop is to put together the player data.
						switch($post->podPressMedia[$key]['type']) {
							case 'audio_mp3':
								$post->podPressMedia[$key]['dimensionW'] = 290;
								$post->podPressMedia[$key]['dimensionH'] = 24;
								//~ $post->podPressMedia[$key]['dimensionW'] = 300;
								//~ $post->podPressMedia[$key]['dimensionH'] = 30;
								break;
							case 'audio_ogg':
							case 'audio_m4a':
							case 'audio_mp4':
							case 'audio_wma':
							case 'video_ogv':
							case 'video_m4v':
							case 'video_mp4':
							case 'video_mov':
							case 'video_qt':
							case 'video_avi':
							case 'video_mpg':
							case 'video_asf':
							case 'video_wmv':
							case 'video_flv':
							case 'video_swf':
								break;
							case 'embed_youtube':
								$x = parse_url($post->podPressMedia[$key]['URI_orig']);
								$x = explode('&', $x['query']);
								foreach($x as $v) {
									if(substr($v, 0, 2) == 'v=') {
										if(str_replace('/', '', $post->podPressMedia[$key]['previewImage']) == str_replace('/', '', $this->settings['videoPreviewImage'])) {
											$post->podPressMedia[$key]['previewImage'] = 'http://img.youtube.com/vi/'. substr($v, 2).'/default.jpg';
										}
										$post->podPressMedia[$key]['URI_Player'] = substr($v, 2).'.youtube';
										break;
									}
								}
								$post->podPressMedia[$key]['URI'] = $post->podPressMedia[$key]['URI_orig'];
								break;
							case 'audio_m3u':
								$post->podPressMedia[$key]['enableDownload'] = true;
							case 'ebook_pdf':
							case 'ebook_epub':
							default:
								$post->podPressMedia[$key]['enablePlayer'] = false;
								$post->podPressMedia[$key]['enablePopup'] = false;
						}
					}
				}
				if ( TRUE == isset($post->podPressMedia[$key]['disablePlayer']) AND (TRUE === $post->podPressMedia[$key]['disablePlayer'] OR 'on' == $post->podPressMedia[$key]['disablePlayer'])) {
					$post->podPressMedia[$key]['enablePlayer'] = false;
					$post->podPressMedia[$key]['enablePopup'] = false;
				} 

				$podPressTemplateData['files'][] = $post->podPressMedia[$key];
				$post->podPressMedia[$key]['URI'] = $post->podPressMedia[$key]['URI_orig'];
				unset($post->podPressMedia[$key]['URI_orig']);
			}

			if(!$this->settings['compatibilityChecks']['wp_head']) {
				$podPressContent = '<code>'.__('podPress theme compatibility problem. Please check podPress->General Settings for more information.', 'podpress').'</code><br/>';
				$this->settings['compatibilityChecks']['wp_head'] = false;
				$this->settings['compatibilityChecks']['wp_footer'] = false;
				podPress_update_option('podPress_config', $this->settings);
			} else {
				/* The theme file needs to populate these */
				$podPressContent = podPress_webContent($podPressTemplateData);
			}
			if ( FALSE !== stripos($content, $podpressTag_in_the_content) ) {
				return str_replace($podpressTag_in_the_content, $podPressContent, $content);
			} else {
				return str_replace($this->podcasttag, $podPressContent, $content);
			}
		}
		
		/**
		* feed_excerpt_filter - a function to filter the excerpt content (mainly to remove the podPress shortcode which is not desired in feed elements)
		*
		* @package podPress
		* @since 8.8.10.7
		*
		* @param str $content - text which may contain the podPress shortcode to determine the position of the player at the blog page
		*
		* @return str the content without the podPress shortcode 
		*/
		function feed_excerpt_filter($content) {
			return str_replace($this->podcasttag, '', $content);
		}

		function xmlrpc_post_addMedia($input) {
			$postdata = $input['postdata'];
			$content_struct = $input['content_struct'];
			if(isset($content_struct['enclosure']) && !empty($content_struct['enclosure']['url'])) {
				$media[0]['URI'] = $content_struct['enclosure']['url'];
				$media[0]['authorized'] = true;
				if(!empty($content_struct['enclosure']['type'])) {
					$media[0]['type'] = $content_struct['enclosure']['type'];
				} else {
					$media[0]['type'] = podPress_mimetypes(podPress_getFileExt($content_struct['enclosure']['url']));
				}
				if($media[0]['type'] == 'video/x-ms-wmv') {
					$media[0]['type'] = 'video/wmv';
				} elseif($media[0]['type'] == 'video/x-flv') {
					$media[0]['type'] = 'video/flv';
				}					
				$media[0]['type'] = str_replace('/', '_', $media[0]['type']);

				if(!empty($content_struct['enclosure']['duration'])) {
					$media[0]['duration'] =$content_struct['enclosure']['duration'];
				} else {
					$media[0]['duration'] = 0;
				}
				if(!empty($content_struct['enclosure']['size'])) {
					$media[0]['size'] = $content_struct['enclosure']['size'];
				} else {
						$media[0]['size'] = 0;
				}
				if(!empty($content_struct['enclosure']['title'])) {
					$media[0]['title'] = $content_struct['enclosure']['title'];
				}
				if(!empty($content_struct['enclosure']['previewImage'])) {
					$media[0]['previewImage'] = $content_struct['enclosure']['previewImage'];
				}
				if(!empty($content_struct['enclosure']['rss'])) {
						$media[0]['rss'] = $content_struct['enclosure']['rss'];
				} else {
					$media[0]['rss'] = true;
				}	

				delete_post_meta($postdata['ID'], '_podPressMedia');
				podPress_add_post_meta($postdata['ID'], '_podPressMedia', $media, true) ;
			}
			return true;
		}
		
		/**
		* wherestr_to_exclude_bots - builds a WHERE string to exclude bot IP addresses and user agents from the statistic output
		*
		* @package podPress
		* @since 8.8.5 beta 3
		*
		* @param str $tablename [optional] - If you want to add the WHERE string to a query with data from two or more db tables then you should use this parameter to add the name of stats table.
		* @param str $begin_phrase [optional] - If you have already a WHERE condition and you want to add this WHERE string to a query then you can use e.g. AND or OR instead of WHERE which is the default
		*
		* @return str WHERE string with one space at the end or an empty string
		*/
		function wherestr_to_exclude_bots($tablename = '', $begin_phrase='WHERE') {
			$botdb = get_option('podpress_botdb');
			if (FALSE == empty($tablename)) {
				$tablename = rtrim($tablename, '.');
				$tablename .= '.';
			}
			$begin_phrase = trim($begin_phrase);
			if (is_array($botdb) AND 0 < count($botdb)) {
				if (is_array($botdb['fullbotnames']) AND 1 < count($botdb['fullbotnames'])) {
					$where = $begin_phrase." ".$tablename."user_agent NOT IN ('". implode("', '", $botdb['fullbotnames'])."') ";
				} elseif ( is_array($botdb['fullbotnames']) AND 1 == count($botdb['fullbotnames']) ) {
					$where = $begin_phrase." ".$tablename."user_agent NOT IN ('". $botdb['fullbotnames'][0]."') ";
				} else {
					$where = '';
				}
				if ($where != '') {
					$and_or_where = 'AND';
				} else {
					$and_or_where = $begin_phrase;
				}
				if (is_array($botdb['IP']) AND 1 < count($botdb['IP'])) {
					$where .= $and_or_where." ".$tablename."remote_ip NOT IN ('". implode("', '", $botdb['IP'])."') ";
				} elseif ( is_array($botdb['IP']) AND 1 == count($botdb['IP']) ) {
					$where .= $and_or_where." ".$tablename."remote_ip NOT IN ('". $botdb['IP'][0]."') ";
				} else {
					$where .= '';
				}
			} else {
				$where = '';
			}
			return $where;
		}
		
		/**
		* cleanup_itunes_keywords - cleans the iTunes:Keywords up and gives a string back which contains max. 8 comma separated words. This string is escaped with strip_tags and htmlspecialchars and ready for storing it in a DB.
		*
		* @package podPress
		* @since 8.8.5 beta 3
		*
		* @param str $rawstring - The raw input string.
		* @param str $blog_charset [optional] - should be a PHP conform charset string like UTF-8 
		* @param bool $do_htmlspecialchars [optional] - do htmlspecialchars or not (since 8.8.10.7)
		*
		* @return str clean keyword string
		*/
		function cleanup_itunes_keywords($rawstring='', $blog_charset='', $do_htmlspecialchars = TRUE) {
			if ( FALSE === empty($rawstring) ) {
				$tmpstring = strip_tags(trim($rawstring));
				$tmpstring_parts = preg_split("/(\,)|(\s+)/", $tmpstring, -1, PREG_SPLIT_NO_EMPTY);
				$i=0;
				foreach ($tmpstring_parts as $tmpstring_part) {
					$string_parts[] = $tmpstring_part;
					if ( 11 == $i ) { // max 12 keywords
						break;
					}
					$i++;
				}
				if ( TRUE === $do_htmlspecialchars ) {
					if ( FALSE === empty($blog_charset) ) {
						return htmlspecialchars(implode(', ', $string_parts), ENT_QUOTES, $blog_charset);
					} else {
						return htmlspecialchars(implode(', ', $string_parts), ENT_QUOTES);
					}
				} else {
					return implode(', ', $string_parts);
				}
			} else {
				return '';
			}
		}
	
	
	// This function converts duration strings of the  format minutes:seconds, hours:minutes:seconds and hours:minutes:seconds:milliseconds into milliseconds.
	// Better ideas are welcome! Write a post here: http://wordpress.org/tags/podpress and use the tag "podpress".
	function strtomilliseconds($durationstr) {
		$dstr_parts=explode(':', $durationstr);
		$nr_dstr_parts=count($dstr_parts);
		if (1 < $nr_dstr_parts AND 5 > $nr_dstr_parts) {
			switch ($nr_dstr_parts) {
				case 2 :
					// this method is only good if the input data which consist of two parts is most likely in the format m:s because 
					// m:s
					$duration = $this->strtomilliseconds_core(1, 2, $dstr_parts);
				break;
				case 3 :
					// h:m:s
					$duration = $this->strtomilliseconds_core(0, 3, $dstr_parts);
				break;
				case 4 :
					// h:m:s:ms
					$duration = $this->strtomilliseconds_core(0, 4, $dstr_parts);
				break;
			}
		}
		if (!isset($duration) OR $duration < 0) {
			$duration = 0;
		}
		return $duration;
	}
	function strtomilliseconds_core($startindex=0, $max_nr_parts=4, $dstr_parts=array()){
		$duration = $j = 0;
		if (!empty($dstr_parts)) {
			for ($i=$startindex; $i < ($max_nr_parts+$startindex); $i++) {
				switch ($i) {
					case 0 : // hours
						$duration += 3600000 * intval($dstr_parts[$j]);
						$j++;
					break;
					case 1 : // minutes
						$duration += 60000 * intval($dstr_parts[$j]);
						$j++;
					break;
					case 2 : // seconds
						$duration += 1000 * intval($dstr_parts[$j]);
						$j++;
					break;
					case 3 : // milliseconds
						$duration += intval($dstr_parts[$j]);
						$j++;
					break;
				}
			}
		}
		return $duration;
	}

	// This function gives the milliseconds value back in the format h:m:s or in a given format.
	function millisecondstostring($duration, $format = 'h:m:s', $dimensionchr = ':', $decimals = 3, $dec_point = '.') {
		if ( FALSE == is_string($format) OR empty($format) ) {
			$format = 'h:m:s';
			$parts = 3;
		} else {
			$format = strtolower($format);
			$possible_formats = Array('h:m:s', 'm:s', 'h:m:s:ms', 'm:s:ms', 's:ms', 'h', 'm', 's', 'ms');
			if ( FALSE == in_array($format, $possible_formats) ) {
				$format = 'h:m:s';
				$parts = 3;
			} else {
				$parts = substr_count( $format, ':' ) + 1;
			}
		}
		// control the dimension character (/ divider) 
		if ( is_array($dimensionchr) AND (empty($dimensionchr) OR $parts > count($dimensionchr)) ) {
			$dimensionchr = Array('h' => __('h', 'podpress'), 'm' => __('min', 'podpress'), 's' => __('s', 'podpress'), 'ms' => __('ms', 'podpress'));
		}
		Switch ($format) {
			default :
			case 'h:m:s' :
				$dur['h'] = intval($duration / 3600000);
				$dur['m'] = intval($duration / (60000) % 60);
				$dur['s'] = intval($duration / (1000) % 60);
				return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
			break;
			case 'm:s' :
				$dur['m'] = intval($duration / 60000);
				$dur['s'] = intval($duration / (1000) % 60);
				return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
			break;
			case 'h:m:s:ms' :
				$dur['h'] = intval($duration / 3600000);
				$dur['m'] = intval($duration / (60000) % 60);
				$dur['s'] = intval($duration / (1000) % 60);
				$dur['ms'] = intval($duration % 1000);
				return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
			break;
			case 'm:s:ms' :
				$dur['m'] = intval($duration / 60000);
				$dur['s'] = intval($duration / (1000) % 60);
				$dur['ms'] = intval($duration % 1000);
				return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
			break;
			case 's:ms' :
				$dur['s'] = intval($duration / 1000);
				$dur['ms'] = intval($duration % 1000);
				return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
			break;
			case 'h' :
				$hours = ($duration / 3600000);
				if ( '.' == $dec_point OR ',' == $dec_point ) {
					$duration_str = number_format($hours, intval($decimals), $dec_point, '');
				} else {
					$duration_str = number_format($hours);
				}
				$dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
				if ( is_array($dimensionchr) AND isset($dimensionchr['h']) ) {
					return $duration_str.' '.$dimensionchr['h'];
				} else {
					return $duration_str;
				}
			break;
			case 'm' :
				$minutes = ($duration / 60000);
				if ( '.' == $dec_point OR ',' == $dec_point ) {
					$duration_str = number_format($minutes, intval($decimals), $dec_point, '');
				} else {
					$duration_str = number_format($minutes);
				}
				$dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
				if ( is_array($dimensionchr) AND isset($dimensionchr['m']) ) {
					return $duration_str.' '.$dimensionchr['m'];
				} else {
					return $duration_str;
				}
			break;
			case 's' :
				$seconds = ($duration / 1000);
				if ( '.' == $dec_point OR ',' == $dec_point ) {
					$duration_str = number_format($seconds, intval($decimals), $dec_point, '');
				} else {
					$duration_str = number_format($seconds);
				}
				$dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
				if ( is_array($dimensionchr) AND isset($dimensionchr['s']) ) {
					return $duration_str.' '.$dimensionchr['s'];
				} else {
					return $duration_str;
				}
			break;
			case 'ms' :
				$dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
				if ( is_array($dimensionchr) AND isset($dimensionchr['ms']) ) {
					return $duration.' '.$dimensionchr['ms'];
				} else {
					return $duration;
				}
			break;
		}
	}
	function millisecondstostring_print($dur, $duration_ms, $dimensionchr = ':') {
		if ($duration_ms < 1000) { // the minimum return value should be 00:01 seconds (this is important for the <itunes:duration> string)
			$dur = Array('m' => 0, 's'=> 1);
		}
		if ( is_array($dimensionchr) ) {
			$use_non_default_dim = TRUE;
			foreach ($dur as $key => $val) {
				if ( FALSE == array_key_exists($key, $dimensionchr) ) {
					$use_non_default_dim = FALSE;
				}
			}
		} else {
			$use_non_default_dim = FALSE;
		}
		$prev_empty = TRUE;
		$dur_parts = count($dur);
		if ( TRUE === $use_non_default_dim ) {
			foreach ($dur as $dur_key => $dur_val) {
				// don't print leading or trailing elements if they are zero and the numaber of elements is greater than 2 (2 elements minimum because the duration string should be atleast of the format m:ss)
				if ( ($dur_parts > 2) AND (TRUE === $prev_empty AND 0 == $dur_val) OR ($dur_key == 'ms' AND $dur_val == 0) ) {
					$prev_empty = TRUE;
				} else {
					// If it is not the leading element but a numerical digit then add a zero and make the string two digits wide.
					if (TRUE !== $prev_empty AND 0 <= $dur_val AND 9 >= $dur_val) {
						$dur_str_ar[] = '0'.$dur_val.' '.$dimensionchr[$dur_key];
					} else {
						$dur_str_ar[] = $dur_val.' '.$dimensionchr[$dur_key];
					}
					$prev_empty = FALSE;
				}
				$dur_parts--;
			}
			return implode(' ', $dur_str_ar);
		} else {
			foreach ($dur as $dur_key => $dur_val) {
				if ( ($dur_parts > 3) AND (TRUE === $prev_empty AND 0 == $dur_val) OR ($dur_key == 'ms' AND $dur_val == 0) ) {
					$prev_empty = TRUE;
				} else {
					if (TRUE !== $prev_empty AND 0 <= $dur_val AND 9 >= $dur_val) {
						$dur_str_ar[] = '0'.$dur_val;
					} else {
						$dur_str_ar[] = $dur_val;
					}
					$prev_empty = FALSE;
				}
				$dur_parts--;
			}
			return implode(':', $dur_str_ar);
		}
	}
	
	function podpress_build_dimchr($dur, $dimensionchr) {
		global $wp_version;
		if ( TRUE == is_array($dimensionchr) ) {
			return $dimensionchr;
		} else {
			if ( FALSE == isset($dur['h']) ) {
				$dur['h'] = 0;
			}
			if ( FALSE == isset($dur['m']) ) {
				$dur['m'] = 0;
			}
			if ( FALSE == isset($dur['s']) ) {
				$dur['s'] = 0;
			}
			if ( FALSE == isset($dur['ms']) ) {
				$dur['ms'] = 0;
			}
			switch ( $dimensionchr ) {
				case 'hminsms' :
					return Array('h' => __('h', 'podpress'), 'm' => __('min', 'podpress'), 's' => __('s', 'podpress'), 'ms' => __('ms', 'podpress'));
				break;
				case 'hrminsecmsec' :
					return Array('h' => __('hr.', 'podpress'), 'm' => __('min.', 'podpress'), 's' => __('sec.', 'podpress'), 'ms' => __('msec.', 'podpress'));
				break;
				case 'hoursminutessecondsmilliseconds' :
					if (version_compare($wp_version, '2.8', '<')) {
						return Array('h' => __ngettext('hour', 'hours', $dur['h'], 'podpress'), 'm' => __ngettext('minute', 'minutes', $dur['m'], 'podpress'), 's' => __ngettext('second', 'seconds', $dur['s'], 'podpress'), 'ms' => __ngettext('millisecond', 'milliseconds', $dur['ms'], 'podpress') );
					} else {
						return Array('h' => _n('hour', 'hours', $dur['h'], 'podpress'), 'm' => _n('minute', 'minutes', $dur['m'], 'podpress'), 's' => _n('second', 'seconds', $dur['s'], 'podpress'), 'ms' => _n('millisecond', 'milliseconds', $dur['ms'], 'podpress') );
					}
				break;
				case 'colon' :
				default :
					return ':';
				break;
			}
		}
	}
}
?>
Back to Top