コード例 #1
0
ファイル: frontend.php プロジェクト: naka211/kkvn
 public static function newSubscriber($name, $email, $confirm = false, $modsub = null)
 {
     $start_micritime = microtime(true);
     if (empty($name) || $name == _JNEWS_NAME) {
         $name = $email;
     }
     if (!empty($modsub->email) && (empty($modsub->name) || $modsub->name == _JNEWS_NAME)) {
         $modsub->name = $modsub->email;
     }
     $database = JFactory::getDBO();
     $acl = JFactory::getACL();
     $timezone = JRequest::getVar('timezone', '00:00:00');
     $lang6 = JRequest::getVar('lang', 'eng');
     $p = JRequest::getVar('passwordA', '');
     if (empty($modsub)) {
         $modsub = new stdClass();
         $modsub->red_subscription = 1;
         $modsub->mod_message = 0;
         $modsub->effect = 2;
         $receivedHTML = JRequest::getVar('receive_html', 0);
         $modsub->receive_html = isset($receivedHTML) && (is_bool($receivedHTML) && $receivedHTML || is_string($receivedHTML) && ($receivedHTML == 'true' || $receivedHTML == '1') || is_int($receivedHTML) && $receivedHTML) ? 1 : 0;
     }
     //get the listid variable from subscription via url
     $l = JRequest::getVar('listid', '');
     if (!empty($l)) {
         $result = jNews_Lists::doListsExists($l);
         if (!$result) {
             $message = jnews::printM('red', _JNEWS_SUBSCRIPTION_NOT_AVAIL_LIST);
             return $message;
             //return message if ever one of the listids enter does not exist
         }
         $result = array();
     }
     if ($GLOBALS[JNEWS . 'level'] > 2) {
         $column1 = JRequest::getVar('column1', '');
         $column2 = JRequest::getVar('column2', '');
         $column3 = JRequest::getVar('column3', '');
         $column4 = JRequest::getVar('column4', '');
         $column5 = JRequest::getVar('column5', '');
     }
     if ($GLOBALS[JNEWS . 'level'] > 1) {
         $security = JRequest::getVar('security_code', '');
         $captcha = JRequest::getVar('security_captcha', '');
     }
     $fromSubscribe = JRequest::getVar('fromSubscribe', '');
     $fromFrontend = JRequest::getVar('fromFrontend', '');
     if (!$modsub->red_subscription) {
         if ($modsub != null) {
             $fromFrontend = 1;
             $p = $modsub->passwordA;
             $name = $modsub->name;
             $email = $modsub->email;
         }
     }
     $canInsert = false;
     $message = '';
     if ($p == $GLOBALS[JNEWS . 'url_pass'] && empty($fromSubscribe) && empty($fromFrontend)) {
         $fromURL = true;
     } else {
         $fromURL = false;
     }
     if ($fromSubscribe) {
         $canInsert = true;
     } elseif ($fromFrontend) {
         //check if the request is coming from the frontend
         $canInsert = true;
     } elseif ($fromURL) {
         //check if the request to insert subscriber is directly from entering the URL
         $canInsert = true;
     } else {
         if (!$modsub->red_subscription) {
             if ($modsub->module_message || $modsub->effect == 2) {
                 $message = '<div id=mod_message>' . _JNEWS_URL_MES . '</div>';
             } else {
                 $message = '<div id=mod_message><span style="color:red;">' . _JNEWS_URL_MES . '</span></div>';
             }
         } else {
             $message .= jnews::printM('red', _JNEWS_URL_MES);
         }
     }
     if ($canInsert) {
         $newSubscriber = new stdClass();
         $newSubscriber->id = 0;
         $newSubscriber->user_id = 0;
         $newSubscriber->name = addslashes($name);
         $newSubscriber->email = $email;
         $newSubscriber->receive_html = isset($modsub->rhtml) ? $modsub->rhtml : (isset($modsub->receive_html) ? $modsub->receive_html : null);
         if ($GLOBALS[JNEWS . 'level'] > 2) {
             $newSubscriber->column1 = $column1;
             $newSubscriber->column2 = $column2;
             $newSubscriber->column3 = $column3;
             $newSubscriber->column4 = $column4;
             $newSubscriber->column5 = $column5;
         }
         if (!$modsub->red_subscription) {
             if ($modsub != null) {
                 $newSubscriber->name = addslashes($modsub->name);
                 $newSubscriber->email = $modsub->email;
                 if (!isset($newSubscriber->receive_html)) {
                     $newSubscriber->receive_html = isset($modsub->rhtml) ? $modsub->rhtml : (isset($modsub->receive_html) ? $modsub->receive_html : null);
                 }
                 if ($GLOBALS[JNEWS . 'level'] > 2) {
                     $newSubscriber->column1 = $modsub->column1;
                     $newSubscriber->column2 = $modsub->column2;
                     $newSubscriber->column3 = $modsub->column3;
                     $newSubscriber->column4 = $modsub->column4;
                     $newSubscriber->column5 = $modsub->column5;
                 }
             }
         }
         if ($GLOBALS[JNEWS . 'require_confirmation'] && !$confirm) {
             $newSubscriber->confirmed = 0;
         } else {
             $newSubscriber->confirmed = 1;
         }
         $newSubscriber->ip = jNews_Subscribers::getIP();
         $newSubscriber->blacklist = 0;
         $newSubscriber->timezone = $timezone;
         $newSubscriber->language_iso = $lang6;
         $newSubscriber->params = '';
         $newSubscriber->subscribe_date = time();
         jnews::objectHTMLSafe($newSubscriber);
         $confirmation = true;
         if (empty($modsub->subscribedlists)) {
             $modsub->subscribedlists = null;
         }
         //check if the subscirber already exist
         $data = array();
         $data['email'] = $newSubscriber->email;
         jNews_Subscribers::getSubscriberIdFromEmail($data);
         $alreadyExist = !empty($data['subscriberId']) ? true : false;
         $subscriberID = !empty($data['subscriberId']) ? $data['subscriberId'] : (!empty($newSubscriber->id) ? $newSubscriber->id : 0);
         if (!jNews_Subscribers::saveSubscriber($newSubscriber, $subscriberID, !$alreadyExist, $modsub->subscribedlists, $modsub->red_subscription)) {
             if (jNews_Subscribers::getSubscriberIdFromEmail($data)) {
                 $confirmation = false;
             } else {
                 return jnews::printM('blue', _JNEWS_ERROR);
             }
         }
         if ($GLOBALS[JNEWS . 'require_confirmation'] && $confirmation && !$confirm && !jNews_Subscribers::userConfirmed($newSubscriber->email)) {
             $needConfirm = true;
         } else {
             $needConfirm = false;
         }
         if ($needConfirm) {
             if (!$modsub->red_subscription) {
                 if ($modsubmodule_message || $modsub->effect == 2) {
                     $message = '<div id=mod_message>' . _JNEWS_COMFIRM_SUBSCRIPTION . '</div>';
                 } else {
                     $message = '<div id=mod_message>' . str_replace(array('<br />', '<br>'), '', _JNEWS_COMFIRM_SUBSCRIPTION) . '</div>';
                 }
                 // <span style="color:blue;"></span>
             } else {
                 $message = jnews::printM('blue', _JNEWS_COMFIRM_SUBSCRIPTION);
             }
         } else {
             //				$message2Show = $alreadyExist ? _JNEWS_SUCCESS_ALREADY_SUB : _JNEWS_SUCCESS_ADD_LIST;
             $message2Show = _JNEWS_SUCCESS_ADD_LIST;
             if (!$modsub->red_subscription) {
                 if ($modsub->module_message || $modsub->effect == 2) {
                     $message = '<div id=mod_message>' . $message2Show . '</div>';
                 } else {
                     $message = '<div id=mod_message><span class="color_green">' . $message2Show . '</span></div>';
                 }
             } else {
                 $message = jnews::printM('green', $message2Show);
             }
         }
     }
     $result['message'] = $message;
     $result['newsubscriber'] = $newSubscriber;
     //return $message;
     return $result;
 }