diff --git a/plugin/nosearchindex/README.md b/plugin/nosearchindex/README.md new file mode 100644 index 0000000000..511132194a --- /dev/null +++ b/plugin/nosearchindex/README.md @@ -0,0 +1,4 @@ +No search index +=== + +This plugin allows administrators to hide the portal from search engines using the robots.txt file and adding a meta tag "noindex". \ No newline at end of file diff --git a/plugin/nosearchindex/index.php b/plugin/nosearchindex/index.php new file mode 100644 index 0000000000..b3d9bbc7f3 --- /dev/null +++ b/plugin/nosearchindex/index.php @@ -0,0 +1 @@ +get_info(); + +$isPlatformAdmin = api_is_platform_admin(); +$editFile = false; + +$file = api_get_path(SYS_PATH).'robots.txt'; + +if ($isPlatformAdmin) { + $originalFile = api_get_path(SYS_PATH).'robots.dist.txt'; + if (!file_exists($originalFile)) { + copy($file, $originalFile); + } + + $originalContent = file_get_contents($originalFile); + + $form = $plugin_info['settings_form']; + + if ($form->validate()) { + $values = $form->getSubmitValues(); + $contents = file_get_contents($originalFile); + $extraContentFile = api_get_home_path().'header_extra_content.txt'; + $noFollow = ''; + + if (isset($values['tool_enable']) && $values['tool_enable'] == 'true') { + file_put_contents($file, $contents."\nDisallow: /\n"); + $value = ''; + if (file_exists($extraContentFile)) { + $backup = file_get_contents($extraContentFile); + file_put_contents($extraContentFile, $backup.$noFollow); + } else { + $value = file_put_contents($extraContentFile, $noFollow); + } + } else { + file_put_contents($file, $contents); + + if (file_exists($extraContentFile)) { + $backup = file_get_contents($extraContentFile); + $backup = str_replace($noFollow, '', $backup); + file_put_contents($extraContentFile, $backup); + } + } + } + $plugin_info['settings_form'] = $form; +} +