function display($tpl = null) { /* * Get the info about current user. * Check if the user is admin. */ $alias = JRequest::getString('alias', null); if (!empty($alias)) { $newslettter = NewsletterHelper::getByAlias($alias); $this->assignRef('newsletter', $newslettter); parent::display(); } }
/** * Renders the newsletter for an subscriber. * * @return void * @since 1.0 */ public function render() { /* * Get the info about current user. * Check if the user is admin. */ //TODO: Get the admin session... /* * Let's render the newsletter. * If subscriber's email is provided then add info about this user * to environment */ $newsletterId = JRequest::getVar('newsletter_id'); $type = JRequest::getVar('type'); $email = urldecode(JRequest::getVar('email')); $alias = JRequest::getString('alias', null); if (!empty($alias)) { $newslettter = NewsletterHelper::getByAlias($alias); $newsletterId = $newslettter['newsletter_id']; } if (empty($newsletterId)) { echo json_encode(array('state' => '0', 'error' => 'The newsletter id is absent')); return; } if (empty($type)) { echo json_encode(array('state' => '0', 'error' => "The type is absent")); return; } $mailer = new MigurMailer(); // emulate user environment SubscriberHelper::saveRealUser(); SubscriberHelper::emulateUser(array('email' => $email)); // render the content of letter for each user $res = $mailer->render(array('type' => $type, 'newsletter_id' => $newsletterId)); SubscriberHelper::restoreRealUser(); echo $res; die; // echo json_encode(array( // 'state' => '1', // 'error' => $res, // )); }