root/branches/release-41/lib/MT/Core.pm @ 2747

Revision 2747, 42.1 kB (checked in by bchoate, 17 months ago)

Updated POD.

  • Property svn:keywords set to Id Revision
Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::Core;
8
9use strict;
10use MT;
11use base 'MT::Component';
12
13# This is just to make our localization scanner happy
14sub trans {
15    return shift;
16}
17
18sub name {
19    return "Core";
20}
21
22my $core_registry;
23
24BEGIN {
25    $core_registry = {
26        version        => MT->VERSION,
27        schema_version => MT->schema_version,
28        object_drivers => {
29            'mysql' => {
30                label => 'MySQL Database',
31                dbd_package => 'DBD::mysql',
32                config_package => 'DBI::mysql',
33            },
34            'postgres' => {
35                label => 'PostgreSQL Database',
36                dbd_package => 'DBD::Pg',
37                dbd_version => '1.32',
38                config_package => 'DBI::postgres',
39            },
40            'sqlite' => {
41                label => 'SQLite Database',
42                dbd_package => 'DBD::SQLite',
43                config_package => 'DBI::sqlite',
44            },
45            'sqlite2' => {
46                label => 'SQLite Database (v2)',
47                dbd_package => 'DBD::SQLite2',
48                config_package => 'DBI::sqlite',
49            },
50        },
51        object_types   => {
52            'entry'           => 'MT::Entry',
53            'author'          => 'MT::Author',
54            'asset'           => 'MT::Asset',
55            'file'            => 'MT::Asset',
56            'asset.image'     => 'MT::Asset::Image',
57            'image'           => 'MT::Asset::Image',
58            'asset.audio'     => 'MT::Asset::Audio',
59            'audio'           => 'MT::Asset::Audio',
60            'asset.video'     => 'MT::Asset::Video',
61            'video'           => 'MT::Asset::Video',
62            'entry.page'      => 'MT::Page',
63            'page'            => 'MT::Page',
64            'category.folder' => 'MT::Folder',
65            'folder'          => 'MT::Folder',
66            'category'        => 'MT::Category',
67            'user'            => 'MT::Author',
68            'commenter'       => 'MT::Author',
69            'blog'            => 'MT::Blog',
70            'template'        => 'MT::Template',
71            'comment'         => 'MT::Comment',
72            'notification'    => 'MT::Notification',
73            'templatemap'     => 'MT::TemplateMap',
74            'banlist'         => 'MT::IPBanList',
75            'ipbanlist'       => 'MT::IPBanList',
76            'tbping'          => 'MT::TBPing',
77            'ping'            => 'MT::TBPing',
78            'ping_cat'        => 'MT::TBPing',
79            'log'             => 'MT::Log',
80            'log.ping'        => 'MT::Log::TBPing',
81            'log.entry'       => 'MT::Log::Entry',
82            'log.comment'     => 'MT::Log::Comment',
83            'log.system'      => 'MT::Log',
84            'tag'             => 'MT::Tag',
85            'role'            => 'MT::Role',
86            'association'     => 'MT::Association',
87            'permission'      => 'MT::Permission',
88            'fileinfo'        => 'MT::FileInfo',
89            'placement'       => 'MT::Placement',
90            'plugindata'      => 'MT::PluginData',
91            'session'         => 'MT::Session',
92            'trackback'       => 'MT::Trackback',
93            'config'          => 'MT::Config',
94            'objecttag'       => 'MT::ObjectTag',
95            'objectscore'     => 'MT::ObjectScore',
96            'objectasset'     => 'MT::ObjectAsset',
97            'touch'           => 'MT::Touch',
98
99            # TheSchwartz tables
100            'ts_job'        => 'MT::TheSchwartz::Job',
101            'ts_error'      => 'MT::TheSchwartz::Error',
102            'ts_exitstatus' => 'MT::TheSchwartz::ExitStatus',
103            'ts_funcmap'    => 'MT::TheSchwartz::FuncMap',
104        },
105        backup_instructions => \&load_backup_instructions,
106        permissions => {
107            'system.administer' => {
108                label => trans("System Administrator"),
109                group => 'sys_admin',
110                order => 0,
111            },
112            'system.create_blog' => {
113                label => trans("Create Blogs"),
114                group => 'sys_admin',
115                order => 100,
116            },
117            'system.manage_plugins' => {
118                label => trans('Manage Plugins'),
119                group => 'sys_admin',
120                order => 200,
121            },
122            'system.edit_templates' => {
123                label => trans('Manage Templates'),
124                group => 'sys_admin',
125                order => 250,
126            },
127            'system.view_log' => {
128                label => trans("View System Activity Log"),
129                group => 'sys_admin',
130                order => 300,
131            },
132
133            'blog.administer_blog' => {
134                label => trans("Blog Administrator"),
135                group => 'blog_admin',
136                order => 0,
137            },
138            'blog.edit_config' => {
139                label => trans("Configure Blog"),
140                group => 'blog_admin',
141                order => 100,
142            },
143            'blog.set_publish_paths' => {
144                label => trans('Set Publishing Paths'),
145                group => 'blog_admin',
146                order => 200,
147            },
148            'blog.edit_categories' => {
149                label => trans('Manage Categories'),
150                group => 'blog_admin',
151                order => 300,
152            },
153            'blog.edit_tags' => {
154                label => trans('Manage Tags'),
155                group => 'blog_admin',
156                order => 400,
157            },
158            'blog.edit_notifications' => {
159                label => trans('Manage Address Book'),
160                group => 'blog_admin',
161                order => 500,
162            },
163            'blog.view_blog_log' => {
164                label => trans('View Activity Log'),
165                group => 'blog_admin',
166                order => 600,
167            },
168
169            'blog.create_post' => {
170                label => trans('Create Entries'),
171                group => 'auth_pub',
172                order => 100,
173            },
174            'blog.publish_post' => {
175                label => trans('Publish Entries'),
176                group => 'auth_pub',
177                order => 200,
178            },
179            'blog.send_notifications' => {
180                label => trans('Send Notifications'),
181                group => 'auth_pub',
182                order => 300,
183            },
184            'blog.edit_all_posts' => {
185                label => trans('Edit All Entries'),
186                group => 'auth_pub',
187                order => 400,
188            },
189            'blog.manage_pages' => {
190                label => trans('Manage Pages'),
191                group => 'auth_pub',
192                order => 500,
193            },
194            'blog.rebuild' => {
195                label => trans('Publish Blog'),
196                group => 'auth_pub',
197                order => 600,
198            },
199
200            'blog.edit_templates' => {
201                label => trans('Manage Templates'),
202                group => 'blog_design',
203                order => 100,
204            },
205
206            'blog.upload' => {
207                label => trans("Upload File"),
208                group => 'blog_upload',
209                order => 100,
210            },
211            'blog.save_image_defaults' => {
212                label => trans('Save Image Defaults'),
213                group => 'blog_upload',
214                order => 200,
215            },
216            'blog.edit_assets' => {
217                label => trans('Manage Assets'),
218                group => 'blog_upload',
219                order => 300,
220            },
221
222            'blog.comment' => {
223                label => trans("Post Comments"),
224                group => 'blog_comment',
225                order => 100,
226            },
227            'blog.manage_feedback' => {
228                label => trans('Manage Feedback'),
229                group => 'blog_comment',
230                order => 200,
231            },
232        },
233        config_settings => {
234            'AtomApp' => {
235                type    => 'HASH',
236                default => {
237                    weblog => 'MT::AtomServer::Weblog::Legacy',
238                    '1.0'  => 'MT::AtomServer::Weblog',
239                    comments => 'MT::AtomServer::Comments',
240                },
241            },
242            'SchemaVersion'   => undef,
243            'MTVersion'       => undef,
244            'NotifyUpgrade'   => { default => 1 },
245            'Database'        => undef,
246            'DBHost'          => undef,
247            'DBSocket'        => undef,
248            'DBPort'          => undef,
249            'DBUser'          => undef,
250            'DBPassword'      => undef,
251            'DefaultLanguage' => {
252                default => 'en_US',
253            },
254            'LocalPreviews'   => { default => 0 },
255            'DefaultSiteRoot' => { default => '', },
256            'DefaultSiteURL'  => { default => '', },
257            'DefaultCommenterAuth' => { default => 'MovableType,LiveJournal,Vox' },
258            'TemplatePath'    => {
259                default => 'tmpl',
260                path    => 1,
261            },
262            'WeblogTemplatesPath' => {
263                default => 'default_templates',
264                path    => 1,
265            },
266            'AltTemplatePath' => {
267                default => 'alt-tmpl',
268                path    => 1,
269            },
270            'CSSPath'    => { default => 'css', },
271            'ImportPath' => {
272                default => 'import',
273                path    => 1,
274            },
275            'PluginPath' => {
276                default => 'plugins',
277                path    => 1,
278                type    => 'ARRAY',
279            },
280            'EnableArchivePaths' => { default => 0, },
281            'SearchTemplatePath' => {
282                default => 'search_templates',
283                path    => 1,
284            },
285            'ObjectDriver'  => undef,
286            'AllowedTextFilters' => undef,
287            'Serializer'    => { default => 'MT', },
288            'SendMailPath'  => { default => '/usr/lib/sendmail', },
289            'RsyncPath'     => undef,
290            'TimeOffset'    => { default => 0, },
291            'WSSETimeout'   => { default => 120, },
292            'StaticWebPath' => { default => '', },
293            'StaticFilePath' => undef,
294            'CGIPath'       => { default => '/cgi-bin/', },
295            'AdminCGIPath'  => undef,
296            'CookieDomain'  => undef,
297            'CookiePath'    => undef,
298            'MailEncoding'  => {
299                default => 'ISO-8859-1',
300            },
301            'MailTransfer'      => { default => 'sendmail' },
302            'SMTPServer'        => { default => 'localhost', },
303            'DebugEmailAddress' => undef,
304            'WeblogsPingURL' => { default => 'http://rpc.weblogs.com/RPC2', },
305            'BlogsPingURL'   => { default => 'http://ping.blo.gs/', },
306            'MTPingURL' => { default => 'http://www.movabletype.org/update/', },
307            'TechnoratiPingURL' =>
308              { default => 'http://rpc.technorati.com/rpc/ping', },
309            'GooglePingURL' =>
310              { default => 'http://blogsearch.google.com/ping/RPC2', },
311            'CGIMaxUpload'          => { default => 20_480_000 },
312            'DBUmask'               => { default => '0111', },
313            'HTMLUmask'             => { default => '0111', },
314            'UploadUmask'           => { default => '0111', },
315            'DirUmask'              => { default => '0000', },
316            'HTMLPerms'             => { default => '0666', },
317            'UploadPerms'           => { default => '0666', },
318            'NoTempFiles'           => { default => 0, },
319            'TempDir'               => { default => '/tmp', },
320            'RichTextEditor'        => { default => 'archetype', },
321            'EntriesPerRebuild'     => { default => 40, },
322            'UseNFSSafeLocking'     => { default => 0, },
323            'NoLocking'             => { default => 0, },
324            'NoHTMLEntities'        => { default => 1, },
325            'NoCDATA'               => { default => 0, },
326            'NoPlacementCache'      => { default => 0, },
327            'NoPublishMeansDraft'   => { default => 0, },
328            'IgnoreISOTimezones'    => { default => 0, },
329            'PingTimeout'           => { default => 60, },
330            'HTTPTimeout'           => { default => 60 },
331            'PingInterface'         => undef,
332            'HTTPInterface'         => undef,
333            'PingProxy'             => undef,
334            'HTTPProxy'             => undef,
335            'PingNoProxy'           => { default => 'localhost', },
336            'HTTPNoProxy'           => { default => 'localhost', },
337            'ImageDriver'           => { default => 'ImageMagick', },
338            'NetPBMPath'            => undef,
339            'AdminScript'           => { default => 'mt.cgi', },
340            'ActivityFeedScript'    => { default => 'mt-feed.cgi', },
341            'ActivityFeedItemLimit' => { default => 50, },
342            'CommentScript'         => { default => 'mt-comments.cgi', },
343            'TrackbackScript'       => { default => 'mt-tb.cgi', },
344            'SearchScript'          => { default => 'mt-search.cgi', },
345            'XMLRPCScript'          => { default => 'mt-xmlrpc.cgi', },
346            'ViewScript'            => { default => 'mt-view.cgi', },
347            'AtomScript'            => { default => 'mt-atom.cgi', },
348            'UpgradeScript'         => { default => 'mt-upgrade.cgi', },
349            'CheckScript'           => { default => 'mt-check.cgi', },
350            'NotifyScript'          => { default => 'mt-add-notify.cgi', },
351            'PublishCharset'        => {
352                default => 'utf-8',
353            },
354            'SafeMode'           => { default => 1, },
355            'GlobalSanitizeSpec' => {
356                default => 'a href,b,i,br/,p,strong,em,ul,ol,li,blockquote,pre',
357            },
358            'GenerateTrackBackRSS' => { default => 0, },
359
360            ## Search settings, copied from Jay's mt-search and integrated
361            ## into default config.
362            'NoOverride'          => { default => '', },
363            'RegexSearch'         => { default => 0, },
364            'CaseSearch'          => { default => 0, },
365            'ResultDisplay'       => { default => 'descend', },
366            'ExcerptWords'        => { default => 40, },
367            'SearchElement'       => { default => 'entries', },
368            'ExcludeBlogs'        => undef,
369            'IncludeBlogs'        => undef,
370            'DefaultTemplate'     => { default => 'default.tmpl', },
371            'Type'                => { default => 'straight', },
372            'MaxResults'          => { default => '20', },
373            'SearchCutoff'        => { default => '9999999', },
374            'CommentSearchCutoff' => { default => '30', },
375            'AltTemplate'         => {
376                type    => 'ARRAY',
377                default => 'feed results_feed.tmpl',
378            },
379            'SearchSortBy'    => undef,
380            'SearchSortOrder' => { default => 'ascend', },
381            'SearchNoOverride'      => { default => 'SearchMaxResults', },
382            'SearchResultDisplay'   => { alias => 'ResultDisplay', },
383            'SearchExcerptWords'    => { alias => 'ExcerptWords', },
384            'SearchDefaultTemplate' => { alias => 'DefaultTemplate', },
385            'SearchMaxResults'      => { alias => 'MaxResults', },
386            'SearchAltTemplate'     => { alias => 'AltTemplate' },
387            'SearchPrivateTags'     => { default => 0 },
388            'RegKeyURL' =>
389              { default => 'http://www.typekey.com/extras/regkeys.txt', },
390            'IdentitySystem' =>
391              { default => 'http://www.typekey.com/t/typekey', },
392            'SignOnURL' =>
393              { default => 'https://www.typekey.com/t/typekey/login?', },
394            'SignOffURL' =>
395              { default => 'https://www.typekey.com/t/typekey/logout?', },
396            'IdentityURL'     => { default => "http://profile.typekey.com/", },
397            'DynamicComments' => { default => 0, },
398            'SignOnPublicKey' => { default => '', },
399            'ThrottleSeconds' => { default => 20, },
400            'SearchCacheTTL'        => { default => 20, },
401            'SearchThrottleSeconds' => { default => 5 },
402            'SearchThrottleIPWhitelist' => undef,
403            'OneHourMaxPings'           => { default => 10, },
404            'OneDayMaxPings'            => { default => 50, },
405            'SupportURL'                => {
406                default => 'http://www.sixapart.com/movabletype/support/',
407            },
408            'NewsURL' => {
409                default => 'http://www.sixapart.com/movabletype/news/',
410            },
411            'NewsboxURL' => {
412                default => 'http://www.sixapart.com/movabletype/news/mt4_news_widget.html',
413            },
414            # 'MTNewsURL' => {
415            #     default => 'http://www.sixapart.com/movabletype/news/mt4_news_widget.html',
416            # },
417            'LearningNewsURL' => {
418                default => 'http://learning.movabletype.org/newsbox.html',
419            },
420            # 'HackingNewsURL' => {
421            #     default => 'http://hacking.movabletype.org/newsbox.html',
422            # },
423            'EmailAddressMain'      => undef,
424            'EmailReplyTo'          => undef,
425            'EmailNotificationBcc'  => { default => 1, },
426            'CommentSessionTimeout' => { default => 60 * 60 * 24 * 3, },
427            'UserSessionTimeout'    => { default => 60 * 60 * 4, },
428            'UserSessionCookieName' => { handler => \&UserSessionCookieName },
429            'UserSessionCookieDomain' => { default => '<$MTBlogHost exclude_port="1"$>' },
430            'UserSessionCookiePath' => { handler => \&UserSessionCookiePath },
431            'UserSessionCookieTimeout' => { default => 60 * 60 * 4, },
432            'LaunchBackgroundTasks' => { default => 0 },
433            'TypeKeyVersion'        => { default => '1.1' },
434            'TransparentProxyIPs'   => { default => 0, },
435            'DebugMode'             => { default => 0, },
436            'ShowIPInformation'     => { default => 0, },
437            'AllowComments'         => { default => 1, },
438            'AllowPings'            => { default => 1, },
439            'HelpURL'               => undef,
440            #'HelpURL'               => {
441            #    default => 'http://www.sixapart.com/movabletype/docs/4.0/',
442            #},
443            'UsePlugins'               => { default => 1, },
444            'PluginSwitch'             => { type    => 'HASH', },
445            'PluginSchemaVersion'      => { type    => 'HASH', },
446            'OutboundTrackbackLimit'   => { default => 'any', },
447            'OutboundTrackbackDomains' => { type    => 'ARRAY', },
448            'IndexBasename'            => { default => 'index', },
449            'LogExportEncoding'        => {
450                default => 'utf-8',
451            },
452            'ActivityFeedsRunTasks' => { default => 1, },
453            'ExportEncoding'        => {
454                default => 'utf-8',
455            },
456            'SQLSetNames'     => undef,
457            'UseSQLite2'      => { default => 0, },
458            'UseJcodeModule'  => { default => 0, },
459            'DefaultTimezone' => {
460                default => '0',
461            },
462            'CategoryNameNodash' => {
463                default => '0',
464            },
465            'DefaultListPrefs' => {
466                type    => 'HASH',
467            },
468            'DefaultEntryPrefs' => {
469                type    => 'HASH',
470                default => {
471                    type   => 'Default',         # Default|All|Custom
472                    button => 'Below',           # Above|Below|Both
473                    height => 162,               # textarea height
474                },
475            },
476            'DeleteFilesAtRebuild'      => { default => 1, },
477            'RebuildAtDelete'           => { default => 1, },
478            'MaxTagAutoCompletionItems' => { default => 1000, },
479            'NewUserAutoProvisioning' =>
480              { handler => \&NewUserAutoProvisioning, },
481            'NewUserTemplateBlogId'   => undef,
482            'DefaultUserLanguage'     => undef,
483            'DefaultUserTagDelimiter' => {
484                handler => \&DefaultUserTagDelimiter,
485                default => 'comma',
486            },
487            'AuthenticationModule' => { default => 'MT', },
488            'AuthLoginURL'         => undef,
489            'AuthLogoutURL'        => undef,
490            'DefaultAssignments'   => undef,
491            'AutoSaveFrequency'         => { default => 5 },
492            'FuturePostFrequency'       => { default => 1 },
493            'AssetCacheDir'             => { default => 'assets_c', },
494            'IncludesDir'               => { default => 'includes_c', },
495            'MemcachedServers'          => { type    => 'ARRAY', },
496            'MemcachedNamespace'        => undef,
497            'MemcachedDriver'           => { default => 'Cache::Memcached' },
498            'CommenterRegistration'     => {
499                type    => 'HASH',
500                default => {
501                    Allow  => '1',
502                    Notify => q(),
503                },
504            },
505            'CaptchaSourceImageBase'     => undef,
506            'SecretToken'                => { handler => \&SecretToken, },
507            ## NaughtyWordChars settings
508            'NwcSmartReplace' => { default => 0, },
509            'NwcReplaceField' =>
510              { default => 'title,text,text_more,keywords,excerpt,tags', },
511            'DisableNotificationPings'   => { default => 0 },
512            'SyncTarget' => { type => 'ARRAY' },
513            'RsyncOptions' => undef,
514            'UserpicAllowRect' => { default => 0 },
515            'UserpicMaxUpload' => { default => 0 },
516            'UserpicThumbnailSize' => { default => 100 },
517
518            # Basename settings
519            'AuthorBasenameLimit' => { default => 30 },
520            'PerformanceLogging' => { default => 0 },
521            'PerformanceLoggingPath' =>  { handler => \&PerformanceLoggingPath },
522            'PerformanceLoggingThreshold' => { default => 0.1 },
523            'ProcessMemoryCommand' => { handler => \&ProcessMemoryCommand },
524            'EnableAddressBook' => { default => 0 },
525            'SingleCommunity' => { default => 0 },
526        },
527        upgrade_functions => \&load_upgrade_fns,
528        applications      => {
529            'xmlrpc'   => { handler => 'MT::XMLRPCServer', },
530            'atom'     => { handler => 'MT::AtomServer', },
531            'feeds'    => { handler => 'MT::App::ActivityFeeds', },
532            'view'     => { handler => 'MT::App::Viewer', },
533            'notify'   => { handler => 'MT::App::NotifyList', },
534            'tb'       => { handler => 'MT::App::Trackback', },
535            'upgrade'  => { handler => 'MT::App::Upgrade', },
536            'wizard'   => { handler => 'MT::App::Wizard', },
537            'comments' => {
538                handler => 'MT::App::Comments',
539                tags => sub { MT->app->load_core_tags },
540            },
541            'search'   => {
542                handler => 'MT::App::Search::Legacy', 
543                tags => sub { MT->app->load_core_tags },
544            },
545            'new_search'   => {
546                handler => 'MT::App::Search', 
547                tags    => sub { 
548                    require MT::Template::Context::Search;
549                    return MT::Template::Context::Search->load_core_tags();
550                },
551                methods => sub { MT->app->core_methods() },
552                default => sub { MT->app->core_parameters() },
553            },
554            'cms'      => {
555                handler         => 'MT::App::CMS',
556                cgi_base        => 'mt',
557                page_actions    => sub { MT->app->core_page_actions(@_) },
558                list_actions    => sub { MT->app->core_list_actions(@_) },
559                list_filters    => sub { MT->app->core_list_filters(@_) },
560                search_apis     => sub {
561                    require MT::CMS::Search;
562                    return MT::CMS::Search::core_search_apis(MT->app, @_);
563                },
564                menus           => sub { MT->app->core_menus() },
565                methods         => sub { MT->app->core_methods() },
566                widgets         => sub { MT->app->core_widgets() },
567                blog_stats_tabs => sub { MT->app->core_blog_stats_tabs() },
568                import_formats  => sub {
569                    require MT::Import;
570                    return MT::Import->core_import_formats();
571                },
572            },
573        },
574        archive_types => \&load_archive_types,
575        tags          => \&load_core_tags,
576        text_filters  => {
577            '__default__' => {
578                label   => 'Convert Line Breaks',
579                handler => 'MT::Util::html_text_transform',
580            },
581            'richtext' => {
582                label   => 'Rich Text',
583                handler => 'MT::Util::rich_text_transform',
584                condition => sub {
585                    my ($type) = @_;
586                    return 1 if $type && ($type ne 'comment');
587                },
588            },
589        },
590        richtext_editors => {
591            'archetype' => {
592                label => 'Movable Type Default',
593                template => 'archetype_editor.tmpl',
594            },
595        },
596        ping_servers  => {
597            'weblogs' => {
598                label => 'weblogs.com',
599                url   => 'http://rpc.weblogs.com/RPC2',
600            },
601            'technorati' => {
602                label => 'technorati.com',
603                url   => 'http://rpc.technorati.com/rpc/ping',
604            },
605            'google' => {
606                label => 'google.com',
607                url   => 'http://blogsearch.google.com/ping/RPC2',
608            },
609        },
610        commenter_authenticators => \&load_core_commenter_auth,
611        captcha_providers        => \&load_captcha_providers,
612        tasks                    => \&load_core_tasks,
613        default_templates        => \&load_default_templates,
614        template_sets => {
615            mt_blog => {
616                label => "Classic Blog",
617                order => 100,
618                # means, load from 'default_templates' registry
619                # which we've established for core templates with
620                # the MT 4.0 registry
621                templates => '*',
622            },
623        },
624        junk_filters             => \&load_junk_filters,
625        task_workers             => {
626            'mt_rebuild' => {
627                label => "Publishes content.",
628                class => 'MT::Worker::Publish',
629            },
630            'mt_sync' => {
631                label => "Synchronizes content to other server(s).",
632                class => 'MT::Worker::Sync',
633            },
634        },
635        archivers => {
636            'zip' => {
637                class => 'MT::Util::Archive::Zip',
638                label => 'zip',
639            },
640            'tgz' => {
641                class => 'MT::Util::Archive::Tgz',
642                label => 'tar.gz',
643            },
644        },
645        template_snippets        => {
646            'insert_entries' => {
647                trigger => 'entries',
648                label   => 'Entries List',
649                content => qq{<mt:Entries lastn="10">\n    \$0\n</mt:Entries>\n},
650            },
651            'blog_url' => {
652                trigger => 'blogurl',
653                label => 'Blog URL',
654                content => '<$mt:BlogURL$>$0',
655            },
656            'blog_id' => {
657                trigger => 'blogid',
658                label => 'Blog ID',
659                content => '<$mt:BlogID$>$0',
660            },
661            'blog_name' => {
662                trigger => 'blogname',
663                label => 'Blog Name',
664                content => '<$mt:BlogName$>$0',
665            },
666            'entry_body' => {
667                trigger => 'entrybody',
668                label => 'Entry Body',
669                content => '<$mt:EntryBody$>$0',
670            },
671            'entry_excerpt' => {
672                trigger => 'entryexcerpt',
673                label => 'Entry Excerpt',
674                content => '<$mt:EntryExcerpt$>$0',
675            },
676            'entry_link' => {
677                trigger => 'entrylink',
678                label => 'Entry Link',
679                content => '<$mt:EntryLink$>$0',
680            },
681            'entry_more' => {
682                trigger => 'entrymore',
683                label => 'Entry Extended Text',
684                content => '<$mt:EntryMore$>$0',
685            },
686            'entry_title' => {
687                trigger => 'entrytitle',
688                label => 'Entry Title',
689                content => '<$mt:EntryTitle$>$0',
690            },
691            'if' => {
692                trigger => 'mtif',
693                label => 'If Block',
694                content => qq{<mt:if name="variable">\n    \$0\n</mt:if>\n},
695            },
696            'if_else' => {
697                trigger => 'mtife',
698                label => 'If/Else Block',
699                content => qq{<mt:if name="variable">\n    \$0\n<mt:else>\n\n</mt:if>\n},
700            },
701            'include_module' => {
702                trigger => 'module',
703                label => 'Include Template Module',
704                content => '<$mt:Include module="$0"$>',
705            },
706            'include_file' => {
707                trigger => 'file',
708                label => 'Include Template File',
709                content => '<$mt:Include file="$0"$>',
710            },
711            'getvar' => {
712                trigger => 'get',
713                label => 'Get Variable',
714                content => '<$mt:var name="$0"$>',
715            },
716            'setvar' => {
717                trigger => 'set',
718                label => 'Set Variable',
719                content => '<$mt:var name="$0" value="value"$>',
720            },
721            'setvarblock' => {
722                trigger => 'setb',
723                label => 'Set Variable Block',
724                content => qq{<mt:SetVarBlock name="variable">\n    \$0\n</mt:SetVarBlock>\n},
725            },
726            'widget_manager' => {
727                trigger => 'widget',
728                label => 'Widget Set',
729                content => '<$mt:WidgetSet name="$0"$>',
730            },
731        },
732    };
733}
734
735sub id {
736    return 'core';
737}
738
739sub load_junk_filters {
740    require MT::JunkFilter;
741    return MT::JunkFilter->core_filters;
742}
743
744sub load_core_tasks {
745    my $cfg = MT->config;
746    return {
747        'FuturePost' => {
748            label     => 'Publish Scheduled Entries',
749            frequency => $cfg->FuturePostFrequency * 60,    # once per minute
750            code      => sub {
751                MT->instance->publisher->publish_future_posts;
752              }
753        },
754        'JunkExpiration' => {
755            label     => 'Junk Folder Expiration',
756            frequency => 12 * 60 * 60,             # no more than every 12 hours
757            code      => sub {
758                require MT::JunkFilter;
759                MT::JunkFilter->task_expire_junk;
760            },
761        },
762        'CleanTemporaryFiles' => {
763            label => 'Remove Temporary Files',
764            frequency => 60 * 60,   # once per hour
765            code => sub {
766                MT::Core->remove_temporary_files;
767            },
768        },
769        'RemoveExpiredUserSessions' => {
770            label => 'Remove Expired User Sessions',
771            frequency => 60 * 60 * 24,   # once a day
772            code => sub {
773                MT::Core->remove_expired_sessions;
774            },
775        },
776        'RemoveExpiredSearchCaches' => {
777            label => 'Remove Expired Search Caches',
778            frequency => 60 * 60 * 24,   # once a day
779            code => sub {
780                MT::Core->remove_expired_search_caches;
781            },
782        },
783    };
784}
785
786sub remove_temporary_files {
787    require MT::Session;
788
789    my @files = MT::Session->load(
790        { kind => 'TF', start => [ undef, time - 60 * 60 ] },
791        { range => { start => 1 } } );
792    my $fmgr = MT::FileMgr->new('Local');
793    foreach my $f (@files) {
794        if ($fmgr->delete($f->name)) {
795            $f->remove;
796        }
797    }
798    # This is a silent task; no need to log removal of temporary files
799    return '';
800}
801
802sub remove_expired_sessions {
803    require MT::Session;
804
805    my $expired = MT->config->UserSessionTimeout;
806    my @sesss = MT::Session->load(
807        { kind => 'US', start => [ undef, time - $expired ] },
808        { range => { start => 1 } } );
809    foreach my $s (@sesss) {
810        $s->remove if !$s->get('remember');
811    }
812    return '';
813}
814
815sub remove_expired_search_caches {
816    require MT::Session;
817
818    MT::Session->remove(
819        { kind => 'CS', start => [ undef, time - 60 * 60 ] },
820        { range => { start => 1 } } );
821    return '';
822}
823
824sub load_default_templates {
825    require MT::DefaultTemplates;
826    return MT::DefaultTemplates->core_default_templates;
827}
828
829sub load_captcha_providers {
830    return MT->core_captcha_providers;
831}
832
833sub load_core_commenter_auth {
834    return MT->core_commenter_authenticators;
835}
836
837sub load_core_tags {
838    require MT::Template::ContextHandlers;
839    return MT::Template::Context::core_tags();
840}
841
842sub load_upgrade_fns {
843    require MT::Upgrade;
844    return MT::Upgrade->core_upgrade_functions;
845}
846
847sub load_backup_instructions {
848    require MT::BackupRestore;
849    return MT::BackupRestore::core_backup_instructions();
850}
851
852sub l10n_class { 'MT::L10N' }
853
854sub init_registry {
855    my $c = shift;
856    return $c->{registry} = $core_registry;
857}
858
859# Config handlers for these settings...
860
861sub load_archive_types {
862    require MT::WeblogPublisher;
863    return MT::WeblogPublisher->core_archive_types;
864}
865
866sub PerformanceLoggingPath {
867    my $cfg = shift;
868    my ($path, $default);
869    return $cfg->set_internal( 'PerformanceLoggingPath', @_ ) if @_;
870
871    unless ($path = $cfg->get_internal('PerformanceLoggingPath')) {
872        $path = $default = File::Spec->catdir(
873            MT->instance->static_file_path, 'support', 'logs');
874    }
875
876    # If the $path is not a writeable directory, we need to
877    # do some work to see if we can create it
878    if (! (-d $path and -w $path)) {
879        # Determine where MT should put its logging data.  It will be
880        # the first existing and writeable directory found or created
881        # between PerformanceLoggingPath configuration directive value
882        # and the default fallback of MT_DIR/support/logs.  If neither
883        # can be used, we return an undefined value and simply don't
884        # log the performance stats.
885        #
886        # However, we do log any such errors in the activity log to
887        # notify the user that there is a problem.
888
889        my @dirs = ( $path, ( $default && $path ne $default ? ( $default ) : () ) );
890        require File::Spec;   
891        foreach my $dir (@dirs) {
892            my $msg = '';
893            if (-d $dir and -w $dir) {
894                $path = $dir;
895            }
896            elsif (! -e $dir) {
897                require File::Path;
898                eval { File::Path::mkpath([$dir], 0, 0777); $path = $dir; };
899                if ($@) {
900                    $msg = MT->translate('Error creating performance logs directory, [_1]. Please either change the permissions to make it writable or specify an alternate using the PerformanceLoggingPath configuration directive: [_2]', $dir, $@);
901                }
902            }
903            elsif (-e $dir and ! -d $dir) {
904                $msg = MT->translate('Error creating performance logs: PerformanceLoggingPath setting must be a directory path, not a file: [_1]', $dir);
905            }
906            elsif (-e $dir and ! -w $dir) {
907                    $msg = MT->translate('Error creating performance logs: PerformanceLoggingPath directory exists but is not writeable: [_1]', $dir);                 
908            }
909
910            if ($msg) {
911                # Issue MT log within an eval block in the
912                # event that the plugin error is happening before
913                # the database has been initialized...
914                require MT::Log;
915                MT->log({  message => $msg, 
916                            class => 'system',
917                            level => MT::Log::ERROR() });
918            }
919            last if $path;
920        }
921    }
922    return $path;
923}
924
925sub ProcessMemoryCommand {
926    my $cfg = shift;
927    $cfg->set_internal( 'ProcessMemoryCommand', @_ ) if @_;
928    my $cmd = $cfg->get_internal('ProcessMemoryCommand');
929    unless ($cmd) {
930        my $os = $^O;
931        if ($os eq 'darwin') {
932            $cmd = 'ps $$ -o rss=';
933        }
934        elsif ($os eq 'linux') {
935            $cmd = 'ps -p $$ -o rss=';
936        }
937        elsif ($os eq 'MSWin32') {
938            $cmd = { command => q{tasklist /FI "PID eq $$" /FO TABLE /NH},
939                regex => qr/([\d,]+) K/ };
940        }
941    }
942    return $cmd;
943}
944
945sub SecretToken {
946    my $cfg = shift;
947    $cfg->set_internal( 'SecretToken', @_ ) if @_;
948    my $secret = $cfg->get_internal('SecretToken');
949    unless ($secret) {
950        my @alpha = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 );
951        $secret = join '', map $alpha[ rand @alpha ], 1 .. 40;
952        $secret = $cfg->set_internal( 'SecretToken', $secret, 1 );
953        $cfg->save_config();
954    }
955    return $secret;
956}
957
958sub DefaultUserTagDelimiter {
959    my $mgr = shift;
960    return $mgr->set_internal( 'DefaultUserTagDelimiter', @_ ) if @_;
961    my $delim = $mgr->get_internal('DefaultUserTagDelimiter');
962    if ( lc $delim eq 'comma' ) {
963        return ord(',');
964    }
965    elsif ( lc $delim eq 'space' ) {
966        return ord(' ');
967    }
968    else {
969        return ord(',');
970    }
971}
972
973sub NewUserAutoProvisioning {
974    my $mgr = shift;
975    return $mgr->set_internal( 'NewUserAutoProvisioning', @_ ) if @_;
976    return 0 unless $mgr->DefaultSiteRoot && $mgr->DefaultSiteURL;
977    $mgr->get_internal('NewUserAutoProvisioning');
978}
979
980sub UserSessionCookieName {
981    my $mgr = shift;
982    return $mgr->set_internal( 'UserSessionCookieName', @_ ) if @_;
983    my $name = $mgr->get_internal('UserSessionCookieName');
984    return $name if defined $name;
985    if ($mgr->get_internal('SingleCommunity')) {
986        return 'mt_blog_user';
987    } else {
988        return 'mt_blog%b_user';
989    }
990}
991
992sub UserSessionCookiePath {
993    my $mgr = shift;
994    return $mgr->set_internal( 'UserSessionCookiePath', @_ ) if @_;
995    my $path = $mgr->get_internal('UserSessionCookiePath');
996    return $path if defined $path;
997    if ($mgr->get_internal('SingleCommunity')) {
998        return '/';
999    } else {
1000        return '<$MTBlogRelativeURL$>';
1001    }
1002}
1003
10041;
1005__END__
1006
1007=head1 NAME
1008
1009MT::Core - Core component for Movable Type functionality.
1010
1011=head1 METHODS
1012
1013=head2 MT::Core::trans($phrase)
1014
1015Stub method that returns the phrase it is given.
1016
1017=head2 MT::Core->name()
1018
1019Returns a string identifying this component.
1020
1021=head2 MT::Core->id()
1022
1023Returns the identifier for this component.
1024
1025=head2 MT::Core::load_junk_filters()
1026
1027Routine that returns the core junk filter registry elements (these
1028live in the L<MT::JunkFilter> package).
1029
1030=head2 MT::Core::load_core_tasks()
1031
1032Routine that returns the core L<MT::TaskMgr> registry elements.
1033
1034=head2 MT::Core->remove_temporary_files()
1035
1036Utility method for removing any temporary files that MT generates.
1037
1038=head2 MT::Core->remove_expired_sessions()
1039
1040Utility method for clearing expired MT user session records.
1041
1042=head2 MT::Core->remove_expired_search_caches()
1043
1044Utility method for removing expired search cache records.
1045
1046=head2 MT::Core::load_default_templates()
1047
1048Routine that returns the default template set registry elements.
1049
1050=head2 MT::Core::load_captcha_providers()
1051
1052Routine that returns the CAPTCHA provider registry elements.
1053
1054=head2 MT::Core::load_core_commenter_auth()
1055
1056Routine that returns the core registry elements for commenter
1057authentication methods.
1058
1059=head2 MT::Core::load_core_tags()
1060
1061Routine that returns the core registry elements for the MT
1062template tags are enabled for the entire system (excludes
1063application-specific tags).
1064
1065=head2 MT::Core::load_upgrade_fns()
1066
1067Routine that returns the core registry elements for the MT
1068schema upgrade framework.
1069
1070=head2 MT::Core::load_backup_instructions
1071
1072Routine that returns the core registry elements for the MT
1073Backup/Restore framework.
1074
1075=head2 MT::Core->l10n_class
1076
1077Returns the localization package for the core component.
1078
1079=head2 $core->init_registry()
1080
1081=head2 MT::Core::load_archive_types()
1082
1083Routine that returns the core registry elements for the
1084publishable archive types. See L<MT::ArchiveType>.
1085
1086=head2 MT::Core::PerformanceLoggingPath
1087
1088A L<MT::ConfigMgr> get/set method for the C<PerformanceLoggingPath>
1089configuration setting. If the user has not designated a path, this
1090will return a default location, which is programatically determined.
1091
1092=head2 MT::Core::ProcessMemoryCommand
1093
1094A L<MT::ConfigMgr> get/set method for the C<ProcessMemoryCommand>
1095configuration setting. If the user has not assigned this themselves,
1096it will return a default command, determined by the operating system
1097Movable Type is running on.
1098
1099=head2 MT::Core::SecretToken
1100
1101A L<MT::ConfigMgr> get/set method for the C<SecretToken>
1102configuration setting. If the user has not assigned this themselves,
1103it will return a random token value, and save it to the database for
1104future use.
1105
1106=head2 MT::Core::DefaultUserTagDelimiter
1107
1108A L<MT::ConfigMgr> get/set method for the C<DefaultUserTagDelimiter>
1109configuration setting. Translates the keyword values 'comma' and
1110'space' to the ASCII code for those characters.
1111
1112=head2 MT::Core::NewUserAutoProvisioning
1113
1114A L<MT::ConfigMgr> get/set method for the C<NewUserAutoProvisioning>
1115configuration setting. Even if the user has enabled this setting,
1116it will force a value of '0' unless the C<DefaultSiteRoot> and
1117C<DefaultSiteURL> configuration settings are also assigned.
1118
1119=head2 MT::Core::UserSessionCookieName
1120
1121A L<MT::ConfigMgr> get/set method for the C<UserSessionCookieName>
1122configuration setting. If the user has not specifically assigned
1123this setting, a default value is returned, affected by the
1124C<SingleCommunity> setting. If C<SingleCommunity> is enabled, it
1125returns a cookie name that is the same for all blogs. If it is
1126off, it returns a cookie name that is blog-specific (contains the
1127blog id in the cookie name).
1128
1129=head2 UserSessionCookiePath
1130
1131A L<MT::ConfigMgr> get/set method for the C<UserSessionCookiePath>
1132configuration setting. If the user has not specifically assigned
1133this setting, a default value is returned, affected by the
1134C<SingleCommunity> setting. If C<SingleCommunity> is enabled, it
1135returns a path that is the same for all blogs ('/'). If it is
1136off, it returns a value that will yield the blog's relative
1137URL path.
1138
1139=head1 LICENSE
1140
1141The license that applies is the one you agreed to when downloading
1142Movable Type.
1143
1144=head1 AUTHOR & COPYRIGHT
1145
1146Except where otherwise noted, MT is Copyright 2001-2008 Six Apart.
1147All rights reserved.
1148
1149=cut
Note: See TracBrowser for help on using the browser.