<% define('ROOT',$_SERVER['DOCUMENT_ROOT']); define('FRAGMENTS_ROOT',str_replace('htdocs','fragments',ROOT)); define('ALBUMS_ROOT',ROOT.'/albums'); umask(0002); $admin = ($_SERVER['HTTP_HOST']=='admin-dorian.apteryx.fr'); $pi=$_SERVER['PATH_INFO']; $user = array_key_exists('REMOTE_USER',$_SERVER) ? $_SERVER['REMOTE_USER'] : FALSE; if ($user) { $link = mysql_connect("localhost", "dorian", "dorian"); mysql_select_db('dorian'); $query = "SELECT * FROM dorian.user_info WHERE USER_NAME='$user'"; $profile = mysql_fetch_assoc(mysql_query($query, $link)); $profile['allow_publish'] = $user=='dorian'; $profile['super_admin'] = $user=='dorian'; mysql_close(); } function filemdate($f) { return date('d/m/Y H:i:s',filemtime($f)); } function versions($f) { $files = glob("$f,*"); $mtimes = array_map("filemdate",$files); $versions = preg_replace("/.*\//", "", $files); return array_combine($versions,$mtimes); } function latest($f) { $lastver = array_pop(glob("$f,*")); if ($lastver=="") $lastver=$f; return $lastver; } function newver($file) { $f = preg_replace('#,[^/]*$#','',$file); $lastver = str_replace("$f,",'',@array_pop(glob("$f,*"))); return sprintf('%06d.%s',1+intval($lastver),$user); } function finclude($f) { if (file_exists($f)) return @readfile($f); else return @readfile(latest($f)); } function insertEditableFragment($id,$className,$f) { global $admin; if ($admin) echo "
"; finclude($f); if ($admin) echo '
'; } // function fwrite_if_newer($dest_filename, $content, $make_link) // Compute new revision number and derive filename to create. // File is created only if content differs from last revision. // If no older revision exists and content is empty, skip it. function fwrite_if_newer($f,$s,$ln=FALSE) { global $user; $lastver = str_replace("$f,",'',@array_pop(glob("$f,*"))); $newver = sprintf('%06d.%s',1+intval($lastver),$user); $fl = "$f,$lastver"; if (!strlen($s) && (!file_exists($fl)||!filesize($fl))) return FALSE; if (file_exists($fl) && strlen($s)===filesize($fl)) { $s2 = file_get_contents($fl); if ($s==$s2) return FALSE; } // TODO : make this a real recursive path check, and add proper error reporting as we may encounter an existing *file* (not a *dir*)... if (!is_dir(dirname($f))) mkdir(dirname($f), 0775, TRUE); file_put_contents($fn="$f,$newver", $s); if ($ln) { @unlink($f); symlink(realpath($fn),$f); } return $newver; } %> <% $admin_mode = $admin; include(ROOT.'/includes/head.html'); %>