Fixes the display of our favicon.
[platal.git] / modules / core.php
index 8792c62..9493be9 100644 (file)
@@ -30,6 +30,7 @@ class CoreModule extends PLModule
             'send_bug'    => $this->make_hook('bug', AUTH_COOKIE),
             'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin'),
             'kill_sessions' => $this->make_hook('kill_sessions', AUTH_COOKIE, 'admin'),
+            'sql_errors'  => $this->make_hook('sqlerror', AUTH_COOKIE, 'admin'),
             'get_rights'  => $this->make_hook('get_rights', AUTH_MDP, 'admin'),
 
             'wiki_help'    => $this->make_hook('wiki_help', AUTH_PUBLIC),
@@ -74,7 +75,8 @@ class CoreModule extends PLModule
 
     function handler_favicon(&$page)
     {
-        $data = file_get_contents(dirname(__FILE__).'/../htdocs/images/favicon.ico');
+        global $globals;
+        $data = file_get_contents($globals->spoolroot . '/htdocs/images/favicon.ico');
         header('Content-Type: image/x-icon');
         echo $data;
         exit;
@@ -83,14 +85,25 @@ class CoreModule extends PLModule
     function handler_robotstxt(&$page)
     {
         global $globals;
-        if (!$globals->core->restricted_platal) {
-            return PL_NOT_FOUND;
+
+        $disallowed_uris = array();
+        if ($globals->core->restricted_platal) {
+            $disallowed_uris[] = '/';
+        } else if (!empty($globals->core->robotstxt_disallowed_uris)) {
+            $disallowed_uris = preg_split('/[\s,]+/',
+                                          $globals->core->robotstxt_disallowed_uris,
+                                          -1, PREG_SPLIT_NO_EMPTY);
         }
 
-        header('Content-Type: text/plain');
-        echo "User-agent: *\n";
-        echo "Disallow: /\n";
-        exit;
+        if (count($disallowed_uris) > 0) {
+            header('Content-Type: text/plain');
+            echo "User-agent: *\n";
+            foreach ($disallowed_uris as $uri) {
+                echo "Disallow: $uri\n";
+            }
+            exit;
+        }
+        return PL_NOT_FOUND;
     }
 
     function handler_purge_cache(&$page)
@@ -191,6 +204,21 @@ class CoreModule extends PLModule
         echo MiniWiki::wikiToHtml($text, $action == 'title');
         exit;
     }
+
+    function handler_sqlerror(&$page, $clear = null) {
+        global $globals;
+        $file = @fopen($globals->spoolroot . '/spool/tmp/query_errors', 'r');
+        if ($file !== false) {
+            echo '<html><body>';
+            fpassthru($file);
+            fclose($file);
+            echo '</html></body>';
+        }
+        if ($clear == 'clear') {
+            @unlink($globals->spoolroot . '/spool/tmp/query_errors');
+        }
+        exit;
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: