| 234 | | require MT::Template; |
| 235 | | $param->{dynamic_enabled} = MT::Template->exist( { blog_id => $obj->id, build_dynamic => 1 }); |
| | 234 | require MT::PublishOption; |
| | 235 | if ( $app->model('template')->exist( |
| | 236 | { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) |
| | 237 | || $app->model('templatemap')->exist( |
| | 238 | { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) ) |
| | 239 | { |
| | 240 | $param->{dynamic_enabled} = 1; |
| | 241 | } |
| 1006 | | my $order = join ',', @at, 'index'; |
| 1007 | | my $entry_pkg = $app->model('entry'); |
| | 1016 | $param->{archive_type_loop} = \@data; |
| | 1017 | $param->{build_order} = join ',', @at, 'index'; |
| | 1018 | 1; |
| | 1019 | } |
| | 1020 | |
| | 1021 | sub rebuild_confirm { |
| | 1022 | my $app = shift; |
| | 1023 | my $blog_id = $app->param('blog_id'); |
| | 1024 | require MT::Blog; |
| | 1025 | my $blog = MT::Blog->load($blog_id) |
| | 1026 | or return $app->error($app->translate('Can\'t load blog #[_1].', $blog_id)); |
| | 1027 | |
| | 1859 | require MT::PublishOption; |
| | 1860 | if ( ( $blog->custom_dynamic_templates eq 'all' |
| | 1861 | || $blog->custom_dynamic_templates eq 'archives' ) |
| | 1862 | && ( $app->model('template')->exist( |
| | 1863 | { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) |
| | 1864 | || $app->model('templatemap')->exist( |
| | 1865 | { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) ) ) |
| | 1866 | { |
| | 1867 | # dynamic enabled and caching option may have changed - update mtview |
| | 1868 | my $cache = $app->param('dynamic_cache') ? 1 : 0; |
| | 1869 | my $conditional = $app->param('dynamic_conditional') ? 1 : 0; |
| | 1870 | _create_mtview( $blog, $blog->site_path, $cache, $conditional ); |
| | 1871 | _create_dynamiccache_dir( $blog, $blog->site_path ) if $cache; |
| | 1872 | if ( $blog->archive_path ) { |
| | 1873 | _create_mtview( $blog, $blog->archive_path, $cache, $conditional ); |
| | 1874 | _create_dynamiccache_dir( $blog, $blog->archive_path ) if $cache; |
| | 1875 | } |
| | 1876 | } |
| 1985 | | require MT::Template; |
| 1986 | | my $dynamic_enabled = MT::Template->exist( { blog_id => $blog->id, |
| 1987 | | build_dynamic => 1 }); |
| 1988 | | |
| 1989 | | # dynamic publishing enabled |
| 1990 | | if ( $dynamic_enabled ) { |
| | 2024 | require MT::PublishOption; |
| | 2025 | if ( $app->model('template')->exist( |
| | 2026 | { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) |
| | 2027 | || $app->model('templatemap')->exist( |
| | 2028 | { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) ) |
| | 2029 | { |
| | 2030 | # dynamic publishing enabled |
| | 2058 | } |
| | 2059 | } |
| | 2060 | |
| | 2061 | sub _create_mtview { |
| | 2062 | my ( $blog, $site_path, $cache, $conditional ) = @_; |
| | 2063 | |
| | 2064 | my $mtview_path = File::Spec->catfile( $site_path, "mtview.php" ); |
| | 2065 | eval { |
| | 2066 | my $mv_contents = ''; |
| | 2067 | if ( -f $mtview_path ) { |
| | 2068 | open( my $mv, "<$mtview_path" ); |
| | 2069 | while ( my $line = <$mv> ) { |
| | 2070 | $mv_contents .= $line if ( $line !~ m!^//|<\?(?:php)?|\?>! ); |
| | 2071 | } |
| | 2072 | close $mv; |
| | 2073 | } |
| | 2074 | my $cgi_path = MT->instance->server_path() || ""; |
| | 2075 | $cgi_path =~ s!/*$!!; |
| | 2076 | my $mtphp_path = File::Spec->canonpath("$cgi_path/php/mt.php"); |
| | 2077 | my $blog_id = $blog->id; |
| | 2078 | my $config = MT->instance->{cfg_file}; |
| | 2079 | my $cache_code = $cache ? "\n \$mt->caching = true;" : ''; |
| | 2080 | my $conditional_code = |
| | 2081 | $conditional ? "\n \$mt->conditional = true;" : ''; |
| | 2082 | my $new_mtview = <<NEW_MTVIEW; |
| | 2083 | |
| | 2084 | include('$mtphp_path'); |
| | 2085 | \$mt = new MT($blog_id, '$config');$cache_code$conditional_code |
| | 2086 | \$mt->view(); |
| | 2087 | NEW_MTVIEW |
| | 2088 | |
| | 2089 | if ( $new_mtview ne substr( $mv_contents, 0, length($new_mtview) ) ) { |
| | 2090 | $mv_contents =~ s!\n!\n//!gs; |
| | 2091 | my $mtview = <<MTVIEW; |
| | 2092 | <?php |
| | 2093 | $new_mtview |
| | 2094 | $mv_contents |
| | 2095 | ?> |
| | 2096 | MTVIEW |
| | 2097 | |
| | 2098 | $blog->file_mgr->mkpath( $site_path ); |
| | 2099 | open( my $mv, ">$mtview_path" ) |
| | 2100 | || die "Couldn't open $mtview_path for appending"; |
| | 2101 | print $mv $mtview || die "Couldn't write to $mtview_path"; |
| | 2102 | close $mv; |
| | 2103 | } |
| | 2104 | }; |
| | 2105 | if ($@) { print STDERR $@; } |
| | 2106 | } |
| | 2107 | |
| | 2108 | sub _create_dynamiccache_dir { |
| | 2109 | my ( $blog, $site_path ) = @_; |
| | 2110 | |
| | 2111 | # FIXME: use FileMgr |
| | 2112 | my $cache_path = File::Spec->catfile( $site_path, 'cache' ); |
| | 2113 | my $fmgr = $blog->file_mgr; |
| | 2114 | my $saved_umask = MT->config->DirUmask; |
| | 2115 | MT->config->DirUmask('0000'); |
| | 2116 | $fmgr->mkpath($cache_path); |
| | 2117 | MT->config->DirUmask($saved_umask); |
| | 2118 | my $message; |
| | 2119 | if ( -d $cache_path ) { |
| | 2120 | $message = MT->translate( |
| | 2121 | 'ErrMovable Type cannot write to the template cache directory. Please check the permissions for the directory called <code>[_1]</code> underneath your blog directory.', |
| | 2122 | 'cache' |
| | 2123 | ) unless ( -w $cache_path ); |
| | 2124 | } |
| | 2125 | else { |
| | 2126 | $message = MT->translate( |
| | 2127 | 'ErrMovable Type was not able to create a directory to cache your dynamic templates. You should create a directory called <code>[_1]</code> underneath your blog directory.', |
| | 2128 | 'cache' |
| | 2129 | ) unless ( -d $cache_path ); |
| | 2130 | } |
| | 2131 | if ( $message ) { |
| | 2132 | MT->log( |
| | 2133 | { |
| | 2134 | message => $message, |
| | 2135 | level => MT::Log::ERROR(), |
| | 2136 | class => 'system', |
| | 2137 | } |
| | 2138 | ); |
| 2109 | | eval { |
| 2110 | | my $mv_contents = ''; |
| 2111 | | if ( -f $mtview_path ) { |
| 2112 | | open( my $mv, "<$mtview_path" ); |
| 2113 | | while ( my $line = <$mv> ) { |
| 2114 | | $mv_contents .= $line if ( $line !~ m!^//|<\?(?:php)?|\?>! ); |
| 2115 | | } |
| 2116 | | close $mv; |
| 2117 | | } |
| 2118 | | my $cgi_path = MT->instance->server_path() || ""; |
| 2119 | | $cgi_path =~ s!/*$!!; |
| 2120 | | my $mtphp_path = File::Spec->canonpath("$cgi_path/php/mt.php"); |
| 2121 | | my $blog_id = $blog->id; |
| 2122 | | my $config = MT->instance->{cfg_file}; |
| 2123 | | my $cache_code = $cache ? "\n \$mt->caching = true;" : ''; |
| 2124 | | my $conditional_code = |
| 2125 | | $conditional ? "\n \$mt->conditional = true;" : ''; |
| 2126 | | my $new_mtview = <<NEW_MTVIEW; |
| 2127 | | |
| 2128 | | include('$mtphp_path'); |
| 2129 | | \$mt = new MT($blog_id, '$config');$cache_code$conditional_code |
| 2130 | | \$mt->view(); |
| 2131 | | NEW_MTVIEW |
| 2132 | | |
| 2133 | | if ( $new_mtview ne substr( $mv_contents, 0, length($new_mtview) ) ) { |
| 2134 | | $mv_contents =~ s!\n!\n//!gs; |
| 2135 | | my $mtview = <<MTVIEW; |
| 2136 | | <?php |
| 2137 | | $new_mtview |
| 2138 | | $mv_contents |
| 2139 | | ?> |
| 2140 | | MTVIEW |
| 2141 | | |
| 2142 | | $blog->file_mgr->mkpath( $site_path ); |
| 2143 | | open( my $mv, ">$mtview_path" ) |
| 2144 | | || die "Couldn't open $mtview_path for appending"; |
| 2145 | | print $mv $mtview || die "Couldn't write to $mtview_path"; |
| 2146 | | close $mv; |
| 2147 | | } |
| 2148 | | }; |
| 2149 | | if ($@) { print STDERR $@; } |
| | 2232 | _create_mtview( $blog, $site_path, $cache, $conditional ); |
| 2176 | | my $cache_path = File::Spec->catfile( $blog->site_path(), 'cache' ); |
| 2177 | | $cfg->DirUmask('0000'); |
| 2178 | | $fmgr->mkpath($cache_path); |
| 2179 | | $cfg->DirUmask($saved_umask); |
| 2180 | | if ( -d $cache_path ) { |
| 2181 | | $message = MT->translate( |
| 2182 | | 'Error: Movable Type cannot write to the template cache directory. Please check the permissions for the directory called <code>[_1]</code> underneath your blog directory.', |
| 2183 | | 'cache' |
| 2184 | | ) unless ( -w $cache_path ); |
| 2185 | | } |
| 2186 | | else { |
| 2187 | | $message = MT->translate( |
| 2188 | | 'Error: Movable Type was not able to create a directory to cache your dynamic templates. You should create a directory called <code>[_1]</code> underneath your blog directory.', |
| 2189 | | 'cache' |
| 2190 | | ) unless ( -d $cache_path ); |
| 2191 | | } |
| 2192 | | } |
| 2193 | | MT->log( |
| 2194 | | { |
| 2195 | | message => $message, |
| 2196 | | level => MT::Log::ERROR(), |
| 2197 | | class => 'system', |
| 2198 | | } |
| 2199 | | ); |
| | 2258 | _create_dynamiccache_dir( $blog, $site_path ); |
| | 2259 | } |