Hey there, :)
Please dont take my word as set in stone here. I asked myself this question aswell, and as far as i can say the influence increase from attacks is something like
After a ***winning attack***:
The difference between what you lost and what he lost devided by 2.5
For example:
If you hit someone and lose troops worth 1mill in influence, but he loses troops worth 4mill in influence, then the difference here is 3mill. (4m-1m)
Now 3mill devided by 2.5 is 1.2m. So in this scenario u gained back the 1mill + 200k.
Again:
This, most certainly, is not the correct formular but rather what i often observe.
And... If you lose the battle... well. If he hits you for 4mill, then you just lost 4mill. :P
Your Influence consists of 5 elements(You can see it if you press Palace-->Statistics-->Influence):
1. Buildings
2. Troops
3. Knowledge
4. Hero
5. Quests