init()) != '') { header('HTTP/1.1 500 Internal Server Error'); echo $err; exit(); } // get image files from directory $ss->get_images(); // set variables, done. list($curr, $caption, $first, $prev, $next, $last) = $ss->run(); /* slideshow class, can be used stand-alone */ class slideshow { private $files_arr = NULL; private $err = NULL; public function __construct(&$err) { $this->files_arr = array(); $this->err = $err; } public function init() { // run actions only if img array session var is empty // check if image directory exists if (!$this->dir_exists()) { return 'Error retrieving images, missing directory'; } return ''; } public function get_images() { // run actions only if img array session var is empty if (isset($_SESSION['imgarr']) && ((time()-$_SESSION["started"])<$lifetime)) { $this->files_arr = $_SESSION['imgarr']; } else { $_SESSION["started"]=time(); $regex = '/^'.CAMERA.'-[0-9]*-snapshot\.(jpg)$/'; $showtime = time()-86400*1.3; if ($dh = opendir(IMGDIR)) { while (false !== ($file = readdir($dh))) { if (filemtime(IMGDIR.'/'.$file)<$showtime) { continue; } if (preg_match($regex, $file)) { $this->files_arr[] = $file; } } closedir($dh); } sort($this->files_arr); $_SESSION['imgarr'] = $this->files_arr; } } public function run() { $last = count($this->files_arr); $curr = $last; if (isset($_GET['img'])) { if (preg_match('/^[0-9]+$/', $_GET['img'])) $curr = (int) $_GET['img']; if ($curr <= 0 || $curr > $last) $curr = 1; } if ($curr <= 1) { $prev = $curr; $next = $curr + 1; } else if ($curr >= $last) { $prev = $last - 1; $next = $last; } else { $prev = $curr - 1; $next = $curr + 1; } // line below sets the caption name... $caption = $this->files_arr[$curr - 1]; $caption = substr($caption,2,4).'/'.substr($caption,6,2).'/'.substr($caption,8,2).' '. substr($caption,10,2).':'.substr($caption,12,2); return array($this->files_arr[$curr - 1], $caption, 1, $prev, $next, $last); } private function dir_exists() { return file_exists(IMGDIR); } }; ?> Веб-камера