Carbonated drinks are made by forcing carbon gas into a beverage under pressure. In an unopened bottle, there is an equilibrium between the carbon that has been dissolved into the liquid and the carbon gas floating at the very top of the bottle. Opening the bottle results in a bit of fizzing as the pressure that has been keeping the carbon dissolved is released, but nothing that will spray you in the face with soda.
If you shake the bottle before opening it, some of the carbon that has been floating at the top of the bottle gets suspended in the liquid. This "extra" carbonation stays in larger (though not necessarily visible) bubbles than the already-dissolved carbon. If you or your innocent friend open the bottle at this point, the large bubbles will rise very quickly to the liquid's surface - resulting in an impressive soda explosion!
If you know that your soda has either accidentally or intentionally been shaken, just let it sit for a little while before opening. Those large bubbles of extra carbonation will eventually work their way out of the beverage and back to the top of the bottle where they belong.