Hide url blogs from selection field in the rcc

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-12-30 00:05:01 +01:00
parent 623395064f
commit 00d3149360
2 changed files with 42 additions and 10 deletions

View file

@ -124,10 +124,12 @@ if ($config["rcc"]["rcc"] == "on") {
$blogs = scandir("../blogs/"); $blogs = scandir("../blogs/");
foreach ($blogs as $blog) { foreach ($blogs as $blog) {
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") { if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
if (BlogListGenerator::getExternalLink($blog, '../') == null) {
$blog = substr($blog, 0, -3); $blog = substr($blog, 0, -3);
echo "<option value='$blog'>$blog</option>"; echo "<option value='$blog'>$blog</option>";
} }
} }
}
?> ?>
</select> </select>
@ -149,10 +151,12 @@ if ($config["rcc"]["rcc"] == "on") {
$blogs = scandir("../blogs/"); $blogs = scandir("../blogs/");
foreach ($blogs as $blog) { foreach ($blogs as $blog) {
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") { if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
if (BlogListGenerator::getExternalLink($blog, '../') == null) {
$blog = substr($blog, 0, -3); $blog = substr($blog, 0, -3);
echo "<option value='$blog'>$blog</option>"; echo "<option value='$blog'>$blog</option>";
} }
} }
}
?> ?>
</select> </select>
@ -197,10 +201,12 @@ if ($config["rcc"]["rcc"] == "on") {
$blogs = scandir("../blogs/"); $blogs = scandir("../blogs/");
foreach ($blogs as $blog) { foreach ($blogs as $blog) {
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") { if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
if (BlogListGenerator::getExternalLink($blog, '../') == null) {
$blog = substr($blog, 0, -3); $blog = substr($blog, 0, -3);
echo "<option value='$blog'>$blog</option>"; echo "<option value='$blog'>$blog</option>";
} }
} }
}
?> ?>
</select> </select>
</p> </p>
@ -220,10 +226,12 @@ if ($config["rcc"]["rcc"] == "on") {
$blogs = scandir("../blogs/"); $blogs = scandir("../blogs/");
foreach ($blogs as $blog) { foreach ($blogs as $blog) {
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") { if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
if (BlogListGenerator::getExternalLink($blog, '../') == null) {
$blog = substr($blog, 0, -3); $blog = substr($blog, 0, -3);
echo "<option value='$blog'>$blog</option>"; echo "<option value='$blog'>$blog</option>";
} }
} }
}
?> ?>
</select> </select>
</p> </p>
@ -251,10 +259,12 @@ if ($config["rcc"]["rcc"] == "on") {
$blogs = scandir("../blogs/"); $blogs = scandir("../blogs/");
foreach ($blogs as $blog) { foreach ($blogs as $blog) {
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") { if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
if (BlogListGenerator::getExternalLink($blog, '../') == null) {
$blog = substr($blog, 0, -3); $blog = substr($blog, 0, -3);
echo "<option value='$blog'>$blog</option>"; echo "<option value='$blog'>$blog</option>";
} }
} }
}
?> ?>
</select> </select>
</p> </p>

View file

@ -112,4 +112,26 @@ class BlogListGenerator
return $i; return $i;
} }
} }
/**
* A function returning the external linkn of
* a blog.
*
* @param string $blog the blog name
* @param string $dir root directory of installation
*
* @return string link to external page else null
*/
public function getExternalLink($blog, $dir)
{
$path = $dir . "/blogs/" . $blog;
$blog = file_get_contents($path) . "\n";
if (substr($blog, 0, 6) == "%TITLE") {
$blog = substr($blog, strpos($blog, "\n") + 1);
}
if (substr($blog, 0, 4) == "%URL") {
return substr($blog, 6, strpos($blog, "\n") - 6);
}
return null;
}
} }