Exemple #1
0
 public static function unsubscribeall($subscriber, $subscriberId, $cle = '')
 {
     $my = JFactory::getUser();
     if ((!empty($subscriberId) and !empty($cle)) || !empty($my->id)) {
         if (md5($subscriber->email) == $cle || !empty($my->id)) {
             //we unsubscribe the user to all lists
             $db = JFactory::getDBO();
             $query = 'SELECT * FROM `#__jnews_lists`';
             $query .= ' WHERE `id` IN (SELECT `list_id` FROM `#__jnews_listssubscribers` WHERE `subscriber_id`=' . $subscriberId . ' AND `unsubscribe`=0)';
             $db->setQuery($query);
             $listsO = $db->loadObjectList();
             if (!empty($listsO)) {
                 foreach ($listsO as $key => $list) {
                     //we send the unsubscription notification to the subscriber if it is turn to yes
                     if ($list->unsubscribesend == 1) {
                         jNews_ProcessMail::sendUnsubcribeEmail($subscriber, $subscriberId, $list);
                     }
                     //we send the unsubscription notification to the list owner if it is turn to yes
                     if ($GLOBALS[JNEWS . 'level'] > 2 && $list->unsubscribenotifyadmin == 1 && !empty($list->notifyadminmsg) && !empty($list->owner)) {
                         $my = JFactory::getUser($list->owner);
                         jNews_ProcessMail::sendNotification($list->notifyadminmsg, $subscriber, $my, $list, JNEWS_SITE_NAME . ' ' . _JNEWS_UNSUBS_NOTIFYSUBJECT);
                     }
                     if (!empty($GLOBALS[JNEWS . 'unsubscribe_notification'])) {
                         $listOfAdminA = explode(',', $GLOBALS[JNEWS . 'unsubscribe_notification']);
                         if (!empty($listOfAdminA)) {
                             foreach ($listOfAdminA as $oneAdmin) {
                                 if (empty($oneAdmin)) {
                                     continue;
                                 }
                                 $owner = new stdClass();
                                 $owner->name = $oneAdmin;
                                 $owner->email = $oneAdmin;
                                 jNews_ProcessMail::sendNotification(_JNEWS_UNSUBSCRIBE_ADMIN_NOTIFICATION, $newSubscriber, $owner, $list, JNEWS_SITE_NAME . ' ' . _JNEWS_UNSUBS_NOTIFYSUBJECT);
                             }
                         }
                     }
                 }
             }
             $query = 'UPDATE `#__jnews_listssubscribers` SET `unsubscribe`=1, `unsubdate`=' . time() . ' WHERE `subscriber_id`=' . $subscriberId;
             $db->setQuery($query);
             $result = $db->query();
         }
     }
     return $result;
 }