Ejemplo n.º 1
0
	function onAfterInitialise(){
		global $mainframe;
		if(!class_exists('plgSystemmyApiConnect') || $mainframe->isAdmin()) 
			return;
		
		$facebook = plgSystemmyApiConnect::getFacebook();
		$signedRequest = $facebook->getSignedRequest();
		$session =& JFactory::getSession();
		if(is_array($signedRequest)){
			JRequest::setVar('tmpl','component');
			if(isset($signedRequest['user_id'])){
				$user = JFactory::getUser();
				if($user->guest){
					global $mainframe;
					$options['uid'] = $signedRequest['user_id'];
					$mainframe->login($signedRequest['user_id'],$options);
				}
			}
		}
		$method = $_SERVER['REQUEST_METHOD'];  
		if($session->get( 'fbtmpl' ) == '1'){
			JRequest::setVar('tmpl','component');
		}
		
		if(JRequest::getVar('tmpl') == 'component')
			$session->set( 'fbtmpl','1');
	}
Ejemplo n.º 2
0
	function getPageLink($id){
		try {
			$facebook = plgSystemmyApiConnect::getFacebook();
			$page = $facebook->api('/'.$id);
			return $page['link'];
		}catch (FacebookApiException $e) {
			error_log($e);
		}
	}
Ejemplo n.º 3
0
	function deleteSubscriptions(){
		global $mainframe;
		$facebook = plgSystemmyApiConnect::getFacebook();
		try{
			foreach($_POST['cid'] as $object){
				$facebook->api('/'.$facebook->getAppId().'/subscriptions','delete',array('access_token' => $this->getRealTimeAccess(),'object' => $object));
			}
			JFactory::getApplication()->enqueueMessage( JText::_('SUBSCRIPTIONS_DELETED') );
		} catch (FacebookApiException $e) {
			JError::raiseNotice( 100, $e->__toString() );
			$mainframe->redirect('index.php?option=com_myapi&view=realtime');
		}
		return;
	}
Ejemplo n.º 4
0
	function onAuthenticate($uid, $options, &$response )
    {
		if(!file_exists(JPATH_SITE.DS.'plugins'.DS.'system'.DS.'myApiConnectFacebook.php')){ return; }
		if(isset($options['group'])){
			if($options['group']!="Public Backend"){
				return;
			}	
		}
      	if(!is_array($uid)){
			$db =& JFactory::getDBO();
			
			$query = "SELECT #__users.id,#__myapi_users.access_token FROM ".$db->nameQuote('#__myapi_users')." JOIN #__users ON #__myapi_users.userId = #__users.id WHERE ".$db->nameQuote('uid')." = ".$db->quote($uid)." AND #__users.block = '0'";
			$db->setQuery( $query );
			$db->query();
			$result = $db->loadAssoc();
			$id = $result['id'];
			if($id != ''){      
				if($result['access_token'] == ''){
					$facebook = plgSystemmyApiConnect::getFacebook();
					$facebookSession = $facebook->getSession();
					$query = "UPDATE ".$db->nameQuote('#__myapi_users')." SET ".$db->nameQuote('access_token')." = ".$db->nameQuote($facebookSession['access_token'])." WHERE ".$db->nameQuote('uid')." = ".$db->quote($uid);
					$db->setQuery($query);
					$db->query();	
				}
				 
				$user = JFactory::getUser($id);
				$response->status			= JAUTHENTICATE_STATUS_SUCCESS;
				$response->error_message	= '';
				$response->username = $user->username;
				return true;
			}
			else{
				$response->status = JAUTHENTICATE_STATUS_FAILURE;
				$response->error_message = JText::_('NOT_LINKED');
				return false;
			}
		}
	 }
Ejemplo n.º 5
0
	function onBeforeDisplayContent( &$article, &$params, $limitstart ){
		if(!file_exists(JPATH_SITE.DS.'plugins'.DS.'system'.DS.'myApiConnectFacebook.php') || (!array_key_exists('category',$article) && !isset($params->showK2Plugins)  )){ return; }
		
		//this may fire fron a component other than com_content
		if((@$article->id != '') && (@$_POST['fb_sig_api_key'] == '')){
			$doc = & JFactory::getDocument();
			
			$plugin = & JPluginHelper::getPlugin('content', 'myApiSend');

			// Load plugin params info
			$myapiparama = new JParameter($plugin->params);
			
			$send_sections 		= $myapiparama->get('send_sections');
			$send_categories 	= $myapiparama->get('send_categories');
			$send_show_on 		= $myapiparama->get('send_show_on');
			$layout_style 		= $myapiparama->get('layout_style');
			$show_faces 		= $myapiparama->get('show_faces');
			$color_scheme 		= $myapiparama->get('color_scheme');
			$verb 				= $myapiparama->get('verb');
			$width 				= $myapiparama->get('width');
			$send_style 		= $myapiparama->get('send_style');
			$font 				= $myapiparama->get('send_font');
			$ref 				= $myapiparama->get('send_ref');
			$show_send 			= $myapiparama->get('send_send');
			$position			= $myapiparama->get('position','myApiShareTop');
			$send_show 			= false;
		
			$facebook = plgSystemmyApiConnect::getFacebook();
			
			if(isset($article->sectionid)){
				if( is_array($send_sections) ){	
					foreach($send_sections as $id){ if($id == $article->sectionid) $send_show = true;  }
				}
				elseif($send_sections == $article->sectionid) $send_show = true;
			}
			
			if(isset($article->category)){
				if( is_array($send_categories) ){	
					foreach($send_categories as $id){ if($id == $article->category) $send_show = true; }
				}
				elseif($send_categories == $article->category) $send_show = true;
			}
			
			if(($send_show) || ($send_show_on == 'all')){
				require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
				
				if(isset($article->slug)){
					require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
					$link = ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid);
				}elseif(method_exists('K2HelperRoute','getItemRoute')){
					$link = K2HelperRoute::getItemRoute($article->id.':'.urlencode($article->alias),$article->catid.':'.urlencode($article->category->alias));
				}else{
					error_log('myApi unable to calculate link for the article id '.$article->id);
					return;
				}
				$u =& JURI::getInstance( JURI::base().$link );
				$port 	= ($u->getPort() == '') ? '' : ":".$u->getPort();
				$link = 'http://'.$u->getHost().$port.$u->getPath().'?'.$u->getQuery();
				$button	= '<fb:send href="'.$link.'" colorscheme="'.$color_scheme.'" font="'.$font.'" ref="'.$ref.'"></fb:send>';
		
				require_once(JPATH_SITE.DS.'plugins'.DS.'system'.DS.'myApiDom.php');
				$article->text = myApiButtons::addToTable($article->text,$position,$button);
			}
		}
	}
Ejemplo n.º 6
0
	function save_myApiTabs(){
		$post 		= JRequest::get('post');	
		$facebook 	= plgSystemmyApiConnect::getFacebook();
		try{
			jimport( 'joomla.application.menu' );
			$data['tab_default_name']	= $post['params']['tab_name'];
			$data['profile_tab_url'] 	= JRoute::_(JURI::root()."index.php?Itemid=".$post['params']['tab_url']);
			$data['edit_url'] = $data['profile_tab_url'];
			$app_update = $facebook->api(array('method' => 'admin.setAppProperties','access_token' => $facebook->getAppId().'|'.$facebook->getApiSecret(),'properties'=> json_encode($data)));
			$this->setRedirect( 'index.php?option=com_myapi&view=plugin&plugin=myApiTabs',JText::_('TAB_SAVED'));
		}catch (FacebookApiException $e) {
			$this->setRedirect( 'index.php?option=com_myapi&view=plugin&plugin=myApiTabs',JText::_('TAB_SAVED_ERROR').$e);
		}
	}
Ejemplo n.º 7
0
	function newUser()
	{
		global $mainframe;

		$return = base64_decode(JRequest::getVar('return',''));
		// Get required system objects
		$user 		= clone(JFactory::getUser());
		$pathway 	=& $mainframe->getPathway();
		$config		=& JFactory::getConfig();
		$authorize	=& JFactory::getACL();
		$document   =& JFactory::getDocument();

		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		// Initialize new usertype setting
		$newUsertype = $usersConfig->get( 'new_usertype' );
		if (!$newUsertype) {
			$newUsertype = 'Registered';
		}
		
		global $fbUser;
		if(!is_object($fbUser)){
			require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_myapi'.DS.'models'.DS.'facebook.php';
			$facebookmodel = new myapiModelfacebook;  //Bring the myAPI facebook model
			$fbUser = $facebookmodel->getLoggedInUser();
		}
		
		if($fbUser['username'] != ''){
			$newuserName = $fbUser['username'];
		}else{
			$newuserName = str_replace(' ', '',$fbUser['name']);
		}
		
		$db = JFactory::getDBO();
		$uniqueUsername = false;
		$i = 0;
		
		while(!$uniqueUsername){
			$tryUsername = $newuserName;
			if($i >= 1){
				$tryUsername = $tryUsername.$i;	
			}
			
			$query = "SELECT COUNT(".$db->nameQuote('id').") FROM ".$db->nameQuote('#__users')." WHERE ".$db->nameQuote('username')." = ".$db->quote($tryUsername);
			$db->setQuery($query);
			$count = $db->loadResult();
			if($count == 0){
				$uniqueUsername = true;
				$newuserName = $tryUsername;
			}
				$i++;
			
		}
		
		jimport('joomla.user.helper');
		$newUser['name'] = $fbUser['name'];
		$newUser['username'] = $newuserName;
		$newUser['password'] = $newUser['password2'] = JUserHelper::genRandomPassword();
		$newUser['email'] = $fbUser['email'];
		
		// Bind the post array to the user object
		if (!$user->bind( $newUser, 'usertype' )) {
			$message = $user->getError();
			$this->setRedirect($return,$message);
		}
		
		// Set some initial user values
		$user->set('id', 0);
		$user->set('usertype', $newUsertype);
		$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

		$date =& JFactory::getDate();
		$user->set('registerDate', $date->toMySQL());

		// If user activation is turned on, we need to set the activation information
		$useractivation = $usersConfig->get( 'useractivation' );
		
		// If there was an error with registration, set the message and display form
		if ( $result = !$user->save() ){
			$message = $user->getError();
			$this->setRedirect($return,$message);
		}elseif($fbUser['id'] != ''){
			$db = JFactory::getDBO();
			$facebook = plgSystemmyApiConnect::getFacebook();
			$facebookSession = $facebook->getSession();
			$query = "INSERT INTO ".$db->nameQuote('#__myapi_users')." (userId,uid,access_token) VALUES(".$db->quote($user->id).",".$db->quote($fbUser['id']).",".$db->quote($facebookSession['access_token']).")";
			$db->setQuery($query);
			$db->query();
			
			//Sync Community Builder
			$sql_sync = "INSERT IGNORE INTO #__comprofiler(id,user_id) SELECT id,id FROM #__users WHERE #__users.id =".$db->Quote($user->id);
			$db->setQuery($sql_sync);
			$db->query();
			
			// Send registration confirmation mail
			$password = $newUser['password'];
			$password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
			myapiController::_sendMail($user, $password);
	
			$message = JText::_( 'LOGGED_IN_FACEBOOK' );
			
			$options['fake_array'] = "This mainframe->login needs and array passed to it";
			$error = $mainframe->login($fbUser['id'],$options);
			$user = JFactory::getUser();
			
			JRequest::setVar('K2UserForm',$a = 1);
			JRequest::setVar('gender',$a = substr($fbUser['gender'],0,1)); 
			JRequest::setVar('url',$a = $fbUser['link']);
			JRequest::setVar('description',$a = $fbUser['bio']);
			
			$dispatcher =& JDispatcher::getInstance();
			$dispatcher->trigger('onAfterStoreUser', array($user->getProperties(), true, $result,''));
			
			MyapiController::syncPhoto($fbUser['id']);
			$this->setRedirect($return,$message);
		}else{
			$this->setRedirect($return,JText::_('NO_UID_FOUND'));
		}
	}
Ejemplo n.º 8
0
	function _myApiTabs(){
		$facebook = plgSystemmyApiConnect::getFacebook();
		$pageLink = 'http://www.facebook.com/apps/application.php?id='.$facebook->getAppId();
		$sideContent = JText::sprintf('MYAPITABS_SIDE',$pageLink).'<br />'.JHTML::_('image', 'plugins/system/addtab.png', null);
		$this->assignRef('aside',$sideContent);
	}
Ejemplo n.º 9
0
	function getLoggedInUserLikes() {
		$facebook = plgSystemmyApiConnect::getFacebook();
		try {
		  $likes = $facebook->api('/me/likes');
		  
		} catch (FacebookApiException $e) {
		  error_log($e);
		  return false;
		}
		return $likes;
	}
Ejemplo n.º 10
0
 **   myApi_fbfan is free software: you can redistribute it and/or modify   **
 **   it under the terms of the GNU General Public License as published by  **
 **   the Free Software Foundation, either version 3 of the License, or	    **	
 **   (at your option) any later version.                                   **
 **                                                                         **
 **   myApi_fbfan is distributed in the hope that it will be useful,	    **
 **   but WITHOUT ANY WARRANTY; without even the implied warranty of	    **
 **   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
 **   GNU General Public License for more details.                          **
 **                                                                         **
 **   You should have received a copy of the GNU General Public License	    **
 **   along with myApi_fbfan.  If not, see <http://www.gnu.org/licenses/>.	**
 **                                                                         **			
 *****************************************************************************/

if(!class_exists('plgSystemmyApiConnect') || !$this->_facebook = plgSystemmyApiConnect::getFacebook())
	return;
			 
$classSfx 		= $params->get('moduleclass_sfx');
$width 			= $params->get('fan_width');
$height 		= $params->get('fan_height');
$header		 	= $params->get('fan_header');
$stream 		= $params->get('fan_stream');
$scheme 		= $params->get('fan_scheme');
$faces	 		= $params->get('fan_faces');
$pageLink 		= $params->get('fan_href');

if($pageLink == ''){
	require_once (dirname(__FILE__).DS.'helper.php');
	
	$plugin =& JPluginHelper::getPlugin('system', 'myApiConnect');
Ejemplo n.º 11
0
	function addFbJs($xid){
		global $fbAsyncInitJs;
		$facebook = plgSystemmyApiConnect::getFacebook();
		$app_id = $facebook->getAppId();
		$fbAsyncInitJs .= "var query".$xid." = FB.Data.query('select id from comment where xid=\"$xid\" ; '); query".$xid.".wait(function(result) { if(result.length > 0){ $('".$xid."commentLink').setHTML('".JText::_('ADD_COMMENT')." ('+result.length+')'); } });";	
	}
Ejemplo n.º 12
0
$query 	= ($u->getQuery() == '') ? '' : '?'.$u->getQuery();
$redirect_login	= base64_encode($host->getScheme().'://'.$host->getHost().$port.$u->getPath().$query); 

if($user->guest){
	$joomla_login = $params->get('login_joomlaLogin');
	$loginText = $params->get('login_button_text');
	require(JModuleHelper::getLayoutPath('mod_myapi_fbLogin','guest'));	
	
}else{
	$unlink	= $params->get('login_unlink','0');
	
	$db = JFactory::getDBO();
	$query = "SELECT ".$db->nameQuote('uid')." FROM ".$db->nameQuote('#__myapi_users')." WHERE userId =".$db->quote($user->id);
	$db->setQuery($query);
	$db->query();
	$num_rows = $db->getNumRows();
	if($num_rows == 0){
		$linked = false;
		$facebook = plgSystemmyApiConnect::getFacebook();
		$loginUrl = $facebook->getLoginUrl(array('next' => JURI::base().'index.php?option=com_myapi&task=newLink&return='.$redirect_login ));
		$linkText = $params->get('login_link_text');
	}
	else { 
		$linked = true; 
		//Get User Avatar
		$avatar = $myApiModel->getAvatar();
	}
	require(JModuleHelper::getLayoutPath('mod_myapi_fbLogin','user'));	
}

?>