Drupal 7 custom module for menu
This is an existing module which does part of what you want to do. The module is Menu item visibility. I recommend looking at how it works and extending it (it says it's extendable) to add the extra pieces you are requesting: visible per page, or visible on PHP code. It probably has hooks you can use to complete your business logic.

In fact, this issue talks about adding "per page" or "php code" conditions essentially.