Пример #1
0
 function subscribe($id, $subscriber_info, $attributes, $mod_jinc = 'false', $notices = array())
 {
     $user = JFactory::getUser();
     if (!$user->authorise('jinc.subscribe', 'com_jinc.newsletter.' . $id)) {
         $this->setError('COM_JINC_ERR011');
         return false;
     }
     jincimport('core.newsletterfactory');
     $ninstance = NewsletterFactory::getInstance();
     if (!($newsletter = $ninstance->loadNewsletter($id, true))) {
         $this->setError('COM_JINC_ERR005');
         return false;
     }
     $suspended = $newsletter->get('suspended');
     if ($suspended == SUSPEND_SUBSCRIPTION || $suspended == SUSPEND_BOTH) {
         $this->setError('COM_JINC_ERR051');
         return false;
     }
     $notice_id = $newsletter->get('notice_id');
     if ($notice_id > 0) {
         if (!in_array($notice_id, $notices)) {
             $this->setError('COM_JINC_ERR026');
             return false;
         }
     }
     if ($newsletter->get('captcha') > CAPTCHA_NO) {
         include_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'securimage' . DIRECTORY_SEPARATOR . 'securimage.php';
         $captcha_code = JRequest::getString('captcha_code', '');
         $securimage = new Securimage();
         if ($mod_jinc == 'true') {
             $securimage->setSessionPrefix('mod_jinc');
         }
         if ($securimage->check($captcha_code) == false) {
             $this->setError('COM_JINC_ERR016');
             return false;
         }
     }
     $subscriber_info['waiting'] = false;
     if (!$newsletter->subscribe($subscriber_info, $attributes)) {
         $this->setError($newsletter->getError());
         return false;
     }
     if ($newsletter->getType() == NEWSLETTER_PUBLIC_NEWS) {
         $this->setState('message', JText::_('COM_JINC_INF008'));
     } else {
         $this->setState('message', JText::_('COM_JINC_INF003'));
     }
     return true;
 }