Current File : /home/jvzmxxx/wiki1/extensions/SocialProfile/UserActivity/SiteActivityHook.php
<?php

class SiteActivityHook {

	/**
	 * Register the <siteactivity> hook with the Parser.
	 *
	 * @param Parser $parser Parser
	 * @return bool
	 */
	public static function onParserFirstCallInit( &$parser ) {
		$parser->setHook( 'siteactivity', array( __CLASS__, 'getSiteActivity' ) );
		return true;
	}

	public static function getSiteActivity( $input, $args, $parser ) {
		global $wgMemc, $wgExtensionAssetsPath;

		$parser->disableCache();

		$limit = ( isset( $args['limit'] ) && is_numeric( $args['limit'] ) ) ? $args['limit'] : 10;

		// so that <siteactivity limit=5 /> will return 5 items instead of 4...
		$fixedLimit = $limit + 1;

		$key = wfMemcKey( 'site_activity', 'all', $fixedLimit );
		$data = $wgMemc->get( $key );
		if ( !$data ) {
			wfDebug( "Got site activity from DB\n" );
			$rel = new UserActivity( '', 'ALL', $fixedLimit );

			$rel->setActivityToggle( 'show_votes', 0 );
			$activity = $rel->getActivityListGrouped();
			$wgMemc->set( $key, $activity, 60 * 2 );
		} else {
			wfDebug( "Got site activity from cache\n" );
			$activity = $data;
		}

		$output = '';
		if ( $activity ) {
			$output .= '<div class="mp-site-activity">
			<h2>' . wfMessage( 'useractivity-siteactivity' )->plain() . '</h2>';

			$x = 1;
			foreach ( $activity as $item ) {
				if ( $x < $fixedLimit ) {
					$typeIcon = UserActivity::getTypeIcon( $item['type'] );
					$output .= '<div class="mp-activity' . ( ( $x == $fixedLimit ) ? ' mp-activity-border-fix' : '' ) . '">
					<img src="' . $wgExtensionAssetsPath . '/SocialProfile/images/' . $typeIcon . '" alt="' . $typeIcon . '" border="0" />'
					. $item['data'] .
					'</div>';
					$x++;
				}
			}

			$output .= '</div>';
		}

		return $output;
	}

}