コード例 #1
0
function report($d)
{
    global $CFG;
    $dirroot = stack_utils::convert_slash_paths($CFG->dirroot . '/question/type/stack/doc/en');
    $wwwroot = $CFG->wwwroot;
    $webdocs = $wwwroot . '/question/type/stack/doc/en';
    $weburl = $wwwroot . '/question/type/stack/doc/doc.php';
    $a = array();
    $fileslinkedto = array();
    if (is_dir($d)) {
        if ($dh = opendir($d)) {
            while (($f = readdir($dh)) !== false) {
                if (substr($f, 0, 1) != '.') {
                    $fpath = "{$d}/{$f}";
                    if (filetype($fpath) == 'dir') {
                        $a = array_merge($a, report($fpath));
                    } else {
                        $fname = pathinfo($fpath, PATHINFO_FILENAME);
                        $fext = pathinfo($fpath, PATHINFO_EXTENSION);
                        $fsize = filesize($fpath);
                        $reldir = str_replace($dirroot, '', $d);
                        $a[] = array($fpath, 'F', 'Found file ' . "{$fpath}");
                        if ($fsize >= 18000) {
                            $a[] = array($fpath, 'W', "Large file ({$fsize} bytes)");
                        }
                        if ($fext != 'bak') {
                            if ($fext != 'md') {
                                $a[] = array($fpath, 'W', "Not a markdown file ({$fext})");
                            }
                            // Let's do some link checking, step one: scrape the links off the document's web page.
                            $links = stack_process_markdown(file_get_contents($fpath), "");
                            preg_match_all("/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^<]*)<\\/a>/is", $links, $found);
                            // The array $found[0] will have the full a tags, found[1] contains their href properties.
                            // Step two, visit these links and check for 404s.
                            foreach ($found[1] as $i => $link) {
                                if (strpos($link, 'mailto:') !== 0 and strpos($link, 'maintenance.php') === false and strpos($link, 'http') !== 0) {
                                    // Don't check mailto:, this file (ARGH!)
                                    // Also if ?ext not true then better not be an external link.
                                    if (strpos($link, 'http') !== 0) {
                                        // If a local link, do some preparation.
                                        if (strpos($link, '/') === 0) {
                                            $link = $webdocs . $link;
                                            // Not a relative link.
                                        } else {
                                            $link = $webdocs . rtrim($reldir, '/') . '/' . $link;
                                        }
                                        // It looks like get_headers isn't evaluating these so lets do it manually.
                                        $segs = explode('/', $link);
                                        while (($pos = array_search('.', $segs)) !== false) {
                                            unset($segs[$pos]);
                                        }
                                        while (($pos = array_search('..', $segs)) !== false) {
                                            unset($segs[$pos], $segs[$pos - 1]);
                                        }
                                        $link = implode('/', $segs);
                                        // Finally it looks like #--- are getting parsed in the request, let's omit them.
                                        if (strpos($link, '#') !== false) {
                                            $link = substr($link, 0, strpos($link, '#'));
                                        }
                                    }
                                    $hs = get_headers($link);
                                    if (strpos($hs[0], '404') !== false) {
                                        $a[] = array($fpath, 'E', 'Error 404 [' . $found[0][$i] . '] appears to be a dead link');
                                    } else {
                                        $fileslinkedto[$found[0][$i]] = true;
                                    }
                                    if ('/' == substr($link, -1)) {
                                        $a[] = array($fpath, 'E', 'Link [' . $found[0][$i] . '] calls a directory.  This should have explicit <tt>index.md</tt> but does not.');
                                    }
                                }
                            }
                        }
                    }
                }
            }
            closedir($dh);
        }
    }
    return $a;
}
コード例 #2
0
 public static function stackmaxima_auto_maxima_optimise($genuinedebug)
 {
     global $CFG;
     self::ensure_config_loaded();
     $imagename = stack_utils::convert_slash_paths($CFG->dataroot . '/stack/maxima_opt_auto');
     $lisp = '1';
     // Try to guess the lisp version.
     if (!(false === strpos($genuinedebug, 'GNU Common Lisp (GCL)'))) {
         $lisp = 'GCL';
     }
     if (!(false === strpos($genuinedebug, 'Lisp SBCL'))) {
         $lisp = 'SBCL';
     }
     if (!(false === strpos($genuinedebug, 'Lisp CLISP'))) {
         $lisp = 'CLISP';
     }
     switch ($lisp) {
         case 'GCL':
             $maximacommand = ':lisp (si::save-system "' . $imagename . '")' . "\n";
             $maximacommand .= 'quit();' . "\n";
             $commandline = stack_utils::convert_slash_paths($imagename . ' -eval \'(cl-user::run)\'');
             break;
         case 'SBCL':
             $maximacommand = ':lisp (sb-ext:save-lisp-and-die "' . $imagename . '" :toplevel #\'run :executable t)' . "\n";
             $commandline = stack_utils::convert_slash_paths($imagename);
             break;
         case 'CLISP':
             $imagename .= '.mem';
             $maximacommand = ':lisp (ext:saveinitmem "' . $imagename . '" :init-function #\'user::run)' . "\n";
             $maximacommand .= 'quit();' . "\n";
             $lisprun = shell_exec('locate lisp.run');
             if (trim($lisprun) == '') {
                 $success = false;
                 $message = stack_string('healthautomaxopt_nolisprun');
                 return array($message, '', $success);
             }
             $lisprun = explode("\n", $lisprun);
             $commandline = $lisprun[0] . ' -q -M ' . stack_utils::convert_slash_paths($imagename);
             break;
         default:
             $success = false;
             $message = stack_string('healthautomaxopt_nolisp');
             return array($message, '', $success);
     }
     // Really make sure there is no cache.
     list($results, $debug) = self::stackmaxima_nocache_call($maximacommand);
     // Question: should we at this stage try to use the optimised image we have created?
     $success = true;
     // Add the timeout command to the message.
     $commandline = 'timeout --kill-after=10s 10s ' . $commandline;
     $message = stack_string('healthautomaxopt_ok', array('command' => $commandline));
     if (!file_exists($imagename)) {
         $success = false;
         $message = stack_string('healthautomaxopt_notok');
     }
     return array($message, $debug, $success);
 }
コード例 #3
0
 /**
  * Get the full path to the folder where plot files are stored.
  * @return string the full path to where the maximalocal.mac file should be stored.
  */
 public static function images_location()
 {
     global $CFG;
     return stack_utils::convert_slash_paths($CFG->dataroot . '/stack/plots');
 }