Beispiel #1
0
 /**
  * Triggered when user logs into the site
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function onUserLogin($user, $options = array())
 {
     // Include main file.
     jimport('joomla.filesystem.file');
     $path = JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php';
     if (!JFile::exists($path)) {
         return;
     }
     // Include the foundry engine
     require_once $path;
     // Load the language string.
     Foundry::language()->load('plg_user_easysocial', JPATH_ADMINISTRATOR);
     // Check if Foundry exists
     if (!Foundry::exists()) {
         Foundry::language()->loadSite();
         echo JText::_('COM_EASYSOCIAL_FOUNDRY_DEPENDENCY_MISSING');
         return;
     }
     if (isset($user['status']) && $user['status'] && $user['type'] == 'Joomla') {
         //successful logged in.
         $my = JUser::getInstance();
         if ($id = intval(JUserHelper::getUserId($user['username']))) {
             $my->load($id);
         }
         $config = Foundry::config();
         $app = Foundry::table('App');
         $app->load(array('element' => 'users', 'group' => SOCIAL_TYPE_USER));
         $appParams = $app->getParams();
         $addStream = false;
         if ($appParams->get('stream_login', true)) {
             $addStream = true;
         }
         // do not add stream when user login from backend.
         $mainframe = JFactory::getApplication();
         // If this is the admin area, skip this.
         if ($mainframe->isAdmin()) {
             return;
         }
         // Only proceed if we need to add the stream
         if ($addStream) {
             $model = Foundry::model('Users');
             // Get the last login time the user previously logged in.
             $lastLogin = $model->getLastLogin($my->id);
             if ($lastLogin) {
                 $lastLogin->count = Foundry::isJoomla25() ? $lastLogin->count + 1 : $lastLogin->count;
                 if ($lastLogin->count >= 2 && $lastLogin->limit < $lastLogin->time) {
                     $addStream = false;
                 }
             }
         }
         if ($addStream) {
             $myUser = Foundry::user($my->id);
             $stream = Foundry::stream();
             $template = $stream->getTemplate();
             $template->setActor($my->id, SOCIAL_TYPE_USER);
             $template->setContext($my->id, SOCIAL_TYPE_USERS);
             $template->setVerb('login');
             // Set the stream to be public
             $template->setAccess('core.view');
             // Add the new template.
             $stream->add($template);
         }
     }
 }