Hi All,

When creating a single Page display in Views (4.7.x), Views doesn't seem to update the daycount
or totalcount in node_counter. Technically, the url is the Views url, so whatever does the core counter update doesn't have the proper Node ID of the page that was displayed by the View to update the proper Node counters.

Tried (didn't work):
<?php
  global $current_view;
  print $GLOBALS['current_view']->url;
  print $GLOBALS['current_view']->num_rows;
  $nodeid=$node->nid;
  print $nodeid;
  print($node->nid);
  print($arg[0]);
?>

Prints:
RandomFrontPage.html
1
NULL
NULL
NULL

Basically it should be simple to find the displayed Node ID, and then run this:

 db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1)); 

to update the counters. But I'm running into a blank wall trying to guess whatever the proper terminology is.

So, does anyone know some code to place in the Views' (footer?) so that the displayed Node's ID is determined and the proper update can be made to node_counter? Preferably with proper syntax?

Thanks,

M.J. Taylor
Publisher
from Reason to Freedom

Comments

M.J. Taylor’s picture

After re-reading the post, Statistics: exclude admin from content view count, would it just be possible to set the global arg(1) to the displayed content's Node ID? Then just let the regular statistics_exit() do the work?

MJ

M.J. Taylor’s picture

Solution and Handbook writeup:

HowTo: Create a Random, Single, Full Node on Your Home Page (4.7.x/5.x)

M.J. Taylor
Publisher
from Reason to Freedom
Wekly libertarian magazine promoting thinking for oneself, thus helping to create a free, benevolent society.

M.J. Taylor’s picture

Okay,

In a blind attempt, since the API section of Views is almost empty, does anyone know how to extract the nid from:

<?php
    $fields = _views_get_fields();
    print($fields['node.body']['addlfields'][0]);
    print($fields['node.body']['addlfields'][0]->nid);
?>

Prints:
nid
NULL

The full listing of the array is below, if someone could just point me at the right variable/syntax, I can do the rest.

Thanks,

M.J. Taylor
Publisher
from Reason to Freedom
Wekly libertarian magazine promoting thinking for oneself, thus helping to create a free, benevolent society.

Put in Footer:
<?php
    $fields = _views_get_fields();
    print_r($fields);
?>

Returns:
    [node.title] => Array
        (
            [name] => Node: Title
            [handler] => Array
                (
                    [views_handler_field_nodelink] => Normal
                    [views_handler_field_nodelink_with_mark] => With updated mark
                )

            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As link
                            [nolink] => Without link
                        )

                )

            [sortable] => 1
            [addlfields] => Array
                (
                    [0] => changed
                )

            [help] => Display the title of the node.
            [table] => node
        )

    [node.nid] => Array
        (
            [name] => Node: ID
            [sortable] => 1
            [notafield] => 1
            [handler] => views_handler_node_nid
            [sort_handler] => views_node_query_handler_nid
            [help] => Display the NID of a node.
            [table] => node
        )

    [node.created] => Array
        (
            [name] => Node: Created Time
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_date_small] => As Short Date
                    [views_handler_field_date] => As Medium Date
                    [views_handler_field_date_large] => As Long Date
                    [views_handler_field_date_custom] => As Custom Date
                    [views_handler_field_since] => As Time Ago
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display the post time of the node. The option field may be used to specify the custom date format as it's required by the date() function or if "as time ago" has been chosen to customize the granularity of the time interval.
            [table] => node
        )

    [node.changed] => Array
        (
            [name] => Node: Updated Time
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_date_small] => As Short Date
                    [views_handler_field_date] => As Medium Date
                    [views_handler_field_date_large] => As Long Date
                    [views_handler_field_date_custom] => As Custom Date
                    [views_handler_field_since] => As Time Ago
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display the last time the node was updated. The option field may be used to specify the custom date format as it's required by the date() function or if "as time ago" has been chosen to customize the granularity of the time interval.
            [table] => node
        )

    [node.type] => Array
        (
            [name] => Node: Type
            [handler] => views_handler_nodetype
            [sortable] => 1
            [help] => The Node Type field will display the type of a node (for example, 'blog entry', 'forum post', 'story', etc)
            [table] => node
        )

    [node.link] => Array
        (
            [name] => Node: Link to node
            [handler] => views_handler_field_node_link
            [sortable] => 
            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [notafield] => true
            [help] => This will create a link to the node; fill the option field with the text for the link. If you want titles that link to the node, use Node: Title instead.
            [table] => node
        )

    [node.body] => Array
        (
            [name] => Node: Body
            [handler] => Array
                (
                    [views_handler_field_body] => Full Text
                    [views_handler_field_teaser] => Teaser
                )

            [addlfields] => Array
                (
                    [0] => nid
                )

            [notafield] => 1
            [help] => Display the Main Content.
            [table] => node
        )

    [node.view] => Array
        (
            [name] => Node: View link
            [handler] => views_handler_node_view
            [notafield] => 1
            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display a link to view the node. Enter the text of this link into the option field; if blank the default "view" will be used.
            [table] => node
        )

    [node.edit] => Array
        (
            [name] => Node: Edit link
            [handler] => Array
                (
                    [views_handler_node_edit_destination] => Return To View
                    [views_handler_node_edit] => Return to Node
                )

            [notafield] => 1
            [addlfields] => Array
                (
                    [0] => type
                    [1] => uid
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display a link to edit the node. Enter the text of this link into the option field; if blank the default "edit" will be used.
            [table] => node
        )

    [node.delete] => Array
        (
            [name] => Node: Delete link
            [handler] => Array
                (
                    [views_handler_node_delete_destination] => Return To View
                    [views_handler_node_delete] => Return To The Frontpage
                )

            [notafield] => 1
            [addlfields] => Array
                (
                    [0] => type
                    [1] => uid
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display a link to delete the node. Enter the text of this link into the option field; if blank the default "delete" will be used.
            [table] => node
        )

    [users.name] => Array
        (
            [name] => Node: Author Name
            [handler] => views_handler_field_username
            [sortable] => 1
            [uid] => uid
            [addlfields] => Array
                (
                    [0] => uid
                )

            [help] => This will display the author of the node.
            [table] => users
        )

    [users.uid] => Array
        (
            [name] => User: Author Picture
            [handler] => views_handler_field_userpic
            [sortable] => 
            [help] => Display the user picture of the author.
            [table] => users
        )

    [book_parent_node.title] => Array
        (
            [name] => Book: Parent Title
            [handler] => Array
                (
                    [views_handler_field_book_parent_title] => As Link
                    [views_handler_field_book_parent_title_nl] => Without Link
                )

            [addlfields] => Array
                (
                    [0] => nid
                )

            [help] => Display the title of the parent node
            [table] => book_parent_node
        )

    [comments.subject] => Array
        (
            [name] => Comment: Subject
            [handler] => Array
                (
                    [views_handler_field_commentlink] => Normal
                    [views_handler_field_commentlink_with_mark] => With updated mark
                )

            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As link
                            [nolink] => Without link
                        )

                )

            [addlfields] => Array
                (
                    [0] => cid
                )

            [sortable] => 1
            [table] => comments
        )

    [comments.comment] => Array
        (
            [name] => Comment: Comment
            [handler] => views_handler_field_comment
            [addlfields] => Array
                (
                    [0] => format
                )

            [help] => Display the content of a comment.
            [table] => comments
        )

    [comments.cid] => Array
        (
            [name] => Comment: Comment ID
            [sortable] => 1
            [help] => Display the CID of a comment.
            [table] => comments
        )

    [comments.timestamp] => Array
        (
            [name] => Comment: Created Time
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_date_small] => As Short Date
                    [views_handler_field_date] => As Medium Date
                    [views_handler_field_date_large] => As Long Date
                    [views_handler_field_date_custom] => As Custom Date
                    [views_handler_field_since] => As Time Ago
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display the post time of the comment.
            [table] => comments
        )

    [comments.name] => Array
        (
            [name] => Comment: Author Name
            [handler] => views_handler_field_username
            [sortable] => 1
            [uid] => uid
            [addlfields] => Array
                (
                    [0] => uid
                )

            [help] => This will display the author of the node.
            [table] => comments
        )

    [comments.add] => Array
        (
            [name] => Comment: Add link
            [handler] => views_handler_comment_add
            [notafield] => 1
            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display a link to add a comment to the node. Enter the text of this link into the option field; if blank the default "Comment" will be used.
            [table] => comments
        )

    [node_comment_statistics.last_comment_timestamp] => Array
        (
            [name] => Comment: Last Comment Time
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_date_small] => As Short Date
                    [views_handler_field_date] => As Medium Date
                    [views_handler_field_date_large] => As Long Date
                    [views_handler_field_date_custom] => As Custom Date
                    [views_handler_field_since] => As Time Ago
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => This will display the last comment time.
            [table] => node_comment_statistics
        )

    [node_comment_statistics.last_comment_name] => Array
        (
            [name] => Comment: Last Comment Author
            [query_handler] => views_query_handler_field_last_comment_name
            [handler] => views_handler_field_last_comment_name
            [sortable] => 1
            [uid] => last_comment_uid
            [addlfields] => Array
                (
                    [0] => last_comment_name
                    [1] => last_comment_uid
                )

            [help] => This will display the name of the last user to comment on the post.
            [table] => node_comment_statistics
        )

    [node_comment_statistics.comment_count] => Array
        (
            [name] => Comment: Count
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_int] => Normal
                    [views_handler_comments_with_new] => With New Count
                )

            [help] => This will display the comment count.
            [table] => node_comment_statistics
        )

    [node_comment_statistics.last_changed] => Array
        (
            [name] => Comment: Last Changed Time
            [query_handler] => views_query_handler_field_last_changed
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_date_small] => As Short Date
                    [views_handler_field_date] => As Medium Date
                    [views_handler_field_date_large] => As Long Date
                    [views_handler_field_date_custom] => As Custom Date
                    [views_handler_field_since] => As Time Ago
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [notafield] => 1
            [help] => This will display the time of the last comment or node edit.
            [table] => node_comment_statistics
        )

    [profile_Interests.value] => Array
        (
            [name] => Profile: Interests
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_Interests
        )

    [profile_Location.value] => Array
        (
            [name] => Profile: Location
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_Location
        )

    [profile_Nationality.value] => Array
        (
            [name] => Profile: Nationality
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_Nationality
        )

    [profile_FavoriteMovie.value] => Array
        (
            [name] => Profile: Favorite Movie
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_FavoriteMovie
        )

    [profile_FavoriteBook.value] => Array
        (
            [name] => Profile: Favorite Book
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_FavoriteBook
        )

    [profile_FavoriteTVSeries.value] => Array
        (
            [name] => Profile: Favorite TV Series
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_FavoriteTVSeries
        )

    [profile_OtherThoughts.value] => Array
        (
            [name] => Profile: Other Thoughts
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_textarea
            [table] => profile_OtherThoughts
        )

    [profile_My_Website.value] => Array
        (
            [name] => Profile: My Website
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_My_Website
        )

    [profile_FavoriteArticle.value] => Array
        (
            [name] => Profile: Favorite Article
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_FavoriteArticle
        )

    [profile_FavoriteArticleURL.value] => Array
        (
            [name] => Profile: Favorite Article Link
            [help] => Other types based profile field help
            [sortable] => 1
            [handler] => views_handler_field_profile_default
            [table] => profile_FavoriteArticleURL
        )

    [node_counter.totalcount] => Array
        (
            [name] => Node: Total Hits
            [sortable] => 1
            [help] => This will display the number of times a node has been read.
            [table] => node_counter
        )

    [node_counter.daycount] => Array
        (
            [name] => Node: Recent Hits
            [sortable] => 1
            [help] => This will display the number of times a node has been read recently.
            [table] => node_counter
        )

    [node_counter.timestamp] => Array
        (
            [name] => Node: Last Hit Time
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_date_small] => As Short Date
                    [views_handler_field_date] => As Medium Date
                    [views_handler_field_date_large] => As Long Date
                    [views_handler_field_date_custom] => As Custom Date
                    [views_handler_field_since] => As Time Ago
                )

            [option] => Array
                (
                    [#type] => textfield
                    [#size] => 10
                    [#maxlength] => 255
                )

            [help] => Display the time the node was last read.
            [table] => node_counter
        )

    [term_node.name] => Array
        (
            [name] => Taxonomy: All Terms
            [help] => This will display all taxonomy terms associated with the node. Note that this causes one extra query per row displayed, and might have a minor performance impact.
            [sortable] => 
            [handler] => views_handler_field_allterms
            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As links
                            [nolink] => Without links
                        )

                )

            [notafield] => 1
            [table] => term_node
        )

    [term_node_3.name] => Array
        (
            [name] => Taxonomy: Terms for Politics
            [sortable] => 
            [help] => This will display all taxonomy terms associated with the node that are members of Politics. Note that this causes one extra query per row displayed, and might have a minor performance impact.
            [handler] => views_handler_field_allterms
            [vocabulary] => 3
            [notafield] => 1
            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As links
                            [nolink] => Without links
                        )

                )

            [table] => term_node_3
        )

    [term_node_4.name] => Array
        (
            [name] => Taxonomy: Terms for Locations
            [sortable] => 
            [help] => This will display all taxonomy terms associated with the node that are members of Locations. Note that this causes one extra query per row displayed, and might have a minor performance impact.
            [handler] => views_handler_field_allterms
            [vocabulary] => 4
            [notafield] => 1
            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As links
                            [nolink] => Without links
                        )

                )

            [table] => term_node_4
        )

    [term_node_2.name] => Array
        (
            [name] => Taxonomy: Terms for Reviews
            [sortable] => 
            [help] => This will display all taxonomy terms associated with the node that are members of Reviews. Note that this causes one extra query per row displayed, and might have a minor performance impact.
            [handler] => views_handler_field_allterms
            [vocabulary] => 2
            [notafield] => 1
            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As links
                            [nolink] => Without links
                        )

                )

            [table] => term_node_2
        )

    [term_node_5.name] => Array
        (
            [name] => Taxonomy: Terms for Groups
            [sortable] => 
            [help] => This will display all taxonomy terms associated with the node that are members of Groups. Note that this causes one extra query per row displayed, and might have a minor performance impact.
            [handler] => views_handler_field_allterms
            [vocabulary] => 5
            [notafield] => 1
            [option] => Array
                (
                    [#type] => select
                    [#options] => Array
                        (
                            [link] => As links
                            [nolink] => Without links
                        )

                )

            [table] => term_node_5
        )

    [term_data.name] => Array
        (
            [name] => Taxonomy: Term
            [sortable] => 1
            [handler] => Array
                (
                    [views_handler_field_tid] => No link
                    [views_handler_field_tid_link] => With link
                )

            [addlfields] => Array
                (
                    [0] => tid
                )

            [help] => This will display one of the taxonomy terms associated with the node; if taxonomy terms were used to filter or sort, it will be the one that triggered the sort or filter.
            [table] => term_data
        )

    [term_data.description] => Array
        (
            [name] => Taxonomy: Term Description
            [sortable] => 
            [help] => This will display the description associated with a taxonomy term.
            [table] => term_data
        )

)