  The quantization of optical fields in vacuum has been known for decades, but
extending the field quantization to lossy and dispersive media in
nonequilibrium conditions has proven to be complicated due to the
position-dependent electric and magnetic responses of the media. In fact,
consistent position-dependent quantum models for the photon number in resonant
structures have only been formulated very recently and only for dielectric
media. Here we present a general position-dependent quantized fluctuational
electrodynamics (QFED) formalism that extends the consistent field quantization
to describe the photon number also in the presence of magnetic field-matter
interactions. It is shown that the magnetic fluctuations provide an additional
degree of freedom in media where the magnetic coupling to the field is
prominent. Therefore, the field quantization requires an additional independent
noise operator that is commuting with the conventional bosonic noise operator
describing the polarization current fluctuations in dielectric media. In
addition to allowing the detailed description of field fluctuations, our
methods provide practical tools for modeling optical energy transfer and the
formation of thermal balance in general dielectric and magnetic nanodevices. We
use the QFED to investigate the magnetic properties of microcavity systems to
demonstrate an example geometry in which it is possible to probe fields arising
from the electric and magnetic source terms. We show that, as a consequence of
the magnetic Purcell effect, the tuning of the position of an emitter layer
placed inside a vacuum cavity can make the emissivity of a magnetic emitter to
exceed the emissivity of a corresponding electric emitter.
