You can use Views Aggregation to count the number of results for your specific cases.
Count number of nodes authored by a user
Since your results (to be counted) are nodes it makes sense to create Content type Views:
- Create Content Views with Page Display and Filter out the node types you want to count later.
- Add node Title field or Node ID under Fields to test you have the correct list of content. Add Author ID or Name to test the Contextual filter later.
- Set Path to
user/%user/stats
, set Menu Tab so it displays under Drupal tabs on user pages
- Add a Contextual filter Author UID (provide default value; User ID from URL) and test by entering user ID number into the Preview, make sure you see all the nodes created by the author with that UID
- Under Fields make sure you only have ONE node field (if you have both NID and Title, remove Title). You can keep the Author fields, for testing if nothing else. We'll use one unique node field to count them aggregated. If we add another node field it will force Views results to show one node per Views row, which will make counting impossible
- Remove Sorting criteria - they mess up Aggregation!
- Turn on Aggregation
- Edit the NID Field Aggregation setting to
Count
or Count DISTINCT
(if you don't have duplicates in your Views results Count will do)
You now have Views counting the results! If you enter user UID into Preview you will see the number of their nodes in the NID field (adjust the NID field label accordingly).
If you enter all
into Preview you will see a list of all Authors (from that nodes list, if you kept that Field) and the number of the nodes they created.
If you visit a user page you should see the stats tab added to Drupal tabs. Adjust the Permissions for the Views Page to limit who can see it.
Count number of comments authored by a user
Repeat the above procedure to count comments, only start with Commment Views Type, set a different Path user/%user/stats-comment
and Menu tab
Count flags
To count how many of the listed nodes are flagged you'll need a Relationship to that information, then you'll be able to list a Field with the Flag status and use Aggregation to count them, similar to the above.
There are answers/articles on how to set up Flag Relationship in Views to display various information.