function onAfterStoreUser($user, $isnew, $success, $msg)
 {
     if ($success === false) {
         return false;
     }
     if (strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)) == 'administrator') {
         $adminPath = strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13));
     } else {
         $adminPath = JPATH_ROOT;
     }
     if (!@(include_once $adminPath . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php')) {
         return;
     }
     include_once JNEWSPATH_CLASSN . 'class.jnews.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.subscribers.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.listssubscribers.php';
     jimport('joomla.html.parameter');
     $plugin =& JPluginHelper::getPlugin('user', 'jnewssyncuser');
     $params = new JParameter($plugin->params);
     $db =& JFactory::getDBO();
     $subscriber = null;
     $confirmed = 1;
     if ($user['block']) {
         $confirmed = 0;
     }
     $subscriber->email = trim(strip_tags($user['email']));
     if (!empty($user['name'])) {
         $subscriber->name = trim(strip_tags($user['name']));
     }
     if (empty($user['block'])) {
         $subscriber->confirmed = 1;
     }
     $subscriber->user_id = $user['id'];
     $subscriber->ip = jNews_Subscribers::getIP();
     $subscriber->receive_html = 1;
     $subscriber->confirmed = $confirmed;
     $subscriber->subscribe_date = jnews::getNow();
     $subscriber->language_iso = 'eng';
     $subscriber->timezone = '00:00:00';
     $subscriber->blacklist = 0;
     //check if the version of jnews is pro
     if ($GLOBALS[JNEWS . 'type'] == 'PRO') {
         $subscriber->column1 = '';
         $subscriber->column2 = '';
         $subscriber->column3 = '';
         $subscriber->column4 = '';
         $subscriber->column5 = '';
     }
     //end if check if the version is pro
     if (!$isnew and !empty($this->oldUser['email']) and $user['email'] != $this->oldUser['email']) {
         $d['email'] = $this->oldUser['email'];
         $infos = jNews_Subscribers::getSubscriberIdFromEmail($this->oldUser);
         $subscriber->id = $infos['subscriberId'];
     }
     if ($isnew) {
         //new registered user
         $status = jNews_Subscribers::saveSubscriber($subscriber, $subscriber->user_id, true);
         if (empty($subscriber->id)) {
             $subscriber->id = jNews_Subscribers::getSubscriberIdFromUserId($subscriber->user_id);
         }
         if (!$status) {
             return;
         }
         $listsToSubscribe = $params->get('lists', '');
         if (!empty($listsToSubscribe)) {
             $condition = ' WHERE `id` IN (' . $listsToSubscribe . ')';
         } else {
             $condition = ' WHERE `auto_add` > 0';
         }
         //get list ids of auto_add lists
         $query = 'SELECT `id`, `list_type`, `params` from `#__jnews_lists`' . $condition;
         $db->setQuery($query);
         $autoListId = $db->loadObjectList();
         $error = $db->getErrorMsg();
         if (!empty($error)) {
             echo $error;
             return false;
         } else {
             //use for masterlists
             $listsA = array();
             foreach ($autoListId as $autoId) {
                 if (!empty($autoId->params)) {
                     //use for masterlists
                     $listsA[] = $autoId->id;
                 } else {
                     //for non-masterlists
                     $subscriber->list_id = $autoId->id;
                     jNews_ListsSubs::saveToListSubscribers($subscriber);
                 }
                 if ($autoId->list_type == 2) {
                     $subscribe = array();
                     $subscribe[] = $autoId->id;
                     if (!empty($subscribe)) {
                         jNews_ListsSubs::subscribeARtoQueue($subscriber->id, $subscribe);
                     }
                 }
             }
             //end of foreach
         }
         if (!empty($listsA)) {
             //we check if the social class file exists for the implementation of master lists
             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                 if (class_exists('social')) {
                     $listidSubsA = array();
                     $masterListSubscriber = null;
                     //we check if configuration for master lists is enabled
                     if ($GLOBALS[JNEWS . 'use_masterlists']) {
                         if ($GLOBALS[JNEWS . 'type'] == 'PLUS' || $GLOBALS[JNEWS . 'type'] == 'PRO') {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //1 - MasterLists for all Potential Users
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 1, $listsA);
                             //2 - MasterLists for all Registered Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 2, $listsA);
                         }
                         if ($GLOBALS[JNEWS . 'type'] == 'PRO') {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //3 - MasterLists for all Front-end Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 3, $listsA);
                         }
                     }
                     $masterListSubscriber->id = $subscriber->id;
                     $masterListSubscriber->list_id = $listidSubsA;
                     jNews_ListsSubs::saveToListSubscribers($masterListSubscriber);
                 }
             }
         }
     } else {
         //confirmed registered user
         //			if(!empty($this->oldUser['block']) AND !empty($subscriber->confirmed)){
         if (empty($subscriber->id)) {
             $subscriber->id = jNews_Subscribers::getSubscriberIdFromUserId($subscriber->user_id);
         }
         plgUserjNewssyncuser::_confirmUserSubscription($subscriber->id);
         //			}
     }
     //endelse
     return true;
 }
Example #2
0
 function onAfterRoute()
 {
     $redirectlink = trim(JRequest::getString('redirectlink'));
     $fromSubscribe = JRequest::getVar('fromSubscribe', '');
     // this is either we have a redirect setup or we come from the module
     if (empty($fromSubscribe) || empty($redirectlink)) {
         return '';
     }
     if (strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)) == 'administrator') {
         $adminPath = strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13));
     } else {
         $adminPath = JPATH_ROOT;
     }
     if (!@(include_once $adminPath . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php')) {
         return;
     }
     include_once JNEWSPATH_CLASS . 'class.jnews.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.subscribers.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.listssubscribers.php';
     jimport('joomla.html.parameter');
     $db = JFactory::getDBO();
     $plugin = JPluginHelper::getPlugin('system', 'vmjnewssubs');
     $registry = new JRegistry();
     if (!method_exists($registry, 'loadString')) {
         $data = trim($plugin->params);
         $options = array('processSections' => false);
         if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
             $ini = JRegistryFormat::getInstance('INI');
             $obj = $ini->stringToObject($data, $options);
         } else {
             $obj = json_decode($data);
         }
         $registry->loadObject($obj);
     } else {
         $registry->loadString($plugin->params);
     }
     $params = $registry;
     $reqfield = $params->get('reqfield', 'user_email');
     $email = JRequest::getString('email');
     $reqvalue = $reqfield == 'user_email' ? $email : JRequest::get($reqfield);
     if (is_array($reqvalue)) {
         //if we find any no we do no
         if (empty($reqvalue)) {
             return '';
         }
         foreach ($reqvalue as $resultArVal) {
             if (empty($resultArVal)) {
                 return '';
             }
         }
     } else {
         if (empty($reqvalue) || empty($email) || in_array(strtolower($reqvalue), array('', '0', 'n', 'no', 'none', 'nein', 'non'))) {
             return;
         }
     }
     $user_id = JRequest::getInt('user_id');
     $email = trim(strip_tags($email));
     $fname = JRequest::getString('first_name', '');
     $mname = JRequest::getString('middle_name', '');
     $lname = JRequest::getString('last_name', '');
     $name = '';
     if (!empty($fname)) {
         $name .= $fname . ' ';
     }
     if (!empty($mname)) {
         $name .= $mname . ' ';
     }
     if (!empty($lname)) {
         $name .= $lname;
     }
     $name = trim($name);
     if (empty($name)) {
         $name = JRequest::getVar('username');
     }
     $subscriber = new stdClass();
     $subscriber->user_id = $user_id;
     $subscriber->name = $name;
     $subscriber->email = $email;
     $subscriber->ip = jNews_Subscribers::getIP();
     $subscriber->receive_html = 1;
     $subscriber->confirmed = $GLOBALS[JNEWS . 'require_confirmation'] == '1' ? 0 : 1;
     $subscriber->subscribe_date = time();
     $subscriber->language_iso = 'eng';
     $subscriber->timezone = '00:00:00';
     $subscriber->blacklist = 0;
     $subscriber->params = '';
     $subscriber->admin_id = 62;
     $status = jNews_Subscribers::saveSubscriber($subscriber, $user_id, true);
     if (!$status) {
         return;
     }
     $listsToSubscribe = $params->get('lists', '');
     $listsToSubscribe = str_replace(' ', '', $listsToSubscribe);
     if (!empty($listsToSubscribe)) {
         $condition = ' WHERE `id` IN (' . $listsToSubscribe . ')';
     } else {
         $condition = '';
     }
     $query = 'SELECT `id`, `list_type`,`params` from `#__jnews_lists`' . $condition;
     $db->setQuery($query);
     $lsidstoinsert = $db->loadObjectList();
     $error = $db->getErrorMsg();
     if (!empty($error)) {
         echo $error;
         return false;
     } else {
         //use for masterlists
         $listsA = array();
         foreach ($lsidstoinsert as $lsid) {
             $d['email'] = $subscriber->email;
             //get the subscriber id which is newly inserted
             jNews_Subscribers::getSubscriberIdFromEmail($d);
             //subscriber_id from the inserted subscriber
             if ($d['subscriberId'] > 0) {
                 $subscriber->id = $d['subscriberId'];
             } else {
                 $subscriber->id = $subscriber->user_id;
             }
             if (!empty($lsid->params)) {
                 //use for masterlists
                 $listsA[] = $lsid->id;
             } else {
                 //for non-masterlists
                 $subscriber->list_id = $lsid->id;
                 jNews_ListsSubs::saveToListSubscribers($subscriber);
             }
             if ($lsid->list_type == 2) {
                 $subscribe = array();
                 $subscribe[] = $lsid->id;
                 if (!empty($subscribe)) {
                     jNews_ListsSubs::subscribeARtoQueue($subscriber->id, $subscribe);
                 }
             }
         }
         //end of foreach
         if (!empty($listsA)) {
             //we check if the social class file exists for the implementation of master lists
             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                 if (class_exists('jNews_Social')) {
                     $listidSubsA = array();
                     $masterListSubscriber = new stdClass();
                     //we check if configuration for master lists is enabled
                     if ($GLOBALS[JNEWS . 'use_masterlists']) {
                         if ($GLOBALS[JNEWS . 'level'] > 1) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //1 - MasterLists for all Potential Users
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 1, $listsA);
                             //2 - MasterLists for all Registered Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 2, $listsA);
                         }
                         if ($GLOBALS[JNEWS . 'level'] > 2) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //3 - MasterLists for all Front-end Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 3, $listsA);
                         }
                     }
                     //we check first if $listidSubsA and if not empty we do the subscription to the lists
                     if (!empty($listidSubsA)) {
                         $masterListSubscriber->id = $subscriber->id;
                         $masterListSubscriber->list_id = $listidSubsA;
                         jNews_ListsSubs::saveToListSubscribers($masterListSubscriber);
                     }
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * This public static function will save entries to listSubscibers
  * @param object $subsListInfo subcriberInfo
  * -> user_id
  * ->array sub_list_id  all lists IDs
  * ->array subscribed only subscribed
  * ->acc_level
  */
 public static function updateSubscriptionToLists($suscription)
 {
     if (empty($suscription->sub_list_id)) {
         return false;
     }
     $db = JFactory::getDBO();
     $listidSubsA = array();
     //subscribe lists
     $listidUnsubsA = array();
     //unsubscribe lists
     $mainframe = JFactory::getApplication();
     //cehck if one of the list is attached to an auto-responder
     //if so make sure we subscribe to it
     $query = 'SELECT `followup_id` FROM `#__jnews_followup`  ';
     $query .= ' WHERE `list_id` IN ( ' . implode($suscription->sub_list_id, ',') . ')';
     $db->setQuery($query);
     $loadResultArray = $db->loadObjectList();
     $attachedList2AutoResponderA = jnews::convertObjectList2Array($loadResultArray);
     if (!empty($attachedList2AutoResponderA)) {
         foreach ($attachedList2AutoResponderA as $oneAutoList) {
             if (!in_array($oneAutoList, $suscription->sub_list_id)) {
                 $suscription->sub_list_id[] = $oneAutoList;
                 $suscription->subscribed[] = 1;
             }
         }
     }
     //get the current state of subscriptions
     $query = 'SELECT `unsubscribe`,`list_id` FROM `#__jnews_listssubscribers`  ';
     $query .= ' WHERE `subscriber_id`= ' . $suscription->user_id;
     $db->setQuery($query);
     $existingSubcriptionsA = $db->loadObjectList('list_id');
     foreach ($suscription->subscribed as $oneID => $checked) {
         $listID2 = (int) $suscription->sub_list_id[$oneID];
         if (isset($existingSubcriptionsA[$listID2])) {
             if ($existingSubcriptionsA[$listID2]->unsubscribe) {
                 //currently unsubscribed
                 if ($checked) {
                     $listidSubsA[] = $listID2;
                 }
             } else {
                 //already subscribed
                 if (!$checked) {
                     $listidUnsubsA[] = $listID2;
                 }
             }
         } else {
             if ($checked) {
                 $listidSubsA[] = $listID2;
             }
         }
     }
     //endfroeach
     //we check if frontend or not
     if (!$mainframe->isAdmin()) {
         //we check if current subscription is not empty
         if (!empty($listidSubsA)) {
             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                 //we check if the social class file exists for the implementation of master lists
                 if (class_exists('jNews_Social')) {
                     //we check if configuration for master lists is enabled
                     if ($GLOBALS[JNEWS . 'use_masterlists']) {
                         if ($GLOBALS[JNEWS . 'level'] > 1) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //1 - MasterLists for all Potential Users
                             $listidSubsA[] = jNews_Social::includeMasterListIds($suscription->user_id, 1, $listidSubsA);
                             //3 - MasterLists for all Registered Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($suscription->user_id, 2, $listidSubsA);
                         }
                         if ($GLOBALS[JNEWS . 'level'] > 2) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //3 - MasterLists for all Front-end Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($suscription->user_id, 3, $listidSubsA);
                         }
                         //we remove here the masterlistids from the $listidUnsubsA
                         //so that masterlist entries won't get updated to unsubscribe
                         foreach ($listidUnsubsA as $key => $lsidunsub) {
                             if (in_array($lsidunsub, $listidSubsA)) {
                                 unset($listidUnsubsA[$key]);
                             }
                         }
                     }
                 }
             }
         }
     }
     //update
     jNews_ListsSubs::_applyChangedSubscription($suscription->user_id, $listidSubsA, $listidUnsubsA);
     $allListsForAR = array();
     if (!empty($listidSubsA)) {
         foreach ($listidSubsA as $id) {
             $allListsForAR[$id] = true;
         }
     }
     if (!empty($listidUnsubsA)) {
         foreach ($listidUnsubsA as $id) {
             $allListsForAR[$id] = false;
         }
     }
     if (empty($allListsForAR)) {
         return true;
     }
     $allListsForARkeysA = array_keys($allListsForAR);
     //we need to separate the ARs from the Lists (From the Subscriptions that were changed)
     $query = 'SELECT `id` FROM `#__jnews_lists` WHERE `list_type`=1 AND `id` IN (' . implode(',', $allListsForARkeysA) . ')';
     $db->setQuery($query);
     $loadResultArray = $db->loadObjectList();
     $listA = jnews::convertObjectList2Array($loadResultArray);
     if (!empty($listA)) {
         $changedARA = array_diff($allListsForARkeysA, $listA);
         //we get the records from  the followup table
         $query = 'SELECT * FROM `#__jnews_followup` WHERE `list_id` IN (' . implode(',', $listA) . ')';
         $db->setQuery($query);
         $followupLists = $db->loadObjectList();
         if (empty($followupLists)) {
             $query = 'SELECT `id` FROM `#__jnews_lists` WHERE `list_type`=2 AND `id` IN (' . implode(',', $allListsForARkeysA) . ')';
             $db->setQuery($query);
             $loadResultArray = $db->loadObjectList();
             $subscribeARA = jnews::convertObjectList2Array($loadResultArray);
             $query = 'SELECT `id` FROM `#__jnews_lists` WHERE `list_type`=2 AND `id` NOT IN (' . implode(',', $allListsForARkeysA) . ')';
             $db->setQuery($query);
             $loadResultArray = $db->loadObjectList();
             $unsubscribeARA = jnews::convertObjectList2Array($loadResultArray);
         } else {
             $subscribeARA = array();
             $unsubscribeARA = array();
             jNews_ListsSubs::_resolveListAndARConflicts($subscribeARA, $unsubscribeARA, $followupLists, $allListsForAR, $changedARA);
         }
     } else {
         $subscribeARA = $listidSubsA;
         $unsubscribeARA = $listidUnsubsA;
     }
     if (!empty($subscribeARA)) {
         jNews_ListsSubs::subscribeARtoQueue($suscription->user_id, $subscribeARA);
     }
     if (!empty($unsubscribeARA)) {
         jNews_ListsSubs::unsubscribeARtoQueue($suscription->user_id, $unsubscribeARA);
     }
     return true;
 }