This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
cern:index [2020/09/18 18:03] – iwn | cern:index [2023/09/28 16:18] – iwn | ||
---|---|---|---|
Line 3: | Line 3: | ||
<file bash index.php> | <file bash index.php> | ||
<?php | <?php | ||
- | $pwd = preg_replace(" | + | <?php |
- | $pwd = preg_replace(" | + | preg_match(" |
- | preg_match(" | + | $pwd = preg_replace(" |
- | $pwdshort = preg_replace(" | + | $pwd = $pwd.preg_replace(" |
- | chdir($pwd); | + | $pwdshort = preg_replace(" |
+ | if(!chdir($pwd)) { // try to go to directory | ||
+ | $msg = "Could not find " | ||
+ | echo $msg; throw new Exception($msg); | ||
+ | } | ||
?> | ?> | ||
< | < | ||
Line 40: | Line 44: | ||
width: 320px; | width: 320px; | ||
min-height: 330px; | min-height: 330px; | ||
- | max-height: | + | max-height: |
} | } | ||
h1 { color: rgb(40, | h1 { color: rgb(40, | ||
Line 108: | Line 112: | ||
<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 |
+ | | ||
+ | $png_filenames | ||
$keywords = explode(" | $keywords = explode(" | ||
- | | + | $regex = isset($_GET[' |
- | if(isset($_GET[' | + | foreach(glob(" |
- | | + | if(!matches($filename,$keywords, |
- | foreach($keywords | + | // |
- | if(isset($_GET[' | + | $png_filename = preg_replace(" |
- | | + | |
- | $matched = False; | + | if(in_array($png_filename,$png_filenames)) // remove PNG |
- | continue; | + | $png_filenames |
- | } | + | }else if(in_array($png_filename, |
- | }else{ | + | |
- | if(!fnmatch(' | + | |
- | $matched | + | |
- | | + | |
- | | + | |
- | } | + | |
- | } | + | |
- | | + | |
} | } | ||
+ | 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 "< |