This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cern:index [2020/05/13 11:29] – 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 | <?php | ||
| - | $pwd = preg_replace(" | + | preg_match(" |
| - | $pwd = preg_replace(" | + | $pwd = preg_replace(" |
| - | chdir($pwd); | + | $pwd = $pwd.preg_replace(" |
| - | $pwdshort = 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); | ||
| + | } | ||
| ?> | ?> | ||
| < | < | ||
| Line 39: | Line 45: | ||
| width: 320px; | width: 320px; | ||
| min-height: 330px; | min-height: 330px; | ||
| - | max-height: | + | max-height: |
| } | } | ||
| h1 { color: rgb(40, | h1 { color: rgb(40, | ||
| Line 107: | Line 113: | ||
| <div> | <div> | ||
| <?php | <?php | ||
| - | $displayed = array(); | ||
| + | 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(); | ||
| 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 |
| - | | + | |
| - | if(isset($_GET[' | + | $png_filenames |
| - | | + | $keywords = explode(" ", |
| - | // | + | $regex = isset($_GET[' |
| - | if(isset($_GET[' | + | foreach(glob(" |
| - | if(!preg_match('/.*'.$_GET['match'].'.*/', $filename)) continue; | + | if(!matches($filename, |
| - | }else{ | + | |
| - | if(!fnmatch(' | + | $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 "< | ||