= " . str2pgts( "\$1" ); $values = array( 1 => pgtime2str( $time ) ); $ress = pg_query_params( $conn, $sql, $values ); if( !$ress ) { return; } echo "tags\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); while( $row ) { $id = $row["ft_id"]; $kind = $row["ft_kind"]; $name = list_escape( $row["ft_name"] ); $descr = list_escape( $row["ft_descr"] ); $timestamp = pgstr2time( $row["ft_timestamp"] ); echo "|" . $id . "|" . $kind . "|" . $name . "|" . $descr . "|" . $timestamp . "|\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); } } function send_fotos( $conn, $time ) { $sql = "select " . "ff_id, ff_state, ff_public, ff_filename, ff_hash, " . "ff_camera, ff_orig_name, ff_timv_width, ff_timv_height, " . "ff_timv_mtime, ff_timv_angle, ff_timv_flip, " . pgts2str( "ff_exif_date" ) . ", " . "ff_date_offset, " . pgts2str( "ff_real_date" ) . ", " . pgts2str( "ff_disp_date" ) . ", " . " ff_comment, " . pgts2str( "ff_timestamp" ) . " " . "from " . "fotolib_foto " . "where " . "ff_timestamp >= " . str2pgts( "\$1" ); $values = array( 1 => pgtime2str( $time ) ); $ress = pg_query_params( $conn, $sql, $values ); if( !$ress ) { return; } echo "fotos\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); while( $row ) { $id = $row["ff_id"]; $state = $row["ff_state"]; $public = $row["ff_public"]; $filename = $row["ff_filename"]; $hash = $row["ff_hash"]; $camera = $row["ff_camera"]; $orig_name = $row["ff_orig_name"]; $timv_width = $row["ff_timv_width"]; $timv_height = $row["ff_timv_height"]; $timv_mtime = $row["ff_timv_mtime"]; $timv_angle = $row["ff_timv_angle"]; $timv_flip = $row["ff_timv_flip"]; $exif_date = pgstr2time( $row["ff_exif_date"] ); $date_offset = $row["ff_date_offset"]; $real_date = pgstr2time( $row["ff_real_date"] ); $disp_date = pgstr2time( $row["ff_disp_date"] ); $comment = list_escape( $row["ff_comment"] ); $timestamp = pgstr2time( $row["ff_timestamp"] ); echo "|" . $id . "|" . $state . "|" . $public . "|" . $filename . "|" . $hash . "|" . $camera . "|" . $orig_name . "|" . $timv_width . "|" . $timv_height . "|" . $timv_mtime . "|" . $timv_angle . "|" . $timv_flip . "|" . $exif_date . "|" . $date_offset . "|" . $real_date . "|" . $disp_date . "|" . $comment . "|" . $timestamp . "|\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); } } function send_fototags( $conn, $time ) { $sql = "select " . "ff_id, ft_id, " . pgts2str( "fft_timestamp" ) . " " . "from " . "fotolib_foto_tag " . "where " . "fft_timestamp >= " . str2pgts( "\$1" ); $values = array( 1 => pgtime2str( $time ) ); $ress = pg_query_params( $conn, $sql, $values ); if( !$ress ) { return; } echo "fototags\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); while( $row ) { $ffid = $row["ff_id"]; $ftid = $row["ft_id"]; $timestamp = pgstr2time( $row["fft_timestamp"] ); echo "|" . $ffid . "|" . $ftid . "|" . $timestamp . "|\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); } } function remote_cameras( $conn, $authenticated, $authlevel ) { $sql = "select " . "ff_camera, " . "count(*) as cnt " . "from " . "fotolib_foto " . "group by " . "ff_camera"; $ress = pg_query( $conn, $sql ); if( !$ress ) { return; } echo "cameras\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); while( $row ) { $cam = $row["ff_camera"]; $cnt = $row["cnt"]; echo "|" . $cam . "|" . $cnt . "|\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); } return true; } function remote_origfiles( $conn, $authenticated, $authlevel ) { if( !var_string( "R", "camera", $cam ) ) { // echo "auth $authenticated level $authlevel "; return false; } $sql = "select " . "ff_camera, ff_orig_name " . "from " . "fotolib_foto " . "where " . "ff_camera = \$1 " . "order by " . "ff_camera, ff_orig_name"; $values = array( 1 => $cam ); $ress = pg_query_params( $conn, $sql, $values ); if( !$ress ) { return; } echo "origfiles\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); while( $row ) { $cam = $row["ff_camera"]; $fil = $row["ff_orig_name"]; echo "|" . $cam . "|" . $fil . "|\n"; $row = pg_fetch_array( $ress, NULL, PGSQL_ASSOC ); } return true; } function remote_sync( $conn, $authenticated, $authlevel ) { if( !var_int( "R", "time", $time, 1, 2147483647 ) ) { // echo "auth $authenticated level $authlevel "; return false; } send_timestamp( $conn ); send_tags( $conn, $time ); send_fotos( $conn, $time ); send_fototags( $conn, $time ); return true; } function remotecmd( $conn, $cmd, $authenticated, $authlevel ) { header( "Content-type: text/plain" ); $ok = false; switch( $cmd ) { case "rem-cameras": $ok = remote_cameras( $conn, $authenticated, $authlevel ); break; case "rem-origfiles": $ok = remote_origfiles( $conn, $authenticated, $authlevel ); break; case "rem-sync": $ok = remote_sync( $conn, $authenticated, $authlevel ); break; default: break; } if( !$ok ) { echo "error\n"; } } ?>