root/branches/release-38/lib/MT/Core.pm @ 2377

Revision 2377, 37.4 kB (checked in by bchoate, 19 months ago)

Fix for setting user context for comment previews. BugId:79757

  • 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 => 10000, },
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    };
777}
778
779sub remove_temporary_files {
780    require MT::Session;
781
782    my @files = MT::Session->load(
783        { kind => 'TF', start => [ undef, time - 60 * 60 ] },
784        { range => { start => 1 } } );
785    my $fmgr = MT::FileMgr->new('Local');
786    foreach my $f (@files) {
787        if ($fmgr->delete($f->name)) {
788            $f->remove;
789        }
790    }
791    # This is a silent task; no need to log removal of temporary files
792    return '';
793}
794
795sub remove_expired_sessions {
796    require MT::Session;
797
798    my $expired = MT->config->UserSessionTimeout;
799    my @sesss = MT::Session->load(
800        { kind => 'US', start => [ undef, time - $expired ] },
801        { range => { start => 1 } } );
802    foreach my $s (@sesss) {
803        $s->remove if !$s->get('remember');
804    }
805    return '';
806}
807
808sub load_default_templates {
809    require MT::DefaultTemplates;
810    return MT::DefaultTemplates->core_default_templates;
811}
812
813sub load_captcha_providers {
814    return MT->core_captcha_providers;
815}
816
817sub load_core_commenter_auth {
818    return MT->core_commenter_authenticators;
819}
820
821sub load_core_tags {
822    require MT::Template::ContextHandlers;
823    return MT::Template::Context::core_tags();
824}
825
826sub load_upgrade_fns {
827    require MT::Upgrade;
828    return MT::Upgrade->core_upgrade_functions;
829}
830
831sub load_backup_instructions {
832    require MT::BackupRestore;
833    return MT::BackupRestore::core_backup_instructions();
834}
835
836sub l10n_class { 'MT::L10N' }
837
838sub init_registry {
839    my $c = shift;
840    return $c->{registry} = $core_registry;
841}
842
843# Config handlers for these settings...
844
845sub load_archive_types {
846    require MT::WeblogPublisher;
847    return MT::WeblogPublisher->core_archive_types;
848}
849
850sub PerformanceLoggingPath {
851    my $cfg = shift;
852    my ($path, $default);
853    return $cfg->set_internal( 'PerformanceLoggingPath', @_ ) if @_;
854
855    unless ($path = $cfg->get_internal('PerformanceLoggingPath')) {
856        $path = $default = File::Spec->catdir(
857            MT->instance->static_file_path, 'support', 'logs');
858    }
859
860    # If the $path is not a writeable directory, we need to
861    # do some work to see if we can create it
862    if (! (-d $path and -w $path)) {
863        # Determine where MT should put its logging data.  It will be
864        # the first existing and writeable directory found or created
865        # between PerformanceLoggingPath configuration directive value
866        # and the default fallback of MT_DIR/support/logs.  If neither
867        # can be used, we return an undefined value and simply don't
868        # log the performance stats.
869        #
870        # However, we do log any such errors in the activity log to
871        # notify the user that there is a problem.
872
873        my @dirs = ( $path, ( $default && $path ne $default ? ( $default ) : () ) );
874        require File::Spec;   
875        foreach my $dir (@dirs) {
876            my $msg = '';
877            if (-d $dir and -w $dir) {
878                $path = $dir;
879            }
880            elsif (! -e $dir) {
881                require File::Path;
882                eval { File::Path::mkpath([$dir], 0, 0777); $path = $dir; };
883                if ($@) {
884                    $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, $@);
885                }
886            }
887            elsif (-e $dir and ! -d $dir) {
888                $msg = MT->translate('Error creating performance logs: PerformanceLoggingPath setting must be a directory path, not a file: [_1]', $dir);
889            }
890            elsif (-e $dir and ! -w $dir) {
891                    $msg = MT->translate('Error creating performance logs: PerformanceLoggingPath directory exists but is not writeable: [_1]', $dir);                 
892            }
893
894            if ($msg) {
895                # Issue MT log within an eval block in the
896                # event that the plugin error is happening before
897                # the database has been initialized...
898                require MT::Log;
899                MT->log({  message => $msg, 
900                            class => 'system',
901                            level => MT::Log::ERROR() });
902            }
903            last if $path;
904        }
905    }
906    return $path;
907}
908
909sub ProcessMemoryCommand {
910    my $cfg = shift;
911    $cfg->set_internal( 'ProcessMemoryCommand', @_ ) if @_;
912    my $cmd = $cfg->get_internal('ProcessMemoryCommand');
913    unless ($cmd) {
914        my $os = $^O;
915        if ($os eq 'darwin') {
916            $cmd = 'ps $$ -o rss=';
917        }
918        elsif ($os eq 'linux') {
919            $cmd = 'ps -p $$ -o rss=';
920        }
921        elsif ($os eq 'MSWin32') {
922            $cmd = { command => q{tasklist /FI "PID eq $$" /FO TABLE /NH},
923                regex => qr/([\d,]+) K/ };
924        }
925    }
926    return $cmd;
927}
928
929sub SecretToken {
930    my $cfg = shift;
931    $cfg->set_internal( 'SecretToken', @_ ) if @_;
932    my $secret = $cfg->get_internal('SecretToken');
933    unless ($secret) {
934        my @alpha = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 );
935        $secret = join '', map $alpha[ rand @alpha ], 1 .. 40;
936        $secret = $cfg->set_internal( 'SecretToken', $secret, 1 );
937        $cfg->save_config();
938    }
939    return $secret;
940}
941
942sub DefaultUserTagDelimiter {
943    my $mgr = shift;
944    return $mgr->set_internal( 'DefaultUserTagDelimiter', @_ ) if @_;
945    my $delim = $mgr->get_internal('DefaultUserTagDelimiter');
946    if ( lc $delim eq 'comma' ) {
947        return ord(',');
948    }
949    elsif ( lc $delim eq 'space' ) {
950        return ord(' ');
951    }
952    else {
953        return ord(',');
954    }
955}
956
957sub NewUserAutoProvisioning {
958    my $mgr = shift;
959    return $mgr->set_internal( 'NewUserAutoProvisioning', @_ ) if @_;
960    return 0 unless $mgr->DefaultSiteRoot && $mgr->DefaultSiteURL;
961    $mgr->get_internal('NewUserAutoProvisioning');
962}
963
964sub UserSessionCookieName {
965    my $mgr = shift;
966    return $mgr->set_internal( 'UserSessionCookieName', @_ ) if @_;
967    my $name = $mgr->get_internal('UserSessionCookieName');
968    return $name if defined $name;
969    if ($mgr->get_internal('SingleCommunity')) {
970        return 'mt_blog_user';
971    } else {
972        return 'mt_blog%b_user';
973    }
974}
975
976sub UserSessionCookiePath {
977    my $mgr = shift;
978    return $mgr->set_internal( 'UserSessionCookiePath', @_ ) if @_;
979    my $path = $mgr->get_internal('UserSessionCookiePath');
980    return $path if defined $path;
981    if ($mgr->get_internal('SingleCommunity')) {
982        return '/';
983    } else {
984        return '<$MTBlogRelativeURL$>';
985    }
986}
987
9881;
Note: See TracBrowser for help on using the browser.