Beispiel #1
0
 /**
  * Singleton method
  *
  * @param null
  * @return MageBridgeConnectorProfile
  */
 public static function getInstance()
 {
     static $instance;
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function display($tpl = null)
 {
     // Initialize the view
     $this->setTitle('Connectors');
     // Set buttons in the toolbar
     MageBridgeToolBarHelper::help('magebridge.connectors');
     JToolBarHelper::publishList();
     JToolBarHelper::unpublishList();
     JToolBarHelper::editListX();
     // Initialize common variables
     $application = JFactory::getApplication();
     $option = JRequest::getCmd('option') . '-connectors';
     // Handle the filters
     $filter_type = $application->getUserStateFromRequest($option . 'filter_type', 'filter_type', '', 'word');
     $filter_state = $application->getUserStateFromRequest($option . 'filter_state', 'filter_state', '', 'word');
     $filter_order = $application->getUserStateFromRequest($option . 'filter_order', 'filter_order', 'p.ordering', 'cmd');
     $filter_order_Dir = $application->getUserStateFromRequest($option . 'filter_order_Dir', 'filter_order_Dir', '', 'word');
     // Get data from the model
     $items = $this->get('Data');
     $total = $this->get('Total');
     $pagination = $this->get('Pagination');
     // filters
     $options = array(array('value' => '', 'text' => '- Select Type -'), array('value' => 'store', 'text' => 'Store Connectors'), array('value' => 'product', 'text' => 'Product Connectors'), array('value' => 'profile', 'text' => 'Profile Connectors'));
     $javascript = 'onchange="document.adminForm.submit();"';
     $lists['type'] = JHTML::_('select.genericlist', $options, 'filter_type', $javascript, 'value', 'text', $filter_type);
     $lists['state'] = JHTML::_('grid.state', $filter_state);
     // table ordering
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['order'] = $filter_order;
     // Prepare the items for display
     if (!empty($items)) {
         foreach ($items as $index => $item) {
             if ($item->type == 'product') {
                 $object = MageBridgeConnectorProduct::getInstance()->getConnectorObject($item);
             } else {
                 if ($item->type == 'profile') {
                     $object = MageBridgeConnectorProfile::getInstance()->getConnectorObject($item);
                 } else {
                     $object = MageBridgeConnectorStore::getInstance()->getConnectorObject($item);
                 }
             }
             if (is_object($object)) {
                 $item->enabled = $object->isEnabled();
             } else {
                 $item->enabled = false;
             }
             $item->edit_link = 'index.php?option=com_magebridge&view=connector&task=edit&cid[]=' . $item->id;
             $items[$index] = $item;
         }
     }
     $user = JFactory::getUser();
     $this->assignRef('user', $user);
     $this->assignRef('lists', $lists);
     $this->assignRef('items', $items);
     $this->assignRef('pagination', $pagination);
     parent::display($tpl);
 }
 public function modifyUserFields($user)
 {
     $connectors = MageBridgeConnectorProfile::getConnectors();
     if (!empty($connectors)) {
         foreach ($connectors as $connector) {
             if (isset($user['joomla_id'])) {
                 $user_id = $user['joomla_id'];
             } else {
                 if (isset($user['id'])) {
                     $user_id = $user['id'];
                 } else {
                     $user_id = null;
                 }
             }
             if ($user_id > 0) {
                 $user = $connector->modifyFields($user_id, $user);
             }
         }
     }
     return $user;
 }
Beispiel #4
0
 /**
  * Method to synchronize the user account with Magento
  *
  * @param array $user
  * @return array $data Data as returned by Magento
  */
 public function synchronize($user)
 {
     // Disable at user events
     if (isset($user['disable_events']) && $user['disable_events'] == 1) {
         return null;
     }
     MageBridgeModelDebug::getInstance()->notice("MageBridgeModelUser::synchronize() on user " . $user['email']);
     // Use the email if no username is set
     if (empty($user['username'])) {
         $user['username'] = $user['email'];
     }
     // Check on the users email
     if ($this->isValidEmail($user['email']) == false) {
         return false;
     }
     // Set the right ID
     $user['joomla_id'] = isset($user['id']) ? $user['id'] : 0;
     // Find some logic to divide the "name" into a "firstname" and "lastname"
     $user = MageBridgeUserHelper::convert($user);
     // Only set the password, when the password does not appear to be the encrypted version
     if (empty($user['password_clear'])) {
         if (isset($user['password']) && !preg_match('/^\\$/', $user['password']) && !preg_match('/^\\{SHA256\\}/', $user['password']) && !preg_match('/([a-z0-9]{32}):([a-zA-Z0-9]+)/', $user['password'])) {
             $user['password_clear'] = $user['password'];
         }
     }
     // Try to detect the password in this POST
     if (empty($user['password_clear'])) {
         $fields = array('password_clear', 'password', 'passwd');
         $jform = JFactory::getApplication()->input->get('jform', array(), 'post');
         foreach ($fields as $field) {
             $password = JFactory::getApplication()->input->getString($field, '', 'post');
             if (empty($password) && is_array($jform) && !empty($jform[$field])) {
                 $password = $jform[$field];
             }
             if (!empty($password)) {
                 $user['password_clear'] = $password;
                 break;
             }
         }
     }
     // Delete unusable fields
     unset($user['id']);
     unset($user['password']);
     unset($user['params']);
     unset($user['userType']);
     unset($user['sendEmail']);
     unset($user['option']);
     unset($user['task']);
     // Delete unusable empty fields
     foreach ($user as $name => $value) {
         if (empty($value)) {
             unset($user[$name]);
         }
     }
     // Encrypt the user-password for transfer through the MageBridge API
     if (isset($user['password_clear'])) {
         if (empty($user['password_clear']) || !is_string($user['password_clear'])) {
             unset($user['password_clear']);
         } else {
             $user['password_clear'] = MageBridgeEncryptionHelper::encrypt($user['password_clear']);
         }
     }
     // Add the Website ID to this user
     $user['website_id'] = MagebridgeModelConfig::load('website');
     // Add the default customer-group ID to this user (in case we need to create a new user)
     $user['default_customer_group'] = MagebridgeModelConfig::load('customer_group');
     // Add the customer-group ID to this user (based upon groups configured in #__magebridge_usergroups)
     $user['customer_group'] = MageBridgeUserHelper::getMagentoGroupId($user);
     // Make sure events are disabled on the Magento side
     $user['disable_events'] = 1;
     // Add the profile-connector data to this user
     $user = MageBridgeConnectorProfile::getInstance()->modifyUserFields($user);
     // Initalize the needed objects
     $bridge = MageBridgeModelBridge::getInstance();
     $register = MageBridgeModelRegister::getInstance();
     // Build the bridge and fetch the result
     $id = $register->add('api', 'magebridge_user.save', $user);
     $bridge->build();
     $data = $register->getDataById($id);
     return $data;
 }
Beispiel #5
0
 /**
  * Handle the event that is generated after a customer is saved in Magento (JSON-RPC)
  *
  * @param array $arguments
  *
  * @return int
  */
 public function mageCustomerSaveAfter($arguments = array())
 {
     // Check if this call is valid
     if (!isset($arguments['customer'])) {
         return false;
     }
     if (!isset($arguments['customer']['email'])) {
         return false;
     }
     // Fetch the right variables
     $customer = $arguments['customer'];
     if (isset($customer['addresses'][0][0])) {
         $address = $customer['addresses'][0][0];
         unset($customer['addresses']);
     } else {
         $address = array();
     }
     // Try to load the user through the Joomla! ID stored in Magento
     if (isset($customer['joomla_id'])) {
         $user = JFactory::getUser();
         $user->load($customer['joomla_id']);
     }
     // Try to load the user through its email-address
     if (!isset($user) || !isset($user->id) || !$user->id > 0) {
         $user = $this->getUser()->loadByEmail($customer['email']);
     }
     // Encrypt the user-password before continuing
     if (isset($customer['password'])) {
         $customer['password'] = MageBridge::decrypt($customer['password']);
     }
     // Start building the data-input for creating the Joomla! user
     if (!empty($customer['name']) && !empty($customer['email'])) {
         $data = array();
         // Include the received email
         if (!empty($customer['email'])) {
             $data['email'] = $customer['email'];
         }
         // Include the real name
         $data['name'] = $this->getRealname($user, $customer);
         // Include the username
         $data['username'] = $this->getUsername($user, $customer);
         // Set the firstname and lastname
         $data['magebridgefirstlast'] = array('firstname' => $customer['firstname'], 'lastname' => $customer['lastname']);
         // Include the password
         if (!empty($customer['password'])) {
             $data['password'] = $customer['password'];
             $data['password2'] = $customer['password'];
         }
         // Activate this account, if it's also activated in Magento
         if (isset($customer['is_active'])) {
             if ($customer['is_active'] == 1) {
                 $data['activation'] = '';
                 $data['block'] = 0;
             } else {
                 $data['block'] = 1;
             }
         }
         // Add the usergroup ID to this user (based upon groups configured in #__magebridge_usergroups)
         $usergroups = is_array($user->groups) ? $user->groups : array();
         $customer['usergroup'] = MageBridgeUserHelper::getJoomlaGroupIds($customer, $usergroups);
         //MageBridgeModelDebug::getInstance()->trace("Customer group", $customer['usergroup']);
         if (!empty($customer['usergroup'])) {
             $user->groups = $customer['usergroup'];
         }
         // If this user did not exist yet, create it
         if ($this->params->get('autocreate', 1) == 1 && ($user == false || $user->id == 0)) {
             $user = $this->getUser()->create($data, true);
             if (is_object($user) && $user->id > 0) {
                 // Save the user through the Profile Connectors
                 $profile = new MageBridgeConnectorProfile();
                 $profile->onSave($user, $customer, $address);
                 // Return the new user-ID
                 return $user->id;
             } else {
                 return 3;
             }
         }
         // Bind the data to the current user
         if ($user->bind($data) == false) {
             return false;
         }
         // Save the user
         if ($user->save() == false) {
             return false;
         }
         // Save the user through the Profile Connectors
         $profile = new MageBridgeConnectorProfile();
         $profile->onSave($user, $customer, $address);
         // Run the newsletter plugins
         if (isset($customer['is_subscribed'])) {
             JPluginHelper::importPlugin('magebridgenewsletter');
             JFactory::getApplication()->triggerEvent('onNewsletterSubscribe', array($user, (bool) $customer['is_subscribed']));
         }
         // Return the user ID for convenience
         return $user->id;
     }
     return false;
 }
 /**
  * Handle task queues
  * 
  * @access private
  * @param null
  * @return null
  */
 private function handleQueue()
 {
     // Get the current session
     $session = JFactory::getSession();
     // Check whether some request is in the queue
     $tasks = $session->get('com_magebridge.task_queue');
     if (!empty($tasks) && is_array($tasks)) {
         foreach ($tasks as $task) {
             if ($task == 'cbsync') {
                 $cb = MageBridgeConnectorProfile::getConnector('cb');
                 $cb->synchronize(JFactory::getUser()->id);
             }
             if ($task == 'jomsocialsync') {
                 $jomsocial = MageBridgeConnectorProfile::getConnector('jomsocial');
                 $jomsocial->synchronize(JFactory::getUser()->id);
             }
         }
     }
     // Add things to the queue, because some bastard extensions do not use events properly
     $tasks = array();
     // Add a CB profile-sync
     if ($this->getParam('spoof_cb_events')) {
         if (JRequest::getCmd('option') == 'com_comprofiler' && JRequest::getCmd('task') == 'saveUserEdit' && JFactory::getUser()->id == JRequest::getInt('id', 0, 'post')) {
             $tasks[] = 'cnsync';
         }
     }
     // Add a JomSocial profile-sync
     if ($this->getParam('spoof_jomsocial_events')) {
         if (JRequest::getCmd('option') == 'com_community' && JRequest::getCmd('view') == 'profile' && in_array(JRequest::getCmd('task'), array('edit', 'editDetails')) && JRequest::getCmd('action', null, 'post') == 'save') {
             $tasks[] = 'jomsocialsync';
         }
     }
     // Save the task queue in the session
     $session->set('com_magebridge.task_queue', $tasks);
 }