PDA

View Full Version : Event Views Counter


robert_2004
09-03-2006, 10:00 PM
This addon allows you to display the number of hits/views a calendar event has received.
It also inserts the eventid into the user's session, so they cannot refresh multiple times to boost the view count.

Thanks to tnguy3n (https://vborg.vbsupport.ru/member.php?u=35159) with his post here (https://vborg.vbsupport.ru/showthread.php?t=78527)

STEP 1 - MySQL modification:

ALTER TABLE event ADD hits INT(7) NOT NULL;

STEP 2 - calendar.php
FIND [line 134]

($hook = vBulletinHook::fetch_hook('calendar_start')) ? eval($hook) : false;

if ($vbulletin->GPC['week'])
{
$_REQUEST['do'] = 'displayweek';
}

BELOW, ADD:

// Event Views Counter - by Robert_2004
// https://vborg.vbsupport.ru/showthread.php?t=1067471

/*
* Comparision done between the host info in the session object.
* If the eventid is not stored in the session, that means the
* event hasn't been visited and therefore add it as a hit
* and update the table.
*/

$_SESSION['eventidsvisited'] = isset($_SESSION['eventidsvisited'])?$_SESSION['eventidsvisited']:array();
$eventids_exists = array_search($vbulletin->GPC['eventid'], $_SESSION['eventidsvisited']);

if ( $eventids_exists == 0) {
$_SESSION['eventidsvisited'][] = $vbulletin->GPC['eventid'];
$db->query_write("
UPDATE " . TABLE_PREFIX . "event
SET hits=hits+1
WHERE eventid=" . $vbulletin->GPC['eventid']);
}

Save and upload.


STEP 3 - template modification
edit template "calendar_showeventsbit"

FIND:

</td>
</tr>
</table>

</form>

</div>
$spacer_close

BEFORE THIS, ADD:

</td>
</tr>
<tr>
<td>
<!-- // Event Views Counter - by Robert_2004 -->
<!-- // https://vborg.vbsupport.ru/showthread.php?t=1067471 -->
<strong>Viewed</strong>: $eventinfo[hits] times

so it should look like:

</td>
</tr>
<tr>
<td>
<strong>Viewed</strong>: $eventinfo[hits] times
</td>
</tr>
</table>

</form>

</div>
$spacer_close

and that *should* be everything - i can't think of anything else that was needed.

if you use - please click INSTALL

hugh_
09-04-2006, 10:41 AM
Can we see a screenshot or example?

Thanks...

hugh

robert_2004
09-05-2006, 03:13 AM
screenshot added to orginal post.
It doesn't help much - as my event listing template is modified a great deal.

finn snor
09-06-2006, 06:17 AM
Great have been looking for this for a long time..Can it be made conditional so only admin can see views ?

robert_2004
09-06-2006, 04:08 PM
Yes, to only allow certain usergroups, use the following code:

usergroups 6 and 5 are admin and super moderators, respectively.



<if condition="is_member_of($bbuserinfo, 6, 5) OR $show['admincplink']">
<tr>
<td>
<strong>Viewed</strong>: $eventinfo[hits] times
</td>
</tr>
</if>

snowname
11-26-2013, 03:06 AM
The database function works on 4.1.3.