Gallery:API Core ShowItem

来自站长百科
Firebrance讨论 | 贡献2008年11月29日 (六) 15:26的版本 (新页面: ==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 priv...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

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);
    }
}