File: Blog.pm

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (2327 lines) | stat: -rw-r--r-- 74,538 bytes parent folder | download
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
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: Blog.pm 4532 2009-10-02 02:25:27Z fumiakiy $

package MT::Blog;

use strict;
use base qw( MT::Object );

use MT::FileMgr;
use MT::Util;

__PACKAGE__->install_properties(
    {   column_defs => {
            'id'                        => 'integer not null auto_increment',
            'parent_id'                 => 'integer',
            'theme_id'                  => 'string(255)',
            'name'                      => 'string(255) not null',
            'description'               => 'text',
            'archive_type'              => 'string(255)',
            'archive_type_preferred'    => 'string(25)',
            'site_path'                 => 'string(255)',
            'site_url'                  => 'string(255)',
            'days_on_index'             => 'integer',
            'entries_on_index'          => 'integer',
            'file_extension'            => 'string(10)',
            'email_new_comments'        => 'boolean',
            'allow_comment_html'        => 'boolean',
            'autolink_urls'             => 'boolean',
            'sort_order_posts'          => 'string(8)',
            'sort_order_comments'       => 'string(8)',
            'allow_comments_default'    => 'boolean',
            'server_offset'             => 'float',
            'convert_paras'             => 'string(30)',
            'convert_paras_comments'    => 'string(30)',
            'allow_pings_default'       => 'boolean',
            'status_default'            => 'smallint',
            'allow_anon_comments'       => 'boolean',
            'words_in_excerpt'          => 'smallint',
            'moderate_unreg_comments'   => 'boolean',
            'moderate_pings'            => 'boolean',
            'allow_unreg_comments'      => 'boolean',
            'allow_reg_comments'        => 'boolean',
            'allow_pings'               => 'boolean',
            'manual_approve_commenters' => 'boolean',
            'require_comment_emails'    => 'boolean',
            'junk_folder_expiry'        => 'integer',
            'ping_weblogs'              => 'boolean',
            'mt_update_key'             => 'string(30)',
            'language'                  => 'string(5)',
            'welcome_msg'               => 'text',
            'google_api_key'            => 'string(32)',
            'email_new_pings'           => 'boolean',
            'ping_blogs'                => 'boolean',
            'ping_technorati'           => 'boolean',
            'ping_google'               => 'boolean',
            'ping_others'               => 'text',
            'autodiscover_links'        => 'boolean',
            'sanitize_spec'             => 'string(255)',
            'cc_license'                => 'string(255)',
            'is_dynamic'                => 'boolean',
            'remote_auth_token'         => 'string(50)',
            'children_modified_on'      => 'datetime',
            'custom_dynamic_templates'  => 'string(25)',
            'junk_score_threshold'      => 'float',
            'internal_autodiscovery'    => 'boolean',
            'basename_limit'            => 'smallint',
            'use_comment_confirmation'  => 'boolean',
            'allow_commenter_regist'    => 'boolean',
            'use_revision'              => 'boolean',
            'archive_url'               => 'string(255)',
            'archive_path'              => 'string(255)',
            ## Have to keep these around for use in mt-upgrade.cgi.
            'old_style_archive_links' => 'boolean',
            'archive_tmpl_daily'      => 'string(255)',
            'archive_tmpl_weekly'     => 'string(255)',
            'archive_tmpl_monthly'    => 'string(255)',
            'archive_tmpl_category'   => 'string(255)',
            'archive_tmpl_individual' => 'string(255)',
            ## end of fields for mt-upgrade.cgi

            # meta properties
            'image_default_wrap_text'  => 'integer meta',
            'image_default_align'      => 'string meta',
            'image_default_thumb'      => 'integer meta',
            'image_default_width'      => 'integer meta',
            'image_default_wunits'     => 'string meta',
            'image_default_constrain'  => 'integer meta',
            'image_default_popup'      => 'integer meta',
            'commenter_authenticators' => 'string meta',
            'require_typekey_emails'   => 'integer meta',
            'nofollow_urls'            => 'integer meta',
            'follow_auth_links'        => 'integer meta',
            'update_pings'             => 'string meta',
            'captcha_provider'         => 'string meta',
            'publish_queue'            => 'integer meta',
            'nwc_smart_replace'        => 'integer meta',
            'nwc_replace_field'        => 'string meta',
            'template_set'             => 'string meta',
            'page_layout'              => 'string meta',
            'include_system'           => 'string meta',
            'include_cache'            => 'integer meta',
            'max_revisions_entry'      => 'integer meta',
            'max_revisions_template'   => 'integer meta',
            'theme_export_settings'    => 'hash meta',
            'category_order'           => 'text meta',
            'folder_order'             => 'text meta',

        },
        meta    => 1,
        audit   => 1,
        indexes => {
            name      => 1,
            parent_id => 1,
        },
        defaults      => { 'custom_dynamic_templates' => 'none', },
        child_classes => [
            'MT::Entry',        'MT::Page',
            'MT::Template',     'MT::Asset',
            'MT::Category',     'MT::Folder',
            'MT::Notification', 'MT::Log',
            'MT::ObjectTag',    'MT::Association',
            'MT::Comment',      'MT::TBPing',
            'MT::Trackback',    'MT::TemplateMap',
            'MT::Touch',
        ],
        datasource  => 'blog',
        primary_key => 'id',
        class_type  => 'blog',
    }
);

# Image upload defaults.
sub ALIGN () {'none'}
sub UNITS () {'pixels'}

sub class_label {
    MT->translate("Blog");
}

sub class_label_plural {
    MT->translate("Blogs");
}

sub list_props {
    return {
        id => {
            base  => '__virtual.id',
            order => 100,
        },
        name => {
            auto      => 1,
            label     => 'Name',
            order     => 200,
            display   => 'force',
            html_link => sub {
                my ( $prop, $obj, $app ) = @_;
                return $app->uri(
                    mode => 'dashboard',
                    args => { blog_id => $obj->id, },
                );
            },
        },
        entry_count => {
            label              => 'Entries',
            filter_label       => '__ENTRY_COUNT',
            order              => 300,
            base               => '__virtual.object_count',
            display            => 'default',
            count_class        => 'entry',
            count_col          => 'blog_id',
            filter_type        => 'blog_id',
            list_screen        => 'entry',
            list_permit_action => 'access_to_entry_list',
        },
        page_count => {
            label              => 'Pages',
            filter_label       => '__PAGE_COUNT',
            order              => 400,
            base               => '__virtual.object_count',
            display            => 'default',
            count_class        => 'page',
            count_col          => 'blog_id',
            filter_type        => 'blog_id',
            list_screen        => 'page',
            list_permit_action => 'access_to_page_list',
        },
        asset_count => {
            label              => 'Assets',
            filter_label       => '__ASSET_COUNT',
            order              => 500,
            base               => '__virtual.object_count',
            count_class        => 'asset',
            count_col          => 'blog_id',
            filter_type        => 'blog_id',
            list_screen        => 'asset',
            count_args         => { no_class => 1 },
            list_permit_action => 'access_to_asset_list',
        },
        comment_count => {
            label              => 'Comments',
            filter_label       => '__COMMENT_COUNT',
            order              => 600,
            base               => '__virtual.object_count',
            count_class        => 'comment',
            count_col          => 'blog_id',
            filter_type        => 'blog_id',
            list_screen        => 'comment',
            list_permit_action => 'access_to_comment_list',
        },

        # not in use in 5.1
        # member_count => {
        #     label              => 'Members',
        #     order              => 700,
        #     base               => '__virtual.object_count',
        #     count_class        => 'permission',
        #     count_col          => 'blog_id',
        #     filter_type        => 'blog_id',
        #     list_screen        => 'member',
        #     count_terms        => { author_id => { not => 0 } },
        #     list_permit_action => 'access_to_member_list',
        # },
        parent_website => {
            view            => ['system'],
            label           => 'Website',
            order           => 800,
            display         => 'default',
            filter_editable => 0,
            raw             => sub {
                my ( $prop, $obj ) = @_;
                return $obj->website->name;
            },
            bulk_sort => sub {
                my $prop    = shift;
                my ($objs)  = @_;
                my %parents = map { $_->parent_id => 1 } @$objs;
                return @$objs if scalar keys %parents <= 1;
                my @parents = MT->model('website')
                    ->load( { id => [ keys %parents ] } );
                my %parent_names = map { $_->id => $_->name } @parents;
                return sort {
                    $parent_names{ $a->parent_id }
                        cmp $parent_names{ $b->parent_id }
                } @$objs;
            },
        },
        created_on => {
            base  => '__virtual.created_on',
            order => 900,
        },
        description => {
            auto    => 1,
            label   => 'Description',
            display => 'none',
        },
        theme_id => {
            label                 => 'Theme',
            base                  => '__virtual.single_select',
            display               => 'none',
            col                   => 'theme_id',
            single_select_options => sub {
                my $prop = shift;
                require MT::Theme;
                my $themes = MT::Theme->load_all_themes;
                return [
                    map { { label => $_->label, value => $_->id } }
                        sort { $a->label cmp $b->label }
                        grep {
                               $_->{class} eq 'blog'
                            || $_->{class} eq 'both'
                        } values %$themes
                ];
            },
        },
        modified_on => {
            display => 'none',
            base    => '__virtual.modified_on',
        },
    };
}

{
    my $default_text_format;

    sub set_defaults {
        my $blog = shift;
        $blog->SUPER::set_defaults(@_);

        unless ($default_text_format) {
            if ( my $allowed = MT->config('AllowedTextFilters') ) {
                $allowed =~ s/\s*,.*//;
                $default_text_format = $allowed; # choose first allowed format
            }
            else {
                $default_text_format = 'richtext';    # MT system default
            }
            my $filters = MT->registry("text_filters");

            # If the 'richtext' filter exists,
            # and is uncondition or it meets the condition, use
            # it as the blog default text format.
            if (!(  $filters->{$default_text_format}
                    && (  !$filters->{$default_text_format}{condition}
                        || $filters->{$default_text_format}{condition}
                        ->('blog') )
                )
                )
            {
                $default_text_format = '__default__';
            }
        }
        $blog->set_values_internal(
            {   days_on_index            => 0,
                entries_on_index         => 10,
                words_in_excerpt         => 40,
                sort_order_posts         => 'descend',
                language                 => MT->config('DefaultLanguage'),
                sort_order_comments      => 'ascend',
                file_extension           => 'html',
                convert_paras            => $default_text_format,
                allow_unreg_comments     => 0,
                allow_reg_comments       => 1,
                allow_pings              => 1,
                moderate_unreg_comments  => MT::Blog::MODERATE_UNTRSTD(),
                moderate_pings           => 1,
                require_comment_emails   => 1,
                allow_comments_default   => 1,
                allow_comment_html       => 1,
                autolink_urls            => 1,
                allow_pings_default      => 1,
                require_comment_emails   => 0,
                convert_paras_comments   => 1,
                email_new_pings          => 1,
                email_new_comments       => 1,
                allow_commenter_regist   => 1,
                use_comment_confirmation => 1,
                sanitize_spec            => 0,
                ping_weblogs             => 0,
                ping_blogs               => 0,
                ping_technorati          => 0,
                ping_google              => 0,
                archive_type             => '',
                archive_type_preferred   => '',
                status_default           => 2,
                junk_score_threshold     => 0,
                junk_folder_expiry       => 14,       # 14 days
                custom_dynamic_templates => 'none',
                internal_autodiscovery   => 0,
                basename_limit           => 100,
                server_offset => MT->config('DefaultTimezone') || 0,

               # something far in the future to force dynamic side to read it.
                children_modified_on => '20101231120000',
                use_revision         => 1,
            }
        );
        return $blog;
    }
}

sub is_blog {
    my $class = shift;
    return $class->class eq 'blog';
}

sub create_default_blog {
    my $class = shift;
    my ( $blog_name, $blog_template, $website_id ) = @_;
    $blog_name ||= MT->translate("First Blog");
    $class = ref $class if ref $class;

    my $blog = new $class;
    $blog->name($blog_name);

    # Enable nofollow options
    $blog->nofollow_urls(1);
    $blog->follow_auth_links(1);

    # Enable default commenter authentication
    $blog->commenter_authenticators( MT->config('DefaultCommenterAuth') );

    # set default page layout
    $blog->page_layout('layout-wtt');

    # Set class type
    $blog->class('blog');

    # Set parent
    $blog->parent_id($website_id);

    $blog->save or return $class->error( $blog->errstr );
    $blog->create_default_templates( $blog_template || 'mt_blog' )
        or return $class->error( $blog->errstr );
    return $blog;
}

sub create_default_templates {
    my $blog = shift;

    my $app       = MT->instance;
    my $curr_lang = $app->current_language;
    $app->set_language( $blog->language );

    require MT::DefaultTemplates;
    my $tmpl_list = MT::DefaultTemplates->templates(@_);
    if ( !$tmpl_list || ( ref($tmpl_list) ne 'ARRAY' ) || ( !@$tmpl_list ) ) {
        $app->set_language($curr_lang);
        return $blog->error(
            MT->translate("No default templates were found.") );
    }

    require MT::Template;
    my @arch_tmpl;
    for my $val (@$tmpl_list) {
        next if $val->{global};

        my $obj = MT::Template->new;
        my $p   = $val->{plugin}
            || 'MT';    # component and/or MT package for translate
        local $val->{name}
            = $val->{name};    # name field is translated in "templates" call
        my $text = $val->{text};
        local $val->{text};
        $val->{text} = $p->translate_templatized($text) if defined $text;
        $obj->build_dynamic(0);

        foreach my $v ( keys %$val ) {
            $obj->column( $v, $val->{$v} ) if $obj->has_column($v);
        }
        $obj->blog_id( $blog->id );
        if ( my $pub_opts = $val->{publishing} ) {
            $obj->include_with_ssi(1) if $pub_opts->{include_with_ssi};
        }
        if (   ( 'widgetset' eq $val->{type} )
            && ( exists $val->{widgets} ) )
        {
            my $modulesets = delete $val->{widgets};
            $obj->modulesets(
                MT::Template->widgets_to_modulesets( $modulesets, $blog->id )
            );
        }
        $obj->save;
        if ( $val->{mappings} ) {
            push @arch_tmpl,
                {
                template => $obj,
                mappings => $val->{mappings},
                exists( $val->{preferred} )
                ? ( preferred => $val->{preferred} )
                : ()
                };
        }
    }

    my %archive_types;
    if (@arch_tmpl) {
        require MT::TemplateMap;
        for my $map_set (@arch_tmpl) {
            my $tmpl     = $map_set->{template};
            my $mappings = $map_set->{mappings};
            foreach my $map_key ( keys %$mappings ) {
                my $m  = $mappings->{$map_key};
                my $at = $m->{archive_type};
                $archive_types{$at} = 1;

                # my $preferred = $mappings->{$map_key}{preferred};
                my $map = MT::TemplateMap->new;
                $map->archive_type($at);
                if ( exists $m->{preferred} ) {
                    $map->is_preferred( $m->{preferred} );
                }
                else {
                    $map->is_preferred(1);
                }
                $map->template_id( $tmpl->id );
                $map->file_template( $m->{file_template} )
                    if $m->{file_template};
                $map->blog_id( $tmpl->blog_id );
                $map->build_type( $m->{build_type} )
                    if defined $m->{build_type};
                $map->save;
            }
        }
    }

    $blog->archive_type( join ',', keys %archive_types );
    foreach my $at (qw( Individual Daily Weekly Monthly Category )) {
        $blog->archive_type_preferred($at), last
            if exists $archive_types{$at};
    }
    $blog->custom_dynamic_templates('none');
    $blog->save;

    MT->run_callbacks( ref($blog) . '::post_create_default_templates',
        $blog, $tmpl_list );

    $app->set_language($curr_lang);
    return $blog;
}

# As of MT 4, we always manage fileinfo records.
sub needs_fileinfo {
    return 1;
}

sub current_timestamp {
    my $blog = shift;
    require MT::Util;
    my @ts = MT::Util::offset_time_list( time, $blog->id );
    return sprintf '%04d%02d%02d%02d%02d%02d',
        $ts[5] + 1900, $ts[4] + 1, @ts[ 3, 2, 1, 0 ];
}

sub website {
    my $blog = shift;
    return $blog unless $blog->is_blog;
    return undef unless $blog->parent_id;

    require MT::Website;
    return MT::Website->load( $blog->parent_id );
}

sub theme {
    require MT::Theme;
    my $blog = shift;
    my $id   = $blog->theme_id;
    return MT::Theme->load($id);
}

sub raw_site_url {
    my $blog = shift;
    my $site_url = $blog->SUPER::site_url || '';
    if ( my ( $subdomain, $path ) = split( '/::/', $site_url ) ) {
        if ( $subdomain ne $site_url ) {
            return ( $subdomain, $path );
        }
    }
    return $site_url;
}

sub site_url {
    my $blog = shift;

    if (@_) {
        return $blog->SUPER::site_url(@_);
    }
    elsif ( $blog->is_dynamic ) {
        my $cfg  = MT->config;
        my $path = $cfg->CGIPath;
        if ( $path =~ m!^/! ) {

            # relative path, prepend blog domain
            my ($blog_domain) = $blog->archive_url =~ m|(.+://[^/]+)|;
            $path = $blog_domain . $path;
        }
        $path .= '/' unless $path =~ m{/$};
        return $path;
    }
    else {
        my $url = '';
        if ( $blog->is_blog() ) {
            if ( my $website = $blog->website() ) {
                $url = $website->SUPER::site_url;
            }
            else {

                # FIXME: there are a few occasions where
                # a blog does not have its parent, like (bugid:102749)
                return $blog->SUPER::site_url;
            }
            my @paths = $blog->raw_site_url;
            if ( 2 == @paths ) {
                if ( $paths[0] ) {
                    $url =~ s!^(https?)://(.+)/$!$1://$paths[0]$2/!;
                }
                if ( $paths[1] ) {
                    $url = MT::Util::caturl( $url, $paths[1] );
                }
            }
            else {
                $url = MT::Util::caturl( $url, $paths[0] );
            }
        }
        else {
            $url = $blog->SUPER::site_url;
        }

        return $url;
    }
}

sub is_site_path_absolute {
    my $blog = shift;

    my $raw_path;
    if ( ref $blog ) {
        $raw_path = $blog->SUPER::site_path;
    }
    else {
        $raw_path = $_[0];
    }

    return 1 if $raw_path =~ m!^/!;
    return 1 if $raw_path =~ m!^[a-zA-Z]:\\!;
    return 1 if $raw_path =~ m!^\\\\[a-zA-Z0-9\.]+!;    # UNC
    return 0;
}

sub site_path {
    my $blog = shift;

    if (@_) {
        $blog->SUPER::site_path(@_);
    }
    else {
        my $raw_path = $blog->SUPER::site_path;
        return $raw_path if $blog->is_site_path_absolute;

        my $base_path = '';
        my $path      = '';
        my $website   = $blog->website();
        if ( $blog->is_blog() && $website ) {
            $base_path = $website->column('site_path');
            if ($base_path) {
                $path = File::Spec->catdir( $base_path, $raw_path );
            }
            else {
                $path = $raw_path;
            }
        }
        else {
            $path = $raw_path;
        }
        return $path;
    }
}

sub raw_archive_url {
    my $blog        = shift;
    my $archive_url = $blog->SUPER::archive_url;
    if ( my ( $subdomain, $path ) = split( '/::/', $archive_url ) ) {
        return ( $subdomain, $path );
        if ( $subdomain ne $archive_url ) {
            return ( $subdomain, $path );
        }
    }
    return $archive_url;
}

sub archive_url {
    my $blog = shift;

    if (@_) {
        $blog->SUPER::archive_url(@_) || $blog->site_url;
    }
    elsif ( $blog->is_dynamic ) {
        return $blog->site_url;
    }
    else {
        my $url = $blog->site_url;
        if ( $blog->is_blog() ) {
            if ( my $website = $blog->website() ) {
                $url = $website->SUPER::site_url;
            }
            my $archive_url = $blog->SUPER::archive_url;
            return $blog->site_url unless $archive_url;
            return $archive_url if $archive_url =~ m!^https?://!;
            my @paths = $blog->raw_archive_url;
            if ( 2 == @paths ) {
                if ( $paths[0] ) {
                    $url =~ s!^(https?)://(.+)/$!$1://$paths[0]$2/!;
                }
                if ( $paths[1] ) {
                    $url = MT::Util::caturl( $url, $paths[1] );
                }
            }
            else {
                $url = MT::Util::caturl( $url, $paths[0] );
            }
        }
        return $url;
    }
}

sub is_archive_path_absolute {
    my $blog = shift;

    my $raw_path = $blog->SUPER::archive_path;
    return 0 unless $raw_path;
    return 1 if $raw_path =~ m!^/!;
    return 1 if $raw_path =~ m!^[a-zA-Z]:\\!;
    return 1 if $raw_path =~ m!^\\\\[a-zA-Z0-9\.]+!;    # UNC
    return 0;
}

sub archive_path {
    my $blog = shift;

    if (@_) {
        $blog->SUPER::archive_path(@_) || $blog->site_path;
    }
    else {
        return $blog->site_path if !$blog->column('archive_path');

        my $raw_path = $blog->SUPER::archive_path;
        return $raw_path if $blog->is_archive_path_absolute;

        my $base_path = '';
        my $path      = '';
        if ( my $website = $blog->website() ) {
            $base_path = $website->SUPER::site_path;
        }
        $path = $raw_path;
        if ($base_path) {
            $path = File::Spec->catdir( $base_path, $raw_path );
        }
        else {
            $path = $blog->site_path;
        }
        return $path;
    }
}

sub comment_text_filters {
    my $blog    = shift;
    my $filters = $blog->convert_paras_comments;
    return [] unless $filters;
    if ( $filters eq '1' ) {
        return ['__default__'];
    }
    else {
        return [ split /\s*,\s*/, $filters ];
    }
}

sub cc_license_url {
    my $cc = $_[0]->cc_license or return '';
    MT::Util::cc_url($cc);
}

sub email_all_comments {
    return $_[0]->email_new_comments == 1;
}

sub email_attn_reqd_comments {
    return $_[0]->email_new_comments == 2;
}

sub email_all_pings {
    return $_[0]->email_new_pings == 1;
}

sub email_attn_reqd_pings {
    return $_[0]->email_new_pings == 2;
}

sub MODERATE_NONE ()    {0}
sub MODERATE_ALL ()     {1}
sub MODERATE_UNTRSTD () {2}
sub MODERATE_UNAUTHD () {3}

sub publish_trusted_commenters {
    !( $_[0]->moderate_unreg_comments == MODERATE_ALL );
}

sub publish_authd_untrusted_commenters {
    return $_[0]->moderate_unreg_comments == MODERATE_UNAUTHD
        || $_[0]->moderate_unreg_comments == MODERATE_NONE;
}

sub publish_unauthd_commenters {
    $_[0]->moderate_unreg_comments == MODERATE_NONE;
}

sub include_path_parts {
    my $blog = shift;
    my ($param) = @_;

    my $filestem = MT::Util::dirify( $param->{name} )
        || 'template';
    $filestem .= '_' . $param->{id};
    my $filename = join q{.}, $filestem, $blog->file_extension;
    my $path = $param->{path} || '';
    my @path;
    if ( $path =~ s!^/!! ) {

        # absolute
        @path = split q{/}, $path;
    }
    else {

        # relative
        push @path, MT->config('IncludesDir');
        push @path, split q{/}, $path;
    }
    return ( $filename, @path );
}

sub include_path {
    my $blog = shift;

    my ( $filename, @path ) = $blog->include_path_parts(@_);
    my $extra_path = File::Spec->catdir(@path);
    my $full_path  = File::Spec->catdir( $blog->site_path, $extra_path );
    my $file_path  = File::Spec->catfile( $full_path, $filename );
    return wantarray ? ( $file_path, $full_path, $filename ) : $file_path;
}

sub include_url {
    my $blog = shift;

    my ( $filename, @path ) = $blog->include_path_parts(@_);
    my $url = join q{/}, $blog->site_url, @path, $filename;
    return $url;
}

sub include_statement {
    my $blog = shift;

    my $system = $blog->include_system or return;

    my ( $statement, $include );
    if ( $system eq 'shtml' ) {
        $statement = q{<!--#include virtual="%s" -->};

        my ( $filename, @path ) = $blog->include_path_parts(@_);
        my $site_url = $blog->site_url;
        $site_url =~ s{ \A \w+ :// [^/]+ }{}xms;
        $site_url =~ s{ / \z }{}xms;
        $include = join q{/}, $site_url, @path, $filename;
    }
    else {
        $include = $blog->include_path(@_);
        $statement
            = $system eq 'php' ? q{<?php include("%s") ?>}
            : $system eq 'jsp' ? q{<%@ include file="%s" %>}
            : $system eq 'asp' ? '<!--#include file="%s" -->'
            :                    return;
    }
    return sprintf $statement, MT::Util::encode_php( $include, q{qq} );
}

sub file_mgr {
    my $blog = shift;
    unless ( exists $blog->{__file_mgr} ) {
## xxx need to add remote_host, remote_user, remote_pwd fields
## then pull params from there; if remote_host is defined, we
## assume we are using FTP?
        $blog->{__file_mgr} = MT::FileMgr->new('Local');
    }
    $blog->{__file_mgr};
}

sub remove {
    my $blog    = shift;
    my $blog_id = $blog->id
        if ref($blog);

    $blog->remove_children( { key => 'blog_id' } );
    my $res = $blog->SUPER::remove(@_);
    if ( $blog_id && $res ) {
        require MT::Permission;
        MT::Permission->remove( { blog_id => $blog_id } );
        require MT::PluginData;
        MT::PluginData->remove( { blog_id => $blog_id } );
    }
    $res;
}

# deprecated: use $blog->remote_auth_token instead
sub effective_remote_auth_token {
    my $blog = shift;
    if ( scalar @_ ) {
        return $blog->remote_auth_token(@_);
    }
    if ( $blog->remote_auth_token() ) {
        return $blog->remote_auth_token();
    }
    undef;
}

sub has_archive_type {
    my $blog   = shift;
    my ($type) = @_;
    my %at     = map { lc $_ => 1 } split( /,/, $blog->archive_type );
    return 0 unless exists $at{ lc $type };

    my $result = 0;
    require MT::TemplateMap;
    my @maps = MT::TemplateMap->load(
        {   blog_id      => $blog->id,
            archive_type => $type
        }
    );
    return 0 unless @maps;
    require MT::PublishOption;

    foreach my $map (@maps) {
        $result++ if $map->build_type != MT::PublishOption::DISABLED();
    }
    return $result;
}

sub accepts_registered_comments {
    $_[0]->allow_reg_comments && $_[0]->commenter_authenticators;
}

sub accepts_comments {
    $_[0]->accepts_registered_comments || $_[0]->allow_unreg_comments;
}

sub count_static_templates {
    my $blog           = shift;
    my ($archive_type) = @_;
    my $result         = 0;
    require MT::TemplateMap;
    my @maps = MT::TemplateMap->load(
        {   blog_id      => $blog->id,
            archive_type => $archive_type
        }
    );
    return 0 unless @maps;
    require MT::PublishOption;
    foreach my $map (@maps) {
        $result++ if $map->build_type != MT::PublishOption::DYNAMIC();
    }

    #$result ||= 1 if ($blog->custom_dynamic_templates || '') ne 'custom';
    return $result;
}

sub touch {
    my $blog = shift;
    my (@types) = @_;
    my ( $s, $m, $h, $d, $mo, $y ) = localtime(time);
    my $mod_time = sprintf( "%04d%02d%02d%02d%02d%02d",
        1900 + $y, $mo + 1, $d, $h, $m, $s );
    require MT::Touch;
    MT::Touch->touch( $blog->id, @types );
    $blog->children_modified_on($mod_time);
    $mod_time;
}

sub clone {
    my $blog = shift;
    my ($param) = @_;
    if ( $param && $param->{Children} ) {
        $blog->clone_with_children(@_);
    }
    else {
        $blog->SUPER::clone(@_);
    }
}

sub clone_with_children {
    my $blog       = shift;
    my ($params)   = @_;
    my $callback   = $params->{Callback} || sub { };
    my $classes    = $params->{Classes};
    my $blog_name  = $params->{BlogName};
    my $website_id = $params->{Website};
    delete $$params{Children} if ( $params->{Children} );
    my $old_blog_id = $blog->id;

    # we must clone:
    #    Blog record
    #    Entry records
    #       - Comment records
    #       - TrackBack records
    #       - TBPing records
    #       - ObjectTag records (if running 3.3)
    #    Category records
    #    Placement records
    #    Template records
    #    Permission records
    #    IPBanList records???
    #    Notification records???

    my $new_blog_id;
    my ( %entry_map, %cat_map, %tb_map, %tmpl_map, %comment_map, $counter,
        $iter );

    # Cloning blog
    my $new_blog = $blog->clone($params);
    $new_blog->name(
          $blog_name
        ? $blog_name
        : MT->translate( "Clone of [_1]", $blog->name )
    );
    $new_blog->parent_id($website_id);
    delete $new_blog->{column_values}->{id};
    delete $new_blog->{changed_cols}->{id};
    $new_blog->modified_on(undef);
    $new_blog->created_on(undef);
    $new_blog->save or die $new_blog->errstr;
    $new_blog_id = $new_blog->id;
    $callback->(
        MT->translate( "Cloned blog... new id is [_1].", $new_blog_id ) );

    if ( ( !exists $classes->{'MT::Permission'} )
        || $classes->{'MT::Permission'} )
    {

        # Cloning PERMISSIONS records
        $counter = 0;
        my $state = MT->translate("Cloning permissions for blog:");
        $callback->( $state, "perms" );
        require MT::Permission;
        $iter = MT::Permission->load_iter( { blog_id => $old_blog_id } );

        while ( my $perm = $iter->() ) {
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $counter ),
                'perms'
            ) if $counter && ( $counter % 100 == 0 );
            $counter++;
            my $new_perm = $perm->clone();
            delete $new_perm->{column_values}->{id};
            delete $new_perm->{changed_cols}->{id};
            $new_perm->blog_id($new_blog_id);
            $new_perm->save or die $new_perm->errstr;
        }
        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'perms'
        );
    }

    if ( ( !exists $classes->{'MT::Association'} )
        || $classes->{'MT::Association'} )
    {

        # Cloning association records
        $counter = 0;
        my $state = MT->translate("Cloning associations for blog:");
        $callback->( $state, "assoc" );
        require MT::Association;
        $iter = MT::Association->load_iter( { blog_id => $old_blog_id } );
        while ( my $assoc = $iter->() ) {
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $counter ),
                'assoc'
            ) if $counter && ( $counter % 100 == 0 );
            $counter++;
            my $new_assoc = $assoc->clone();
            delete $new_assoc->{column_values}->{id};
            delete $new_assoc->{changed_cols}->{id};
            $new_assoc->blog_id($new_blog_id);
            $new_assoc->save or die $new_assoc->errstr;
        }
        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'assoc'
        );
    }

    # include/exclude class logic
    # if user has not specified 'Classes' element, clone everything
    # if user has specified Classes, but a particular class is not
    # identified, clone it (forward compatibility). if a class is
    # specified and the flag is '1', clone it. if a class is specified
    # but the flag is '0', skip it.

    # MT::Entry -> MT::Category, MT::Comment, MT::Tracback, MT::TBPing
    # MT::Page -> MT::Folder, MT::Comment, MT::Trackback, MT::TBPing

    if ( ( !exists $classes->{'MT::Entry'} ) || $classes->{'MT::Entry'} ) {

        # Cloning ENTRY records
        my $state = MT->translate("Cloning entries and pages for blog...");
        $callback->( $state, "entries" );
        $counter = 0;
        require MT::Entry;
        $iter = MT::Entry->load_iter(
            { blog_id => $old_blog_id, class => '*' } );
        while ( my $entry = $iter->() ) {
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $counter ),
                'entries'
            ) if $counter && ( $counter % 100 == 0 );
            $counter++;
            my $entry_id  = $entry->id;
            my $new_entry = $entry->clone();
            delete $new_entry->{column_values}->{id};
            delete $new_entry->{changed_cols}->{id};
            $new_entry->blog_id($new_blog_id);
            $new_entry->save or die $new_entry->errstr;
            $entry_map{$entry_id} = $new_entry->id;
        }
        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'entries'
        );

        if ( ( !exists $classes->{'MT::Category'} )
            || $classes->{'MT::Category'} )
        {

            # Cloning CATEGORY records
            my $state = MT->translate("Cloning categories for blog...");
            $callback->( $state, "cats" );
            $counter = 0;
            require MT::Category;
            $iter = MT::Category->load_iter(
                { blog_id => $old_blog_id, class => '*' } );
            my %cat_parents;
            while ( my $cat = $iter->() ) {
                $callback->(
                    $state . " "
                        . MT->translate(
                        "[_1] records processed...", $counter
                        ),
                    'cats'
                ) if $counter && ( $counter % 100 == 0 );
                $counter++;
                my $cat_id     = $cat->id;
                my $old_parent = $cat->parent;
                my $new_cat    = $cat->clone();
                delete $new_cat->{column_values}->{id};
                delete $new_cat->{changed_cols}->{id};
                $new_cat->blog_id($new_blog_id);

                # temporarily wipe the parent association
                # to avoid constraint issues.
                $new_cat->parent(0);
                $new_cat->save or die $new_cat->errstr;
                $cat_map{$cat_id} = $new_cat->id;
                if ($old_parent) {
                    $cat_parents{ $new_cat->id } = $old_parent;
                }
            }

            # reassign the new category parents
            foreach ( keys %cat_parents ) {
                my $cat = MT::Category->load($_);
                if ($cat) {
                    $cat->parent( $cat_map{ $cat_parents{ $cat->id } } );
                    $cat->save or die $cat->errstr;
                }
            }

            # reconstruct the category order
            $new_blog->category_order(
                join(
                    ',',
                    map( $cat_map{$_},
                        split( /,/, ( $blog->category_order || '' ) ) )
                )
            );

            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed.", $counter ),
                'cats'
            );

            # Placements are automatically cloned if categories are
            # cloned.
            $state = MT->translate("Cloning entry placements for blog...");
            $callback->( $state, "places" );
            require MT::Placement;
            $iter = MT::Placement->load_iter( { blog_id => $old_blog_id } );
            $counter = 0;
            while ( my $place = $iter->() ) {
                $callback->(
                    $state . " "
                        . MT->translate(
                        "[_1] records processed...", $counter
                        ),
                    'places'
                ) if $counter && ( $counter % 100 == 0 );
                $counter++;
                my $new_place = $place->clone();
                delete $new_place->{column_values}->{id};
                delete $new_place->{changed_cols}->{id};
                $new_place->blog_id($new_blog_id);
                $new_place->category_id( $cat_map{ $place->category_id } );
                $new_place->entry_id( $entry_map{ $place->entry_id } );
                $new_place->save or die $new_place->errstr;
            }
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed.", $counter ),
                'places'
            );
        }

        if ( ( !exists $classes->{'MT::Comment'} )
            || $classes->{'MT::Comment'} )
        {

            # Comments can only be cloned if entries are cloned.
            my $state = MT->translate("Cloning comments for blog...");
            $callback->( $state, "comments" );
            require MT::Comment;
            $iter = MT::Comment->load_iter( { blog_id => $old_blog_id } );
            $counter = 0;
            my %comment_parents;
            while ( my $comment = $iter->() ) {
                $callback->(
                    $state . " "
                        . MT->translate(
                        "[_1] records processed...", $counter
                        ),
                    'comments'
                ) if $counter && ( $counter % 100 == 0 );
                $counter++;

                my $new_comment = $comment->clone();
                delete $new_comment->{column_values}->{id};
                delete $new_comment->{changed_cols}->{id};
                $new_comment->entry_id( $entry_map{ $comment->entry_id } );
                $new_comment->blog_id($new_blog_id);
                $new_comment->save or die $new_comment->errstr;
                $comment_map{ $comment->id } = $new_comment->id;
                if ( $comment->parent_id ) {
                    $comment_parents{ $new_comment->id }
                        = $comment->parent_id;
                }
            }
            foreach ( keys %comment_parents ) {
                my $comment = MT::Comment->load($_);
                if ($comment) {
                    $comment->parent_id(
                        $comment_map{ $comment_parents{ $comment->id } } );
                    $comment->save or die $comment->errstr;
                }
            }
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed.", $counter ),
                'comments'
            );
        }

        if ( ( !exists $classes->{'MT::ObjectTag'} )
            || $classes->{'MT::ObjectTag'} )
        {

            # conditionally do MT::ObjectTag since it is only
            # available with MT 3.3.
            if ( $MT::VERSION >= 3.3 ) {
                my $state = MT->translate("Cloning entry tags for blog...");
                $callback->( $state, "tags" );
                require MT::ObjectTag;
                $iter
                    = MT::ObjectTag->load_iter(
                    { blog_id => $old_blog_id, object_datasource => 'entry' }
                    );
                $counter = 0;
                while ( my $entry_tag = $iter->() ) {
                    $callback->(
                        $state . " "
                            . MT->translate(
                            "[_1] records processed...", $counter
                            ),
                        "tags"
                    ) if $counter && ( $counter % 100 == 0 );
                    $counter++;
                    my $new_entry_tag = $entry_tag->clone();
                    delete $new_entry_tag->{column_values}->{id};
                    delete $new_entry_tag->{changed_cols}->{id};
                    $new_entry_tag->blog_id($new_blog_id);
                    $new_entry_tag->object_id(
                        $entry_map{ $entry_tag->object_id } );
                    $new_entry_tag->save or die $new_entry_tag->errstr;
                }
                $callback->(
                    $state . " "
                        . MT->translate( "[_1] records processed.",
                        $counter ),
                    'tags'
                );
            }
        }
    }
    elsif ( ( !exists $classes->{'MT::Category'} )
        || $classes->{'MT::Category'} )
    {

        # Cloning CATEGORY records
        my $state = MT->translate("Cloning categories for blog...");
        $callback->( $state, "cats" );
        $counter = 0;
        require MT::Category;
        $iter = MT::Category->load_iter(
            { blog_id => $old_blog_id, class => '*' } );
        my %cat_parents;
        while ( my $cat = $iter->() ) {
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $counter ),
                'cats'
            ) if $counter && ( $counter % 100 == 0 );
            $counter++;
            my $cat_id     = $cat->id;
            my $old_parent = $cat->parent;
            my $new_cat    = $cat->clone();
            delete $new_cat->{column_values}->{id};
            delete $new_cat->{changed_cols}->{id};
            $new_cat->blog_id($new_blog_id);

            # temporarily wipe the parent association
            # to avoid constraint issues.
            $new_cat->parent(0);
            $new_cat->save or die $new_cat->errstr;
            $cat_map{$cat_id} = $new_cat->id;
            if ($old_parent) {
                $cat_parents{ $new_cat->id } = $old_parent;
            }
        }

        # reassign the new category parents
        foreach ( keys %cat_parents ) {
            my $cat = MT::Category->load($_);
            if ($cat) {
                $cat->parent( $cat_map{ $cat_parents{ $cat->id } } );
                $cat->save or die $cat->errstr;
            }
        }

        # reconstruct the category order
        $new_blog->category_order(
            join(
                ',',
                map( $cat_map{$_},
                    split( /,/, ( $blog->category_order || '' ) ) )
            )
        );

        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'cats'
        );
    }

    if ( ( !exists $classes->{'MT::Trackback'} )
        || $classes->{'MT::Trackback'} )
    {
        my $state = MT->translate("Cloning TrackBacks for blog...");
        $callback->( $state, "tbs" );
        require MT::Trackback;
        $iter = MT::Trackback->load_iter( { blog_id => $old_blog_id } );
        $counter = 0;
        while ( my $tb = $iter->() ) {
            next
                unless ( $tb->entry_id && $entry_map{ $tb->entry_id } )
                || ( $tb->category_id && $cat_map{ $tb->category_id } );

            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $counter ),
                'tbs'
            ) if $counter && ( $counter % 100 == 0 );
            $counter++;
            my $tb_id  = $tb->id;
            my $new_tb = $tb->clone();
            delete $new_tb->{column_values}->{id};
            delete $new_tb->{changed_cols}->{id};

            if ( $tb->category_id ) {
                if ( my $cid = $cat_map{ $tb->category_id } ) {
                    my $cat_tb
                        = MT::Trackback->load( { category_id => $cid } );
                    if ($cat_tb) {
                        my $changed;
                        if ( $tb->passphrase ) {
                            $cat_tb->passphrase( $tb->passphrase );
                            $changed = 1;
                        }
                        if ( $tb->is_disabled ) {
                            $cat_tb->is_disabled(1);
                            $changed = 1;
                        }
                        $cat_tb->save if $changed;
                        $tb_map{$tb_id} = $cat_tb->id;
                        next;
                    }
                }
            }
            elsif ( $tb->entry_id ) {
                if ( my $eid = $entry_map{ $tb->entry_id } ) {
                    my $entry_tb = MT::Entry->load($eid)->trackback;
                    if ($entry_tb) {
                        my $changed;
                        if ( $tb->passphrase ) {
                            $entry_tb->passphrase( $tb->passphrase );
                            $changed = 1;
                        }
                        if ( $tb->is_disabled ) {
                            $entry_tb->is_disabled(1);
                            $changed = 1;
                        }
                        $entry_tb->save if $changed;
                        $tb_map{$tb_id} = $entry_tb->id;
                        next;
                    }
                }
            }

            # A trackback wasn't created when saving the entry/category,
            # (perhaps trackbacks are now disabled for the entry/category?)
            # so create one now
            $new_tb->entry_id( $entry_map{ $tb->entry_id } )
                if $tb->entry_id && $entry_map{ $tb->entry_id };
            $new_tb->category_id( $cat_map{ $tb->category_id } )
                if $tb->category_id && $cat_map{ $tb->category_id };
            $new_tb->blog_id($new_blog_id);
            $new_tb->save or die $new_tb->errstr;
            $tb_map{$tb_id} = $new_tb->id;
        }
        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'tbs'
        );

        if ( ( !exists $classes->{'MT::TBPing'} )
            || $classes->{'MT::TBPing'} )
        {
            my $state = MT->translate("Cloning TrackBack pings for blog...");
            $callback->( $state, "pings" );
            require MT::TBPing;
            $iter = MT::TBPing->load_iter( { blog_id => $old_blog_id } );
            $counter = 0;
            while ( my $ping = $iter->() ) {
                next unless $tb_map{ $ping->tb_id };
                $callback->(
                    $state . " "
                        . MT->translate(
                        "[_1] records processed...", $counter
                        ),
                    'pings'
                ) if $counter && ( $counter % 100 == 0 );
                $counter++;
                my $new_ping = $ping->clone();
                delete $new_ping->{column_values}->{id};
                delete $new_ping->{changed_cols}->{id};
                $new_ping->tb_id( $tb_map{ $ping->tb_id } );
                $new_ping->blog_id($new_blog_id);
                $new_ping->save or die $new_ping->errstr;
            }
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed.", $counter ),
                'pings'
            );
        }
    }

    if ( ( !exists $classes->{'MT::Template'} )
        || $classes->{'MT::Template'} )
    {
        my $state = MT->translate("Cloning templates for blog...");
        $callback->( $state, "tmpls" );
        require MT::Template;
        $iter = MT::Template->load_iter(
            { blog_id => $old_blog_id, type => { not => 'widgetset' } } );
        my $tmpl_processor = sub {
            my ( $new_blog_id, $counter, $tmpl, $new_tmpl, $tmpl_map ) = @_;
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $$counter ),
                'tmpls'
            ) if $counter && ( $$counter % 100 == 0 );
            my $tmpl_id = $tmpl->id;
            $$counter++;
            delete $new_tmpl->{column_values}->{id};
            delete $new_tmpl->{changed_cols}->{id};

            # linked_file won't be cloned for now because
            # new blog does not have site_path - breaks relative path
            delete $new_tmpl->{column_values}->{linked_file};
            delete $new_tmpl->{column_values}->{linked_file_mtime};
            delete $new_tmpl->{column_values}->{linked_file_size};
            $new_tmpl->blog_id($new_blog_id);
            $new_tmpl->save or die $new_tmpl->errstr;
            $tmpl_map->{$tmpl_id} = $new_tmpl->id;
        };
        $counter = 0;
        while ( my $tmpl = $iter->() ) {
            my $new_tmpl = $tmpl->clone();
            $tmpl_processor->(
                $new_blog_id, \$counter, $tmpl, $new_tmpl, \%tmpl_map
            );
        }
        $iter = MT::Template->load_iter(
            { blog_id => $old_blog_id, type => 'widgetset' } );
        while ( my $tmpl = $iter->() ) {
            my @old_widgets = split /,/, $tmpl->modulesets;
            my $new_tmpl = $tmpl->clone();
            $tmpl_processor->(
                $new_blog_id, \$counter, $tmpl, $new_tmpl, \%tmpl_map
            );
            my @new_widgets;
            foreach (@old_widgets) {
                if ( exists $tmpl_map{$_} ) {
                    push @new_widgets, $tmpl_map{$_};
                }
                else {
                    my $global_widget = MT::Template->load($_);
                    push @new_widgets, $_
                        if $global_widget
                            && $global_widget->blog_id == 0
                            && $global_widget->type eq 'widget';
                }
            }
            $new_tmpl->modulesets( join( ',', @new_widgets ) );
            $new_tmpl->save;
        }
        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'tmpls'
        );

        $state = MT->translate("Cloning template maps for blog...");
        $callback->( $state, "tmplmaps" );
        require MT::TemplateMap;
        $iter = MT::TemplateMap->load_iter( { blog_id => $old_blog_id } );
        $counter = 0;
        while ( my $map = $iter->() ) {
            $callback->(
                $state . " "
                    . MT->translate( "[_1] records processed...", $counter ),
                'tmplmaps'
            ) if $counter && ( $counter % 100 == 0 );
            $counter++;
            my $new_map = $map->clone();
            delete $new_map->{column_values}->{id};
            delete $new_map->{changed_cols}->{id};
            $new_map->template_id( $tmpl_map{ $map->template_id } );
            $new_map->blog_id($new_blog_id);
            $new_map->save or die $new_map->errstr;
        }
        $callback->(
            $state . " "
                . MT->translate( "[_1] records processed.", $counter ),
            'tmplmaps'
        );
    }

    MT->run_callbacks(
        ref($blog) . '::post_clone',
        OldBlogId     => $blog->id,
        old_blog_id   => $blog->id,
        NewBlogId     => $new_blog->id,
        new_blog_id   => $new_blog->id,
        OldObject     => $blog,
        old_object    => $blog,
        NewObject     => $new_blog,
        new_object    => $new_blog,
        EntryMap      => \%entry_map,
        entry_map     => \%entry_map,
        CategoryMap   => \%cat_map,
        category_map  => \%cat_map,
        TrackbackMap  => \%tb_map,
        trackback_map => \%tb_map,
        TemplateMap   => \%tmpl_map,
        template_map  => \%tmpl_map,
        Callback      => $callback,
        callback      => $callback,
    );
    $new_blog;
}

sub smart_replace {
    my $blog = shift;
    if (@_) {
        $blog->nwc_smart_replace(@_);
        return;
    }
    my $val = $blog->nwc_smart_replace;
    return defined($val) ? $val : MT->config->NwcSmartReplace;
}

sub smart_replace_fields {
    my $blog = shift;
    if (@_) {
        $blog->nwc_replace_field(@_);
        return;
    }
    my $val = $blog->nwc_replace_field;
    return defined($val) ? $val : MT->config->NwcReplaceField;
}

sub apply_theme {
    my $blog = shift;
    my ($theme_id) = @_;
    require MT::Theme;
    $theme_id ||= $blog->theme_id;
    $theme_id ||=
        $blog->is_blog
        ? MT->config->DefaultBlogTheme
        : MT->config->DefaultWebsiteTheme;
    my $theme = MT::Theme->load($theme_id);
    if ( !defined $theme ) {
        return $blog->error(
            MT->translate(
                "Failed to load theme [_1]: [_2]", $theme_id,
                MT::Theme->errstr
            )
        );
    }
    $theme->apply($blog)
        or return $blog->error(
        MT->translate(
            "Failed to apply theme [_1]: [_2]", $theme_id,
            MT::Theme->errstr
        )
        );
    return 1;
}

sub use_revision {
    my $blog = shift;
    return unless ref($blog);
    return $blog->SUPER::use_revision(@_)
        if 0 < scalar(@_);
    return 0 unless MT->config->TrackRevisions;
    return $blog->SUPER::use_revision;
}

sub template_set {
    my $blog = shift;
    if (@_) {
        return $blog->SUPER::template_set(@_);
    }

    my $theme = $blog->theme;
    unless ($theme) {

        # Try to load template set as theme.
        require MT::Theme;
        $theme = MT::Theme->load( $blog->SUPER::template_set );
    }

    if ($theme) {
        my @elements = $theme->elements;
        my ($elem) = grep { $_->{importer} eq 'template_set' } @elements;
        if ($elem) {
            my $set = $elem->{data};
            $set->{envelope} = $theme->path
                if ref $set;
            return $set;
        }
    }

    $blog->SUPER::template_set;
}

sub to_hash {
    my $obj  = shift;
    my $hash = $obj->SUPER::to_hash(@_);
    $hash->{'blog.site_url'}    = $obj->site_url;
    $hash->{'blog.archive_url'} = $obj->archive_url
        if exists( $hash->{'blog.archive_url'} );
    return $hash;
}

1;
__END__

=head1 NAME

MT::Blog - Movable Type blog record

=head1 SYNOPSIS

    use MT::Blog;
    my $blog = MT::Blog->load($blog_id);
    $blog->name('Some new name');
    $blog->save
        or die $blog->errstr;

=head1 DESCRIPTION

An I<MT::Blog> object represents a blog in the Movable Type system. It
contains all of the settings, preferences, and configuration for a particular
blog. It does not contain any per-author permissions settings--for those,
look at the I<MT::Permission> object.

=head1 USAGE

As a subclass of I<MT::Object>, I<MT::Blog> inherits all of the
data-management and -storage methods from that class; thus you should look
at the I<MT::Object> documentation for details about creating a new object,
loading an existing object, saving an object, etc.

=head1 DATA ACCESS METHODS

The I<MT::Blog> object holds the following pieces of data. These fields can
be accessed and set using the standard data access methods described in the
I<MT::Object> documentation.

=over 4

=item * id

The numeric ID of the blog.

=item * parent_id

The ID of the Website (MT::Website) this blog belongs to

=item * theme_id

If a theme was applied for this blog, this field will hold the theme ID

=item * name

The name of the blog.

=item * description

The blog description.

=item * archive_type

A comma-separated list of archive types used in this particular blog, where
an archive type is one of the following: C<Individual>, C<Daily>, C<Weekly>,
C<Monthly>, or C<Category>. For example, a blog's I<archive_type> would be
C<Individual,Monthly> if the blog were using C<Individual> and C<Monthly>
archives.

=item * archive_type_preferred

The "preferred" archive type, which is used when constructing a link to the
archive page for a particular archive--if multiple archive types are selected,
for example, the link can only point to one of those archives. The preferred
archive type (which should be one of the archive types set in I<archive_type>,
above) specifies to which archive this link should point (among other things).

=item * site_path

The path to the directory containing the blog's output index templates

=item * site_url

The URL corresponding to the I<site_path>

=item * days_on_index

The number of days to be displayed on the index

=item * entries_on_index

The number of entries to be displayed on the index

=item * file_extension

The file extension to be used for archive pages.

=item * email_new_comments

A three-states boolean flag specifying whether authors should be notified
of all new comments posted on entries they have written, just moderated
comments or don't send at all

=item * allow_comment_html

A boolean flag specifying whether HTML should be allowed in comments. If it
is not allowed, it is automatically stripped before building the page (note
that the content stored in the database is B<not> stripped).

=item * autolink_urls

A boolean flag specifying whether URLs in comments should be turned into
links. Note that this setting is only taken into account if
I<allow_comment_html> is turned off.

=item * sort_order_posts

The default sort order for entries. Valid values are either C<ascend> or
C<descend>.

=item * sort_order_comments

The default sort order for comments. Valid values are either C<ascend> or
C<descend>.

=item * allow_comments_default

The default value for the I<allow_comments> field in the I<MT::Entry> object.

=item * server_offset

A slight misnomer, this is actually the timezone that the B<user> has
selected; the value is the offset from GMT.

=item * convert_paras

A comma-separated list of text filters to apply to each entry when it
is built.

=item * convert_paras_comments

A comma-separated list of text filters to apply to each comment when it
is built.

=item * allow_pings_default

The default value for the I<allow_pings> field in the I<MT::Entry> object.

=item * status_default

The default value for the I<status> field in the I<MT::Entry> object.

=item * allow_anon_comments

A boolean flag specifying whether anonymous comments (those posted without
a name or an email address) are allowed.

=item * allow_unreg_comments

A boolean flag specifying whether unregistered comments (those posted
without a validated email/password pair) are allowed.

=item * allow_reg_comments

A boolean flag specifying whether registered users's comments (those posted
with a validated email/password pair) are allowed.

=item * moderate_unreg_comments

Specifying which comments will not be displayed until approved by the
entry author. can be MT::Blog::MODERATE_NONE, (all comments are to be
published immediately) MODERATE_UNTRSTD, (unused) MODERATE_UNAUTHD,
(moderate only comments from unauthenticated users) or MODERATE_ALL

=item * manual_approve_commenters

Specify that the author need to approve each commenter before their
comment will be displayed. this override the MODERATE_NONE setting in
moderate_unreg_comments

=item * allow_commenter_regist

A boolean flag specifying if we should allow commenters to register
to the website, or should they ask the administrator to add them

=item * require_comment_emails

Force the commenters to enter a valid email address

=item * words_in_excerpt

The number of words in an auto-generated excerpt.

=item * allow_pings

Allow blog-level pings

=item * email_new_pings

A flag wether MT should email the blog owner for all new pings, just
moderated pings, or not at all

=item * ping_weblogs

boolean indicating wether to ping weblogs.com

=item * ping_blogs

unused

=item * ping_technorati

unused

=item * ping_google

boolean indicating wether to ping blogsearch.google.com

=item * ping_others

A list of servers to ping after an entry is saved, using XML-RPC.
the list is \r delimited

=item * junk_folder_expiry

How many days junk is kept before automatically deleted. zero to
immediately delete spam

=item * mt_update_key

The Movable Type Recently Updated Key to be sent to I<movabletype.org> after
an entry is saved

=item * google_api_key

unused

=item * autodiscover_links

Search entries for links and upgrade them to pings

=item * internal_autodiscovery

Search entries for links to the same domain of this blog, and upgrade
them to pings

=item * sanitize_spec

sanitize spec to pass MT::Sanitize for sanitizing HTML comments. can
be '0' to disable sanitizing, '1' to enable, or a full spec string

=item * cc_license

IF the blog is CC license, this property holds the variation. for example
'nc-sa' for NonCommercial-ShareAlike

=item * is_dynamic

Specify if this blog is published dynamically or statically

=item * remote_auth_token

A TypePad token

=item * children_modified_on

Field used to communicate to the dynamic publishing (PHP) when this blog
changed - new entry was added, or an entry was edited

=item * custom_dynamic_templates

When using dynamic publishing, this field controls when a template will be
converted to a PHP page. possible values: 'all' - all templates are to
built dynamically. 'none' - all the template will be build on-demand.
'async_all' - all the template will be build a-synchronically.
'async_partial' - the main index, feed and the preferred archive type
are to by build on-demand, and the rest will be built a-synchronically.
'archives' - only the index is to be build on-demand, all the rest will
be built dynamically

=item * junk_score_threshold

When a new comment is entered, it is checked if it is spam using spam
filters. each filter is voting by returning a number between -10 to 10,
(or ABSTAIN) and then numbers are merged to a single spam score. if this
score is bigger then junk_score_threshold, this comment is considered
spam

=item * basename_limit

Maximum number of words that will appear in the base name of an entry.
the base name if based on the entry title, and used to build the entry URL

=item * use_comment_confirmation

If true, after entring a comment the commenter will be redirected to
a 'comment accepted' page

=item * language

The language for date and time display for this particular blog.

=item * welcome_msg

The welcome message to be displayed on the main Editing Menu for this blog.
Should contain all desired HTML formatting.

=item * use_revision

If the global TrackRevisions configuration is enabled, enables the
revision tracking for this blog

=item * archive_path

The path to the directory where the blog's archives are stored.

=item * archive_url

The URL corresponding to the I<archive_path>.

=back

=head1 META DATA ACCESS METHODS

=over 4

=item * image_default_wrap_text

Default setting for embedded images in entries

=item * image_default_align

Default setting for embedded images in entries

=item * image_default_thumb

Default setting for embedded images in entries

=item * image_default_width

Default setting for embedded images in entries

=item * image_default_wunits

Default setting for embedded images in entries

=item * image_default_constrain

Default setting for embedded images in entries

=item * image_default_popup

Default setting for embedded images in entries

=item * commenter_authenticators

A comma-delimited list of authentication options for commenters.
for example: "MovableType,TypeKey,LiveJournal"

=item * require_typekey_emails

If true, force typepad commenters to enter their email

=item * nofollow_urls

If true, add a 'nofollow' tag to all the URLs in the comments and
TrackBacks

=item * follow_auth_links

If true, do not add a 'nofollow' tag to URLs in comments written by
trusted commenter, even if the nofollow_urls property is true

=item * update_pings

Comma-delimited list of server to ping for blog-level updates

=item * captcha_provider

The name of the captcha provider to use for commenter. By default the
captcha option is off, and there is a built-in captcha generator named
'mt_default'. plugins can add more generators

=item * publish_queue

The flag is set to 1 if custom_dynamic_templates is async_all or
async_partially, acting as a flag to use TheSchwartz publishing queue
instead of publishing immediately (in the case of static publishing)

=item * nwc_smart_replace

Replace UTF-8 characters frequently used by word processors with their
more common web equivalents. possible values: 2 - don't replace. 1 -
replace to HTML entities. 0 - replace to ASCII characters

=item * nwc_replace_field

A comma-delimited list specifying where to do the smart replace. possible
values are: qw{title text text_more keywords excerpt tags}

=item * template_set

Returns the template_set that was applied for this blog

=item * page_layout

IF you have a style applied to this blog, it is possible to tweak the
layout of the page, specifying how many columns to use, and do we want
wide or thin columns. all values start with 'layout-', concatenated with
one of: qw{wt tw wm mw wtt twt}, there 't' stand for thin, 'w' for wide
and 'm' for medium

=item * include_system

If this meta field exists, turns the mt:Include tags to Server Side
Includes. It can specify one of these include systems: shtml,
php, jsp or asp

=item * include_cache

=item * max_revisions_entry

If revisions are enabled for this blog, (see use_revision) specify how
many revision to keep for each entry

=item * max_revisions_template

If revisions are enabled for this blog, (see use_revision) specify how
many revision to keep for each template

=item * theme_export_settings

A hash that remembers the last configuration a theme was exported from
this blog. contains at least a "core" key, that contains a hash
with all the configuration, such as name, version, author etc. If there
are plugins with theme exporters installed, they will have an entry in
this hash as well

=item * category_order

Contain a comma-delimiter list of category ids, ordered

=item * folder_order

Contain a comma-delimiter list of folder ids, ordered

=back

=head1 METHODS

=head2 $blog->set_defaults

Set default values to all of the data fields

=head2 $blog->is_blog

returns true if this object is a blog and not some subclass (such as
MT::Website)

=head2 MT::Blog->create_default_blog( [ $blog_name, $blog_template, $website_id ] )

Create a default blog to a newly created website

=head2 $blog->create_default_templates( @templates )

Apply a set of default templates to the blog, from a given template set

=head2 $blog->current_timestamp

Create a time stamp for the blog's time zone, in the "YYYYMMDDHHMMSS"
format

=head2 $blog->website

Returns the blog's parent MT::Website object, or undef if it does not
have one

=head2 $blog->theme

returns the blog's theme (a MT::Theme object)

=head2 $blog->raw_site_url

=head2 $blog->raw_archive_url

=head2 $blog->is_site_path_absolute

returns true is site_path is absolute, (i.e. start with X:\ on DOS,
with '/' on Unix, etc)

=head2 $blog->is_archive_path_absolute

returns true is archive_path is absolute, (i.e. start with X:\ on DOS,
with '/' on Unix, etc)

=head2 $blog->comment_text_filters

Returns an arrayref containing the names of the text filters to be
applied to comments

=head2 $blog->cc_license_url

Returns a URL to a website explaining about the Creative Commons license
that was chosen for this blog

=head2 $blog->email_all_comments

returns true if email will be sent to entry authors for every comment

=head2 $blog->email_attn_reqd_comments

returns true if email will be sent to entry authors only for comments
that require moderation

=head2 $blog->email_all_pings

returns true if email will be sent to entry authors for every ping

=head2 $blog->email_attn_reqd_pings

returns true if email will be sent to entry authors only for pings
that require moderation

=head2 $blog->publish_trusted_commenters

true if it is OK to publish comments from thrusted commenters

=head2 $blog->publish_authd_untrusted_commenters

true if it is OK to publish comments from authenticated but non-thrusted
commenters

=head2 $blog->publish_unauthd_commenters

true if it is OK to publish comments even from un-authenticated
commenters - everyone

=head2 $blog->include_path_parts( %$param )

Accept $param hashref that should contain either a "name" key, for a file
name, or an "id" key for template_id. from these keys a filename will
be created

the path to this file can be passed by the "path" key. if not passed or
if not absolute path, will return a path that start with the IncludeDir
configuration directive

returns ($filename, @path). for using these:

    $file = File::Spec->catfile(
        File::Spec->catdir($blog->site_path, @path),
        $filename
        );

=head2 $blog->include_path

Similar to include_path_parts, but will calculate that final path for you.
In scalar context, returns the final path. in list context returns
(full path, directory, filename)

=head2 $blog->include_url

Similar to include_path_parts, but will return the URL to this file

=head2 $blog->include_statement

Similar to include_path, but wrap the path with an include statement,
according to the include_system defined

=head2 $blog->file_mgr

Returns the I<MT::FileMgr> object specific to this particular blog.

=head2 $blog->has_archive_type( $type )

returns true if this blog support a $type archive type, and have
templates for it

=head2 $blog->accepts_registered_comments

returns true if the blog is configured to allow comments from registered
commenters, and have authenticators to let them register

=head2 $blog->accepts_comments

returns true if commenting is allowed for registered and unregistered
commenters

=head2 $blog->count_static_templates( $archive_type )

returns how many static templates (non-dynamic) the blog have

=head2 $blog->touch( @types )

update the last-modified record (an MT::Touch object) for the passed
@types respectably to this blog to 'now'. @types should be model names,
like 'author' or 'entry'

=head2 clone( [ \%parameters ] )

MT::Blog provides a clone method that supports cloning of all known child
records related to the MT::Blog object. To invoke this behavior, you
simply specify a parameter hash with a 'Children' key set.

    # Clones blog and all data related to this blog within the database.
    my $new_blog = $original_blog->clone({ Children => 1 });

You may further specify what kind of records are cloned in the process
of cloning child objects. Use the 'Classes' parameter to specifically
exclude particular classes:

    # Clones everything except comments and trackback pings
    my $new_blog = $original_blog->clone({
        Children => 1,
        Classes => { 'MT::Comments' => 0, 'MT::TBPing' => 0 }
    });

Note: Certain exclusions will prevent the clone process from including
other classes. For instance, if you exclude MT::Trackback, all MT::TBPing
objects are automatically excluded.

=head2 $blog->smart_replace( [ $new_value ] )

get/set the nwc_smart_replace property. when getting, if not set for
this blog, returns whatever is configured in the global NwcSmartReplace

=head2 $blog->smart_replace_fields( [ $new_value ] )

get/set the nwc_replace_field property. when getting, if not set for
this blog, returns whatever is configured in the global NwcReplaceField

=head2 $blog->apply_theme( [ $theme_id ] )

apply a theme to the blog. if not specify, try to re-apply the current
theme, and if not exists, apply the default theme

=head1 NOTES

=over 4

=item *

When you remove a blog using I<MT::Blog::remove>, in addition to removing the
blog record, all of the entries, notifications, permissions, comments,
templates, and categories in that blog will also be removed.

=item *

Because the system needs to load I<MT::Blog> objects from disk relatively
often during the duration of one request, I<MT::Blog> objects are cached by
the I<MT::Blog::load> object so that each blog only need be loaded once. The
I<MT::Blog> objects are cached in the I<MT::Request> singleton object; note
that this caching B<only occurs> if the blogs are loaded by numeric ID.

=back

=head1 AUTHOR & COPYRIGHTS

Please see the I<MT> manpage for author, copyright, and license information.

=cut