Skip to content

Commit

Permalink
Merge pull request #129 from ContentsViewer/pre
Browse files Browse the repository at this point in the history
Pre
  • Loading branch information
ContentsViewer authored Apr 21, 2020
2 parents 67e5d6b + 1b4cbe6 commit 14ec75b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Module/ContentsDatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function RegistMetadata($content){
foreach($content->tags as $tag){
ContentsDatabase::RegistTag($content->path, $tag);

if(strtolower($tag) == 'editing' || $tag == '編集中'){
if(strtolower($tag) == 'editing' || $tag == '編集中' || $tag == 'noindex-latest'){
$shouldAddLatest = false;
}
}
Expand Down
59 changes: 39 additions & 20 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,47 @@
}

// .htaccessの確認
$htaccess = "
<IfModule mod_rewrite.c>
RewriteEngine On
";
$htaccess =
"\n<IfModule mod_rewrite.c>\n" .
"RewriteEngine On\n";

if(REDIRECT_HTTPS_ENABLED){
$htaccess .= "
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
";
}

$htaccess .= "
RewriteCond %{REQUEST_URI} !(^" . CLIENT_URI . "/)
RewriteCond %{REQUEST_URI} !(^" . SERVICE_URI . "/)
RewriteRule ^(.*)$ index.php
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
";
file_put_contents(ROOT_DIR . '/.htaccess', $htaccess);
$htaccess .=
"\nRewriteCond %{HTTPS} off\n" .
"RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]\n";
}

$htaccess .=
"\nRewriteCond %{REQUEST_URI} !(^" . CLIENT_URI . "/)\n" .
"RewriteCond %{REQUEST_URI} !(^" . SERVICE_URI . "/)\n" .
"RewriteRule ^(.*)$ index.php\n" .
"\nRewriteCond %{HTTP:Authorization} ^(.*)\n" .
"RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]\n" .
"</IfModule>\n";

// NOTE fopen オプション w ではなく c にする理由
// wの時は, ファイルポインタをファイルの先頭に置き, ファイルサイズをゼロにします.
// つまり, openしたときにファイルが切り詰められる. ファイルの中身が消される.
// cオプションは, 切り詰められない.
$htaccessFp = fopen(ROOT_DIR . '/.htaccess', 'c+');
if(flock($htaccessFp, LOCK_SH)){
$htaccessFileContents = stream_get_contents($htaccessFp);
flock($htaccessFp, LOCK_UN);
fclose($htaccessFp);

if(preg_match("/(^|\n)# BEGIN CollabCMS *\n(.*)\n# END CollabCMS */s", $htaccessFileContents, $matches, PREG_OFFSET_CAPTURE)){
$htaccessFileContents = substr_replace($htaccessFileContents, $htaccess, $matches[2][1], strlen($matches[2][0]));
file_put_contents(ROOT_DIR . '/.htaccess', $htaccessFileContents, LOCK_EX);
}
else{
file_put_contents(ROOT_DIR . '/.htaccess',
$htaccessFileContents .
"\n# BEGIN CollabCMS\n" .
$htaccess .
"\n# END CollabCMS\n",
LOCK_EX);
}
}

$vars = [];

Expand Down

0 comments on commit 14ec75b

Please sign in to comment.