Beispiel #1
0
 /**
  * This public static function will save the subscriber information every new subscription or update subscription
  * @param listids - listid subscribed from the module if the saving of subscriber is via ajax
  * @param redirect - if to redirect the page or not
  */
 public static function saveSubscriber($subscriber, &$subscriberId, $newSubscriber = false, $listids = null, $redirect = false)
 {
     $subscriber->receive_html = isset($subscriber->receive_html) && (is_bool($subscriber->receive_html) && $subscriber->receive_html || is_string($subscriber->receive_html) && ($subscriber->receive_html == 'true' || $subscriber->receive_html == '1') || is_int($subscriber->receive_html) && $subscriber->receive_html) ? 1 : 0;
     $db = JFactory::getDBO();
     $xf = new jNews_Config();
     //dashboard summary
     jnews::objectHTMLSafe($subscriber);
     $d['confirm'] = true;
     $d['email'] = $subscriber->email;
     if (empty($subscriber->ip)) {
         $subscriber->ip = '';
     }
     if ($newSubscriber) {
         $query = "INSERT IGNORE INTO `#__jnews_subscribers` (`name`,`email` ,`ip`, `receive_html` , `confirmed` ";
         $query .= " , `subscribe_date` , `language_iso` , `timezone`, `blacklist`";
         //" , `params`";
         if ($GLOBALS[JNEWS . 'level'] > 2) {
             $query .= " , `column1`";
             $query .= " , `column2`";
             $query .= " , `column3`";
             $query .= " , `column4`";
             $query .= " , `column5`";
         }
         if (!empty($subscriber->user_id)) {
             $query .= " , `user_id` ";
         }
         $query .= ") VALUES (" . " '{$subscriber->name}' , " . " '{$subscriber->email}' , " . " '{$subscriber->ip}' , " . " '{$subscriber->receive_html}' , " . " '{$subscriber->confirmed}' , " . " '{$subscriber->subscribe_date}', " . " '{$subscriber->language_iso}', " . " '{$subscriber->timezone}', " . " '{$subscriber->blacklist}' ";
         if ($GLOBALS[JNEWS . 'level'] > 2) {
             //check if the version is pro
             //$query .=" '$subscriber->params' , ";
             $query .= ",";
             if (array_key_exists('column1', $subscriber)) {
                 $query .= " '{$subscriber->column1}',  ";
             } else {
                 $query .= " '',  ";
             }
             if (array_key_exists('column2', $subscriber)) {
                 $query .= " '{$subscriber->column2}',  ";
             } else {
                 $query .= " '',  ";
             }
             if (array_key_exists('column3', $subscriber)) {
                 $query .= " '{$subscriber->column3}',  ";
             } else {
                 $query .= " '',  ";
             }
             if (array_key_exists('column4', $subscriber)) {
                 $query .= " '{$subscriber->column4}',  ";
             } else {
                 $query .= " '',  ";
             }
             if (array_key_exists('column5', $subscriber)) {
                 $query .= " '{$subscriber->column5}'  ";
             } else {
                 $query .= " '' ";
             }
         }
         if (!empty($subscriber->user_id)) {
             $query .= " , " . intval($subscriber->user_id);
         }
         $query .= ")";
         $db->setQuery($query);
         $db->query();
         //get the subscriber id which is newly inserted
         //Update dashboard summary
         if (jNews_Subscribers::getSubscriberIdFromEmail($d)) {
             $d['confirm'] = false;
             $xf->plus('totalsubcribers0', 1);
             $xf->plus('act_totalsubcribers0', 1);
         }
         //subscriber_id from the inserted subscriber
         if ($d['subscriberId'] > 0) {
             $subscriberId = $d['subscriberId'];
             $subscriber->id = $d['subscriberId'];
         } else {
             $subscriber->id = 0;
             $subscriberId = 0;
         }
         //TODO: Add an option either to require confirmation during site registration once the sync users plugin is turn on
         //added condition  empty($subscriber->user_id) so that it will not send confirmation email during registration
         if ($newSubscriber && $GLOBALS[JNEWS . 'require_confirmation'] == '1' && empty($subscriber->user_id)) {
             //added $subscriber
             jNews_ProcessMail::sendConfirmationEmail($subscriber, $subscriberId);
         }
     } else {
         //Update Subscriber
         if (empty($subscriber->id)) {
             $subscriber->id =& $subscriberId;
         }
         $query = "UPDATE IGNORE `#__jnews_subscribers` SET ";
         $query .= " `name` = '{$subscriber->name}' , ";
         $query .= " `email` = '{$subscriber->email}' , ";
         if ($GLOBALS[JNEWS . 'level'] > 2) {
             if (!empty($subscriber->column1)) {
                 $query .= " `column1` = '{$subscriber->column1}' , ";
             }
             if (!empty($subscriber->column2)) {
                 $query .= " `column2` = '{$subscriber->column2}' , ";
             }
             if (!empty($subscriber->column3)) {
                 $query .= " `column3` = '{$subscriber->column3}' , ";
             }
             if (!empty($subscriber->column4)) {
                 $query .= " `column4` = '{$subscriber->column4}' , ";
             }
             if (!empty($subscriber->column5)) {
                 $query .= " `column5` = '{$subscriber->column5}' , ";
             }
         }
         $query .= " `receive_html` = {$subscriber->receive_html}  , ";
         $query .= " `confirmed` =  {$subscriber->confirmed}  , " . " `timezone` = '{$subscriber->timezone}' , ";
         $query .= " `language_iso` = '{$subscriber->language_iso}' , ";
         $query .= " `blacklist` = {$subscriber->blacklist} ";
         //$query.= " `params` = '$subscriber->params'  " .
         $query .= " WHERE `id` = {$subscriber->id} ";
         $db->setQuery($query);
         $db->query();
     }
     $subscriberInfo = jNews_ListsSubs::getListidsSubscribedInfo($subscriber->id, $listids, $redirect);
     return true;
 }