Flarum discussion views

image

First and foremost, a huge thanks to @Toby and @luceos for helping me when I was stuck at moments with this extension on discord.

Anyway, my first extension - H Y P E.
I'm very proud to say I wanted this sort of extension for some time now. Since nobody made this yet .. Well I made it myself 😁

Features

  • Obviously tracks how much a discussion has been viewed and displays it per discussion on the discussionlist
  • Adds 2 sorting options: popular and unpopular
  • Adds 1 event which developers can listen for: DiscussionWasViewed
  • Adds 1 new permission where people can (re)set the viewcount of a discussion (default to admins)

Installation

composer require michaelbelgium/flarum-discussion-views

Screenshots

Normal:
image
Smaller screens:
Imgur

Reset the view count

Imgur

Extension settings

Imgur

Viewlist

Imgur

Footer viewlist

Imgur
imgur

Links

    ThomasLewis Right now litteraly anyone, any time when the discussion page gets loaded. I could look for unique views but not sure what it should be based on at first thought

      MichaelBelgium You could possibly track it by session ID in the database, but that could get messy fairly quickly without cross-checking session IDs with user numbers (to delete the session ID from the db entry if the user has a new one).
      Another possibility is using an array or list to store user IDs and session IDs. You would have to check the array/list every time the discussion was opened to see if it already had been logged.
      One issue with either of these is: do you delete the session IDs after a reply because there is new information?

      arajdon Only think im surely planning is to be able to sort by views, just like u can sort by "top", "latest" and "newest". Also thats a nice css edit!

      You should do a pull request if you like, it would be much better design than current

        A great extension, I like it.

        One question: is it meant to drop the number of comments for each discussion when you enter 'tablet view'?

        On full view, I have the number of comments and the number of views from H Y P E
        For me, drop it into tablet view, and it drops the number of comments, and only keeps the number of views.

        I think that's more appropriate MichaelBelgium
        extension.less

        .item-discussion-views {
        font-size: 14px;
        float:right;
        width: 10px;
        margin-top: 10px;
        margin-right: -45px;
        }
        @media (min-width: 768px)
        {
        .item-discussion-views:before {
        display: inline-block;
        font: normal normal normal 14px/1 FontAwesome;
        font-size: inherit;
        text-rendering: auto;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        content: "\f26c";
        float: left;
        margin-left: -21px;
        margin-top: 3px;
        }
        }
        @media (max-width: 767px) {
        .item-discussion-views
        {
        display: none !important;
        }
        }

          MichaelBelgium

          May you please allow for options to disable (hide) the replied count or number viewed on both mobile or desktop view?

          It looks great on desktop but on mobile I would like to hide the replied count and only show number viewed. I'm using a Pixel XL and can provide a screenshot if needed.

          Thank you.

            I get an error.

            Installation failed, reverting ./composer.json to its original content.

            [ErrorException]
            file_put_contents(/home/website/public_html/forums/vendor/composer/installed.
            json): failed to open stream: Permission denied

              jordanjay29 I guess it needs to be a toggle or something on the admin page so u can choose to display the comment count or not etc

              ericm9 I don't think that's the fault of the extension, I assume you're installing it on a VPS or some kind, and the webserver doesn't have permission to write/edit files

                7 days later