Пример #1
0
 function subscribe($pSubscribeHash)
 {
     // $notify = FALSE, $remind = FALSE ) {
     $ret = FALSE;
     if ($this->isValid()) {
         global $gBitSystem;
         global $gBitSmarty;
         global $gBitUser;
         // Check for duplicates
         $all_subs = $this->getSubscribers(TRUE);
         $duplicate = FALSE;
         foreach ($all_subs as $sub) {
             if ($sub['email'] == $pSubscribeHash['email']) {
                 $duplicate = TRUE;
                 $urlCode = $sub['sub_code'];
             } elseif (!empty($pSubscribeHash['user_id']) && $sub['user_id'] == $pSubscribeHash['user_id']) {
             }
         }
         $urlCode = !$duplicate ? md5(BitUser::genPass()) : $urlCode;
         $now = date("U");
         // Generate a code and store it and send an email  with the
         // URL to confirm the subscription put valid as 'n'
         if (!$duplicate) {
             if (@BitBase::verifyId($pSubscribeHash['user_id'])) {
                 // we have user_id subscribing, use the id, NULL the email
                 $subUserId = $pSubscribeHash['user_id'];
                 $subEmail = NULL;
             } else {
                 // we have user_id subscribing, use the id, NULL the email
                 $subUserId = NULL;
                 $subEmail = $pSubscribeHash['email'];
             }
             $query = "insert into `" . BIT_DB_PREFIX . "mail_subscriptions` (`content_id`, `user_id`, `email`,`sub_code`,`is_valid`,`subscribed_date`) VALUES (?,?,?,?,?,?)";
             $result = $this->mDb->query($query, array($this->mContentId, $subUserId, $subEmail, $urlCode, 'n', (int) $now));
         }
         if (!empty($pSubscribeHash['notify']) && $this->getField('validate_addr') == 'y' || !empty($pSubscribeHash['remind'])) {
             // Generate a code and store it and send an email  with the
             $gBitSmarty->assign('sub_code', $urlCode);
             $mail_data = $gBitSmarty->fetch('bitpackage:newsletters/confirm_newsletter_subscription.tpl');
             @mail($email, tra('Newsletter subscription information at') . ' ' . $gBitSystem->getConfig("bitmailer_from"), $mail_data, "From: " . $gBitSystem->getConfig("sender_email") . "\r\nContent-type: text/plain;charset=utf-8\r\n");
         }
         $ret = TRUE;
     }
     return $ret;
 }