Skip to content

Commit 14ec75b

Browse files
Merge pull request #129 from ContentsViewer/pre
Pre
2 parents 67e5d6b + 1b4cbe6 commit 14ec75b

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

Module/ContentsDatabaseManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function RegistMetadata($content){
7373
foreach($content->tags as $tag){
7474
ContentsDatabase::RegistTag($content->path, $tag);
7575

76-
if(strtolower($tag) == 'editing' || $tag == '編集中'){
76+
if(strtolower($tag) == 'editing' || $tag == '編集中' || $tag == 'noindex-latest'){
7777
$shouldAddLatest = false;
7878
}
7979
}

index.php

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,47 @@
1919
}
2020

2121
// .htaccessの確認
22-
$htaccess = "
23-
<IfModule mod_rewrite.c>
24-
RewriteEngine On
25-
";
22+
$htaccess =
23+
"\n<IfModule mod_rewrite.c>\n" .
24+
"RewriteEngine On\n";
2625

2726
if(REDIRECT_HTTPS_ENABLED){
28-
$htaccess .= "
29-
RewriteCond %{HTTPS} off
30-
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
31-
";
32-
}
33-
34-
$htaccess .= "
35-
RewriteCond %{REQUEST_URI} !(^" . CLIENT_URI . "/)
36-
RewriteCond %{REQUEST_URI} !(^" . SERVICE_URI . "/)
37-
RewriteRule ^(.*)$ index.php
38-
39-
RewriteCond %{HTTP:Authorization} ^(.*)
40-
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
41-
</IfModule>
42-
";
43-
file_put_contents(ROOT_DIR . '/.htaccess', $htaccess);
27+
$htaccess .=
28+
"\nRewriteCond %{HTTPS} off\n" .
29+
"RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]\n";
30+
}
31+
32+
$htaccess .=
33+
"\nRewriteCond %{REQUEST_URI} !(^" . CLIENT_URI . "/)\n" .
34+
"RewriteCond %{REQUEST_URI} !(^" . SERVICE_URI . "/)\n" .
35+
"RewriteRule ^(.*)$ index.php\n" .
36+
"\nRewriteCond %{HTTP:Authorization} ^(.*)\n" .
37+
"RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]\n" .
38+
"</IfModule>\n";
39+
40+
// NOTE fopen オプション w ではなく c にする理由
41+
// wの時は, ファイルポインタをファイルの先頭に置き, ファイルサイズをゼロにします.
42+
// つまり, openしたときにファイルが切り詰められる. ファイルの中身が消される.
43+
// cオプションは, 切り詰められない.
44+
$htaccessFp = fopen(ROOT_DIR . '/.htaccess', 'c+');
45+
if(flock($htaccessFp, LOCK_SH)){
46+
$htaccessFileContents = stream_get_contents($htaccessFp);
47+
flock($htaccessFp, LOCK_UN);
48+
fclose($htaccessFp);
49+
50+
if(preg_match("/(^|\n)# BEGIN CollabCMS *\n(.*)\n# END CollabCMS */s", $htaccessFileContents, $matches, PREG_OFFSET_CAPTURE)){
51+
$htaccessFileContents = substr_replace($htaccessFileContents, $htaccess, $matches[2][1], strlen($matches[2][0]));
52+
file_put_contents(ROOT_DIR . '/.htaccess', $htaccessFileContents, LOCK_EX);
53+
}
54+
else{
55+
file_put_contents(ROOT_DIR . '/.htaccess',
56+
$htaccessFileContents .
57+
"\n# BEGIN CollabCMS\n" .
58+
$htaccess .
59+
"\n# END CollabCMS\n",
60+
LOCK_EX);
61+
}
62+
}
4463

4564
$vars = [];
4665

0 commit comments

Comments
 (0)