Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Newsletter_Block_Subscribe
  • Mage_Newsletter_Helper_Data
  • Mage_Newsletter_ManageController
  • Mage_Newsletter_Model_Message
  • Mage_Newsletter_Model_Mysql4_Problem
  • Mage_Newsletter_Model_Mysql4_Problem_Collection
  • Mage_Newsletter_Model_Mysql4_Queue
  • Mage_Newsletter_Model_Mysql4_Queue_Collection
  • Mage_Newsletter_Model_Mysql4_Subscriber
  • Mage_Newsletter_Model_Mysql4_Subscriber_Collection
  • Mage_Newsletter_Model_Mysql4_Template
  • Mage_Newsletter_Model_Mysql4_Template_Collection
  • Mage_Newsletter_Model_Observer
  • Mage_Newsletter_Model_Problem
  • Mage_Newsletter_Model_Queue
  • Mage_Newsletter_Model_Resource_Problem
  • Mage_Newsletter_Model_Resource_Problem_Collection
  • Mage_Newsletter_Model_Resource_Queue
  • Mage_Newsletter_Model_Resource_Queue_Collection
  • Mage_Newsletter_Model_Resource_Subscriber
  • Mage_Newsletter_Model_Resource_Subscriber_Collection
  • Mage_Newsletter_Model_Resource_Template
  • Mage_Newsletter_Model_Resource_Template_Collection
  • Mage_Newsletter_Model_Session
  • Mage_Newsletter_Model_Subscriber
  • Mage_Newsletter_Model_Template
  • Mage_Newsletter_Model_Template_Filter
  • Mage_Newsletter_SubscriberController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Newsletter
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Newsletter subscribe controller
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Newsletter
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Newsletter_SubscriberController extends Mage_Core_Controller_Front_Action
 35: {
 36:     /**
 37:       * New subscription action
 38:       */
 39:     public function newAction()
 40:     {
 41:         if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) {
 42:             $session            = Mage::getSingleton('core/session');
 43:             $customerSession    = Mage::getSingleton('customer/session');
 44:             $email              = (string) $this->getRequest()->getPost('email');
 45: 
 46:             try {
 47:                 if (!Zend_Validate::is($email, 'EmailAddress')) {
 48:                     Mage::throwException($this->__('Please enter a valid email address.'));
 49:                 }
 50: 
 51:                 if (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_ALLOW_GUEST_SUBSCRIBE_FLAG) != 1 && 
 52:                     !$customerSession->isLoggedIn()) {
 53:                     Mage::throwException($this->__('Sorry, but administrator denied subscription for guests. Please <a href="%s">register</a>.', Mage::helper('customer')->getRegisterUrl()));
 54:                 }
 55: 
 56:                 $ownerId = Mage::getModel('customer/customer')
 57:                         ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
 58:                         ->loadByEmail($email)
 59:                         ->getId();
 60:                 if ($ownerId !== null && $ownerId != $customerSession->getId()) {
 61:                     Mage::throwException($this->__('This email address is already assigned to another user.'));
 62:                 }
 63: 
 64:                 $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
 65:                 if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
 66:                     $session->addSuccess($this->__('Confirmation request has been sent.'));
 67:                 }
 68:                 else {
 69:                     $session->addSuccess($this->__('Thank you for your subscription.'));
 70:                 }
 71:             }
 72:             catch (Mage_Core_Exception $e) {
 73:                 $session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage()));
 74:             }
 75:             catch (Exception $e) {
 76:                 $session->addException($e, $this->__('There was a problem with the subscription.'));
 77:             }
 78:         }
 79:         $this->_redirectReferer();
 80:     }
 81: 
 82:     /**
 83:      * Subscription confirm action
 84:      */
 85:     public function confirmAction()
 86:     {
 87:         $id    = (int) $this->getRequest()->getParam('id');
 88:         $code  = (string) $this->getRequest()->getParam('code');
 89: 
 90:         if ($id && $code) {
 91:             $subscriber = Mage::getModel('newsletter/subscriber')->load($id);
 92:             $session = Mage::getSingleton('core/session');
 93: 
 94:             if($subscriber->getId() && $subscriber->getCode()) {
 95:                 if($subscriber->confirm($code)) {
 96:                     $session->addSuccess($this->__('Your subscription has been confirmed.'));
 97:                 } else {
 98:                     $session->addError($this->__('Invalid subscription confirmation code.'));
 99:                 }
100:             } else {
101:                 $session->addError($this->__('Invalid subscription ID.'));
102:             }
103:         }
104: 
105:         $this->_redirectUrl(Mage::getBaseUrl());
106:     }
107: 
108:     /**
109:      * Unsubscribe newsletter
110:      */
111:     public function unsubscribeAction()
112:     {
113:         $id    = (int) $this->getRequest()->getParam('id');
114:         $code  = (string) $this->getRequest()->getParam('code');
115: 
116:         if ($id && $code) {
117:             $session = Mage::getSingleton('core/session');
118:             try {
119:                 Mage::getModel('newsletter/subscriber')->load($id)
120:                     ->setCheckCode($code)
121:                     ->unsubscribe();
122:                 $session->addSuccess($this->__('You have been unsubscribed.'));
123:             }
124:             catch (Mage_Core_Exception $e) {
125:                 $session->addException($e, $e->getMessage());
126:             }
127:             catch (Exception $e) {
128:                 $session->addException($e, $this->__('There was a problem with the un-subscription.'));
129:             }
130:         }
131:         $this->_redirectReferer();
132:     }
133: }
134: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0