(a) In any action based upon prison conditions brought under any statute or Constitutional provision, if attorney fees are recoverable pursuant to any state statute, no attorney fees shall be awarded to a prisoner, except to the extent that:
(1) The fees were directly and reasonably incurred by an attorney in proving an actual violation of prisoner's rights protected by the Constitution or statute; and
(2) The amount of the fees is proportionately related to the court-ordered relief for the violation, or the fees were directly and reasonably incurred in enforcing the relief ordered for the violation.
(b) Nothing in this section shall prohibit a prisoner from entering into an agreement to pay an attorney fee in excess of the amount authorized in this section, if the fee is paid by the prisoner rather than by another party to a civil action.