示例#1
0
		public function login() {
		
			//Hash for the API Key
			$cache_u_apikey = md5($this->get('eventarc-password'));
			
			//HAsh for the User ID
			$cache_u_id = md5($this->get('eventarc-username'));
		
			$cache = new Cacheable(Symphony::Database());
			
			//Check for a cached API Key
			$cached_u_apikey = $cache->check($cache_u_apikey);
			$this->u_apikey = $cached_u_apikey['data'];
			
			//Check for a cached User ID
			$cached_u_id = $cache->check($cache_u_id);
			$this->u_id = $cached_u_id['data'];	
			
			// Login first using the credentials from preferences. 
			// This returns the API key which is stored and used for all subsequent requests.
			if (empty($this->u_apikey) || empty($this->u_id))
			{
				$eventarc = new Eventarc;
				try
				{
					$login_data = $eventarc->user_login($this->get('eventarc-username'),$this->get('eventarc-password'));
						
					//Save the API key in Cache for 1 hour.
					$cache->write($cache_u_apikey, $login_data['u_apikey'], 60);
					$cached_u_apikey = $cache->check($cache_u_apikey);
					$this->u_apikey = $cached_u_apikey['data'];
					
					//Save the User ID in Cache for 1 hour.
					$cache->write($cache_u_id, $login_data['u_id'], 60);
					$cached_u_id = $cache->check($cache_u_id);
					$this->u_apikey = $cached_u_id['data'];
	
					// Re-make eventarc with the new apikey
					$this->eventarc = new Eventarc($this->u_apikey, $this->get('eventarc-username'));
					return $this->eventarc;
					
				}
				catch (Eventarc_Exception $e)
				{
					echo 'Error: '.$e->getMessage();
					return false;
				}
			} else {
				try
				{
					$this->eventarc = new Eventarc($this->u_apikey, $this->get('eventarc-username'));
					return $this->eventarc;
				} catch (Eventarc_Exception $e)
				{
					echo 'Error: '.$e->getMessage();
					return false;
				}
			}
		}
		protected function __trigger(){
		
			//Check the hash and the ID match
			if($_GET["hash"] == sha1($_GET["id"])) {
			
				
				//Get the entry object from the ID.
				if(!isset(self::$entryManager)) {
					self::$entryManager = new entryManager(Symphony::Engine());
				}
				$entry_id = $_GET["id"];
				$section_id = self::$entryManager->fetchEntrySectionID($entry_id);
				
				$entry = self::$entryManager->fetch($entry_id, $section_id);
				$entry = $entry[0];
				

				//Retreive the Pushed JSON from the Eventarc API.
				$data = json_decode(
					utf8_encode(file_get_contents("php://input")), 
					TRUE
				);
				
				//Eventarc entry id.
				$e_id = $data['e_id'];
				
				//Login to eventarc & return the API key.
				$eventarc = new Eventarc;
				$login_data = $eventarc->user_login($this->get('eventarc-username'),$this->get('eventarc-password'));
				$u_apikey = $login_data['u_apikey'];
				
				//Now retrieve the Event
				$eventarc = new Eventarc($u_apikey, $this->get('eventarc-username'));
				$event = $eventarc->event_get($e_id);
				
				//First save the standard event entry fields	
				$fields = array();
				foreach($event as $key => $value) {
					if($this->string_begins_with($key, 'e_')) {
						$fields[str_replace('e_', 'e-', $key)] = strip_tags($value);
					} else if ($this->string_begins_with($key, 'g_')) {
						$fields[str_replace('g_', 'g-', $key)] = strip_tags($value);
					} 
				}	
				//Update the e_status to be 'Yes/No' for Symphony;
				if($fields['e-status'] == 'active') {
					$fields['e-status'] = 'yes';
				} else {
					$fields['e-status'] = 'no';
				}
				//Now look for address details
				$address = $eventarc->event_get_address($e_id);
				foreach($address as $key => $value) {
					if($this->string_begins_with($key, 'a_')) {
						$fields[str_replace('a_', 'a-', $key)] = strip_tags($value);
					} 
				}
					
				if(!isset(self::$fieldManager)) {
					self::$fieldManager = new fieldManager(Symphony::Engine());
				}
				
				foreach($fields as $key => $value) {
					$field_id = self::$fieldManager->fetchFieldIDFromElementName($key);
					if(isset($field_id)) {
						$entry->setData($field_id, array(
							'value' => $value,
						));
					}
				}
				
				$entry->commit();
				
				return true;
			
			}
		}
示例#3
0
<?php

	require_once('class.eventarc.php');

	if(isset($_GET["apikey"]) && isset($_GET["uname"])) {
		
		$eventarc = new Eventarc($_GET["apikey"], $_GET["uname"]);
		$groups = $eventarc->group_list();
		
		header("Content-type: application/json");
		echo json_encode($groups);
		
	}