Gallery2:API Core ShowItem - Gallery Codex
Personal tools

Gallery2:API Core ShowItem

From Gallery Codex

Admin's views don't increase view count

Within ShowItem.inc there's code that increments an album's view count when the album is viewed. To ignore views made by anyone with admin privileges, you need to:

  • Find out if the user viewing the page is an admin
  • Only call incrementItemViewCount() if the user is not an admin

This is how it is done (around line 106, v2.1 and line 120, v.2.2):

/* Is the user an admin? */
list ($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
if ($ret) {
    return array($ret->wrap(__FILE__, __LINE__), null);
 }
 /* Increment the view count */
 if (!$isAdmin) {
    $ret = GalleryCoreApi::incrementItemViewCount($item->getId());
    if ($ret) {
       return array($ret->wrap(__FILE__, __LINE__), null);
    }
 }

This is how it is done (around line 106, v2.0.x):

/* Is the user an admin? */
list ($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
if ($ret->isError()) {
    return array($ret->wrap(__FILE__, __LINE__), null);
}
/* Increment the view count */
if (!$isAdmin) {
    $ret = GalleryCoreApi::incrementItemViewCount($item->getId());
    if ($ret->isError()) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
}