Is the pro rata share that a passenger pays limited to the time he spends in the plane, or can it apply to the whole “operation”? Let’s say my friend, who lives 100 miles away, asks me to fly him on a tour of his hometown. I take off from my home airport, fly 2 hours to his local airport, and land to pick him up. After flying him on a 1 hour tour, I drop him off and return, solo, to my home airport. Upon landing, 2 hours later, I refuel and, finding that I spent 100 dollars on gas for the entire day, prompt him to pay me 50 bucks. Given I made all legs of the flight for the sole purpose of entertaining his desire. Is my request for 50 dollars legal? Or, given that he was only in the plane for 1 hour out of 5, am I only entitled to 20?
The situation you're describing is a commercial operation. Without a commercial certificate (and a part 135 operation) you may not receive any compensation at all.
The FAA has consistently held that the 61.113's non-compensation exemption in 61.113(c) requires common purpose for the pilot and passengers (Bobertz - 2009, p.2):
Absent a bona fide common purpose for their travel, reimbursement for the pro rata share of operating expenses constitutes compensation and the flights would be considered a commercial operation for which a part 119 certificate is required.
There is unfortunately not a strict definition of common purpose. However, the basic ground rule is that to fall under 61.113(c), the pilot must have their own reason for making the flight, independent of the passenger's.
The Bobertz interpretation presents an illustrative example: if a pilot wanted to go to a race, they could bring contestants to the race as passengers, and receive compensation. Because the pilot was flying there for the purpose of attending the race, common purpose is established, and pro-rata cost sharing is permitted.
However, if not all of the members of the race team could fit in the plane, the pilot could not share the cost to go back to the origin to make a second trip: there's no independent reason to do so. This crosses the line into a commercial operation, so no compensation is allowed.
Applying these guidelines to your question, the key phrase here is:
I made all legs of the flight for the sole purpose of entertaining his desire.
There is clearly no common purpose. Therefore, accepting any compensation for the flight, even a pro-rata cost, is compensation in violation of 61.113.
Past FAA legal interpretations have held that "building flight time" is considered compensation. So any expense (e.g. fuel cost) relating to the solo flight time you acquired enroute to your friend's house, if reimbursed to you in part by him, would be considered compensation and not allowed under the circumstances you describe. Once he is onboard 61.113(c) specifically allows a pro rata share of operating expenses to be paid by him to you.
Here is a relevant excerpt from a legal interpretation. Although the underlying circumstances prompting the interpretation are different (glider towing), the essential principle (compensation) is the same.
Here is a copy of the complete interpretation: (legal interpretation)