Dynamic Search in TYPO3: Code Snippets

Snippet 1

t3lib_extMgm::addService($_EXTKEY,  'auth' /* sv type */,  
'tx_myprofile_sv1' /* sv key */,
		array(

			'title' => 'MyProfile Authentication',
			'description' => 'Frontend authentication service',
			'subtype' => 'getUserFE,authUserFE,getGroupsFE',
			'available' => TRUE,
			'priority' => 100,
			'quality' => 100,

			'os' => '',
			'exec' => '',

			'classFile' => t3lib_extMgm::extPath($_EXTKEY).'sv1/class.tx_myprofile_sv1.php',
			'className' => 'tx_myprofile_sv1',
		)
	);

Snippet 2

require_once(PATH_t3lib.'class.t3lib_svbase.php');

class tx_myprofile_sv1 extends tx_sv_authbase {
	var $prefixId = 'tx_myprofile_sv1';		// Same as class name
	var $scriptRelPath = 'sv1/class.tx_myprofile_sv1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'myprofile';	// The extension key.

Snippet 3

// Check if we're on a profile page page
if(in_array($GLOBALS['TSFE']->id,t3lib_div::trimExplode(',',$this->profilePageIdList))) {
	// Check if the user is member is isn't set (tx_myprofile_pi1[uid])
	$membersGet = t3lib_div::_GET('tx_myprofile_pi1');		

	// A member id is given, we use it.
	$requestedUserId = $membersGet['uid'];

	// If we have a profile page user id
	if($requestedUserId) {	
		if($user['uid'] == $requestedUserId) {
			$GLOBALS['TSFE']->register['myprofile']['auth']['isOwner'] = 1;

			// User viewing their own profile page?  Then don't cache it.
			$GLOBALS['TSFE']->set_no_cache();	
		} else {
			$GLOBALS['TSFE']->register['myprofile']['auth']['isOwner'] = 0;

			// This method returns a usergroup uid representing friends
			// or public users and a true or false to the existence of a friendship.
			$addGroup = $this->getFriendshipGroup($user['uid'],$requestedUserId);
			if($addGroup) {
				$groups[] = $addGroup;
			}
		}
	}
	if($requestedUserId) {
		
$GLOBALS['TSFE']->register['myprofile']['auth']['requestedUserId'] = 
intval($requestedUserId);
	}
}
/* Profile stuff ends here */

Snippet 4

$GLOBALS['TSFE']->page_cache_reg1 = $userUid;

Snippet 5

function clearCacheByPageAndRegister($page,$reg1Val) {
	if($page == true) {
		$where = 'reg1="'.intval($reg1Val).'" AND page_id="'.intval($page).'"';			
	} else {
		$where = 'reg1="'.intval($reg1Val).'"';
	}
	$GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages',$where);
}