This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cern:index [2018/05/02 11:45] – iwn | cern:index [2023/10/04 16:10] (current) – iwn | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Include this file in each directory of your website to display plots in a nice and searchable way ([[cern: | + | Include this file in each directory of your website to display plots in a nice and searchable way ([[cern: |
| <file bash index.php> | <file bash index.php> | ||
| + | <?php | ||
| + | preg_match(" | ||
| + | $pwd = preg_replace(" | ||
| + | $pwd = $pwd.preg_replace(" | ||
| + | $pwdshort = preg_replace(" | ||
| + | if(!chdir($pwd)) { // try to go to directory | ||
| + | $msg = "Could not find " | ||
| + | $msg .= "Could not find $pwd..."; | ||
| + | print_r($_SERVER); | ||
| + | echo $msg; throw new Exception($msg); | ||
| + | } | ||
| + | ?> | ||
| < | < | ||
| < | < | ||
| - | < | + | < |
| + | <link rel=" | ||
| <style type=' | <style type=' | ||
| - | body { | + | |
| font-family: | font-family: | ||
| font-size: 9pt; | font-size: 9pt; | ||
| line-height: | line-height: | ||
| - | } | + | |
| - | div.pic h3 { | + | div.pic h3 { |
| - | font-size: | + | font-size: |
| margin: 0.5em 1em 0.2em 1em; | margin: 0.5em 1em 0.2em 1em; | ||
| - | } | + | |
| - | div.pic p { | + | div.pic p { |
| font-size: 11pt; | font-size: 11pt; | ||
| margin: 0.2em 1em 0.1em 1em; | margin: 0.2em 1em 0.1em 1em; | ||
| - | } | + | |
| - | div.pic { | + | div.pic { |
| display: block; | display: block; | ||
| float: left; | float: left; | ||
| Line 27: | Line 40: | ||
| text-align: center; | text-align: center; | ||
| margin: 2px 10px 10px 2px; | margin: 2px 10px 10px 2px; | ||
| - | -moz-box-shadow: | + | -moz-box-shadow: |
| - | -webkit-box-shadow: | + | -webkit-box-shadow: |
| - | box-shadow: | + | box-shadow: |
| width: 320px; | width: 320px; | ||
| - | } | + | min-height: 330px; |
| - | a { text-decoration: | + | max-height: 360px; |
| - | a:hover { text-decoration: | + | |
| - | div.dirlinks h2 { margin-bottom: | + | h1 { color: rgb(40, |
| - | div.dirlinks { margin: 0 24pt; } | + | h2 { padding-top: |
| - | div.dirlinks a { | + | h2 a { color: rgb(20, |
| + | h3 a { color: rgb(40, | ||
| + | | ||
| + | a:hover { text-decoration: | ||
| + | div.dirlinks h2 { padding-top: | ||
| + | div.dirlinks { margin: 0 15pt; } | ||
| + | div.dirlinks a { | ||
| font-size: 11pt; font-weight: | font-size: 11pt; font-weight: | ||
| padding: 0 0.5em; | padding: 0 0.5em; | ||
| - | } | + | } |
| + | pre { | ||
| + | font-family: | ||
| + | max-width: | ||
| + | white-space: | ||
| + | white-space: | ||
| + | white-space: | ||
| + | white-space: | ||
| + | word-wrap: | ||
| + | | ||
| </ | </ | ||
| </ | </ | ||
| < | < | ||
| - | < | + | < |
| + | < | ||
| <?php | <?php | ||
| $has_subs = false; | $has_subs = false; | ||
| - | foreach (glob(" | + | foreach(glob(" |
| - | if (is_dir($filename) && !preg_match("/ | + | if(is_dir($filename) && !preg_match("/ |
| - | $has_subs = true; | + | $has_subs = true; |
| - | break; | + | break; |
| } | } | ||
| } | } | ||
| - | if ($has_subs) { | + | if($has_subs){ |
| print "< | print "< | ||
| print "< | print "< | ||
| print "<a href=\" | print "<a href=\" | ||
| - | foreach (glob(" | + | foreach(glob(" |
| - | if (is_dir($filename) && ($_SERVER[' | + | if(is_dir($filename) && ($_SERVER[' |
| - | print " <a href=\" | + | print " <a href=\" |
| - | } | + | } |
| } | } | ||
| + | print "</ | ||
| + | }else{ | ||
| + | print "< | ||
| + | print "< | ||
| print "</ | print "</ | ||
| } | } | ||
| - | foreach (array(" | + | foreach(array(" |
| - | if (file_exists($readme)) { | + | if(file_exists($readme)){ |
| - | print "< | + | |
| + | $readmeblock = file_get_contents($readme); | ||
| + | # | ||
| + | $readmeblock = preg_replace(" | ||
| + | $readmeblock = preg_replace(" | ||
| + | print "< | ||
| } | } | ||
| } | } | ||
| Line 72: | Line 110: | ||
| < | < | ||
| - | < | + | < |
| <div> | <div> | ||
| <?php | <?php | ||
| + | |||
| + | function matches($filename, | ||
| + | if(isset($_GET[' | ||
| + | foreach($keywords as $keyword){ | ||
| + | if($regex){ | ||
| + | if(!preg_match('/ | ||
| + | return false; | ||
| + | }else{ | ||
| + | if(!fnmatch(' | ||
| + | return false; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | function is_animated($filename) { // check if gif is animated | ||
| + | // https:// | ||
| + | if(!($fh = @fopen($filename,' | ||
| + | return false; | ||
| + | $count = 0; | ||
| + | while(!feof($fh) && $count < 2) { | ||
| + | $chunk = fread($fh, 1024 * 100); //read 100kb at a time | ||
| + | $count += preg_match_all('# | ||
| + | } | ||
| + | fclose($fh); | ||
| + | return $count > 1; | ||
| + | } | ||
| + | |||
| $displayed = array(); | $displayed = array(); | ||
| - | if ($_GET[' | + | if($_GET[' |
| print "Plots will not be displayed.\n"; | print "Plots will not be displayed.\n"; | ||
| - | } else { | + | }else{ |
| - | $other_exts | + | |
| - | $filenames | + | // Get images to be diplayed |
| - | | + | $disp_filenames |
| - | if (isset($_GET[' | + | $png_filenames |
| - | if (isset($_GET[' | + | $keywords = explode(" ",$_GET[' |
| - | if (!preg_match('/.*'.$_GET['match'].'.*/', $filename)) continue; | + | |
| - | } else { | + | foreach(glob(" |
| - | if (!fnmatch(' | + | if(!matches($filename, |
| - | | + | |
| + | $png_filename = preg_replace(" | ||
| + | | ||
| + | if(in_array($png_filename,$png_filenames)) // remove PNG | ||
| + | $png_filenames = array_diff($png_filenames, | ||
| + | }else if(in_array($png_filename, | ||
| + | continue; | ||
| } | } | ||
| + | array_push($disp_filenames, | ||
| + | } | ||
| + | foreach($png_filenames as $filename){ // get PNGs | ||
| + | if(!matches($filename, | ||
| + | array_push($disp_filenames, | ||
| + | } | ||
| + | foreach(glob(" | ||
| + | if(!matches($filename, | ||
| + | $png_filename = preg_replace(" | ||
| + | $gif_filename = preg_replace(" | ||
| + | if(!in_array($png_filename, | ||
| + | | ||
| + | array_push($disp_filenames, | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | // Display, and include other extensions | ||
| + | $other_exts = array(' | ||
| + | natsort($disp_filenames); | ||
| + | foreach($disp_filenames as $filename){ // get PNGs | ||
| array_push($displayed, | array_push($displayed, | ||
| - | $brfname = str_replace(" | + | $brfname = str_replace(" |
| print "< | print "< | ||
| print "< | print "< | ||
| - | print "<a href=\" | + | print "<a href=\" |
| $others = array(); | $others = array(); | ||
| - | foreach ($other_exts as $ex) { | + | foreach($other_exts as $ex){ |
| - | $other_filename = str_replace(' | + | |
| - | if (file_exists($other_filename)) | + | $other_filename = preg_replace(" |
| - | array_push($others, | + | if(strcmp($other_filename, |
| - | if ($ex != ' | + | if(!file_exists($other_filename)) |
| - | } | + | array_push($others, |
| + | if($ex != ' | ||
| } | } | ||
| - | if ($others) print "< | + | if($others) print "< |
| print "</ | print "</ | ||
| } | } | ||
| Line 108: | Line 202: | ||
| ?> | ?> | ||
| </ | </ | ||
| + | |||
| <div style=" | <div style=" | ||
| < | < | ||
| <ul> | <ul> | ||
| - | <? | + | <?php |
| - | foreach (glob(" | + | foreach(glob(" |
| - | if ($_GET[' | + | if($_GET[' |
| - | if (isset($_GET[' | + | if(isset($_GET[' |
| - | | + | if(isset($_GET[' |
| - | if (!preg_match('/ | + | if(!preg_match('/ |
| - | | + | }else{ |
| - | if (!fnmatch(' | + | if(!fnmatch(' |
| - | | + | } |
| } | } | ||
| - | if (is_dir($filename)) { | + | if(is_dir($filename)){ |
| - | print "< | + | print "< |
| - | } else { | + | }else{ |
| - | print "< | + | print "< |
| } | } | ||
| } | } | ||
| Line 131: | Line 226: | ||
| </ul> | </ul> | ||
| </ | </ | ||
| + | <br> | ||
| </ | </ | ||
| </ | </ | ||
| </ | </ | ||