Preview Newsletter template

@return void|$this
436206
public function execute()
    {
        $encodedId = $this->_request->getParam('id');

        /** @var \Shockwavemk\Mail\Base\Model\Mail $_mail */
        $mail = $this->_objectManager->get('\Shockwavemk\Mail\Base\Model\Mail');
        $mail->load(base64_decode($encodedId));

        $encodedPath = $this->_request->getParam('path');
        $localPath = base64_decode($encodedPath);

        /** @var \Shockwavemk\Mail\Base\Model\Mail\Attachment[] $attachments */
        $attachments = $mail->getAttachments();

        /** @var \Shockwavemk\Mail\Base\Model\Mail\Attachment $attachment */
        /** @noinspection IsEmptyFunctionUsageInspection */
        if(empty($attachment = $attachments[$localPath])) {

            $this->messageManager->addError(
                __('Sorry, there was an error getting requested content. Please contact the store owner.')
            );

            return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
        }

        try
        {
            $this->_processDownload($attachment);
            exit(0);
        }
        catch (\Exception $e)
        {
            $this->messageManager->addError(
                __('Sorry, there was an error getting requested content. Please contact the store owner: ' . $e->getMessage())
            );
        }

        return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
    }
1297687
public function create()
    {
        /**
         * @var NewsletterSubscription $newsletterSubscription
         */
        $classNamespace = $this->getEntityNamespace();
        $newsletterSubscription = new $classNamespace();
        $newsletterSubscription
            ->setEnabled(true)
            ->setCreatedAt($this->now());

        return $newsletterSubscription;
    }
1190555
public function display()
    {
        \OWeb\manage\Events::getInstance()->sendEvent('DisplayContent_Start@OWeb\manage\Template');
        echo $this->content;
        \OWeb\manage\Events::getInstance()->sendEvent('DisplayContent_End@OWeb\manage\Template');
    }
482398
public function render_email_address() {
		$placeholder = get_bloginfo( 'admin_email' );
		$current = $this->options->email_address;
		$value = $placeholder === $current ? '' : $current;

		echo $this->template->render( // WPCS: XSS OK.
			'options/email-address.php',
			compact( 'placeholder', 'value' )
		);
	}
1252214
private function generateTemplate()
    {
        $relPath = '/Resources/views/';
        $this->renderFiles(
            $this->skeletonDir . $relPath,
            $this->getTemplateDir($this->bundle),
            array('bundle' => $this->bundle, 'demosite' => $this->demosite, 'shortBundleName' => $this->shortBundleName, 'isV4' => $this->isSymfony4()),
            true
        );

        if (!$this->demosite) {
            // Layout
            $this->removeFile($this->getTemplateDir($this->bundle) . '/Layout/_mobile-nav.html.twig');
            $this->removeFile($this->getTemplateDir($this->bundle) . '/Layout/_demositemessage.html.twig');
        }

        $this->assistant->writeLine('Generating template files : <info>OK</info>');
    }
1371603
public function previewTemplateWithEmail($template, $send_email) {
        $data = [ ];
        $data['template'] = $template;
        $data['send_email'] = $send_email;

        $result = $this->apiPost('preview', $data);
        return $result;
    }
1193544
public function render()
    {
        parent::render();

        $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
        $oNewsletter = oxNew(\OxidEsales\Eshop\Application\Model\Newsletter::class);

        if (isset($soxId) && $soxId != "-1") {
            $oNewsletter->load($soxId);
            $this->_aViewData["edit"] = $oNewsletter;
        }

        // generate editor
        $this->_aViewData["editor"] = $this->_generateTextEditor(
            "100%",
            255,
            $oNewsletter,
            "oxnewsletter__oxtemplate"
        );

        return "newsletter_main.tpl";
    }
185462
def preview_to(recipient)
      @newsletter = build_newsletter
      mail = build_mail
      mail.to = recipient.email
      replace_and_send_mail_safely(mail, recipient)
    end
267758
public function save()
    {
        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");
        $aParams['oxnewsletter__oxshopid'] = \OxidEsales\Eshop\Core\Registry::getConfig()->getShopId();

        $oNewsletter = oxNew(\OxidEsales\Eshop\Application\Model\Newsletter::class);
        if ($soxId != "-1") {
            $oNewsletter->load($soxId);
        } else {
            $aParams['oxnewsletter__oxid'] = null;
        }

        $oNewsletter->assign($aParams);
        $oNewsletter->save();

        // set oxid if inserted
        $this->setEditObjectId($oNewsletter->getId());
    }
637607
public function edit()
    {
        if (!userHasPermission('admin:blog:post:' . $this->blog->id . ':edit')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Fetch and check post
        $iPostId = (int) $this->uri->segment(6);

        $this->data['post'] = $this->blog_post_model->getById($iPostId);

        if (!$this->data['post']) {

            show404();
        }

        // --------------------------------------------------------------------------

        //  Set method info
        $this->data['page']->title = 'Edit ' . $this->data['postName'] . ' &rsaquo; ' . $this->data['post']->title;

        // --------------------------------------------------------------------------

        //  Process POST
        if ($this->input->post()) {

            //  Are we running in preview mode?
            $bIsPreview = (bool) $this->input->post('isPreview');

            //  Only validate non-previews
            if (empty($bIsPreview)) {

                $oFormValidation = Factory::service('FormValidation');

                $oFormValidation->set_rules('is_published', '', '');
                $oFormValidation->set_rules('published', '', '');
                $oFormValidation->set_rules('title', '', 'required');
                $oFormValidation->set_rules('type', '', 'required');
                $oFormValidation->set_rules('body', '', 'required');
                $oFormValidation->set_rules('excerpt', '', '');
                $oFormValidation->set_rules('image_id', '', '');
                $oFormValidation->set_rules('video_url', '', '');
                $oFormValidation->set_rules('audio_url', '', '');
                $oFormValidation->set_rules('seo_keywords', '', '');

                if ($this->input->post('slug')) {

                    $sTable = $this->blog_post_model->getTableName();
                    $oFormValidation->set_rules(
                        'slug',
                        '',
                        'alpha_dash|unique_if_diff[' . $sTable . '.slug.' . $this->data['post']->slug . ']'
                    );
                }

                if ($this->input->post('type') === 'PHOTO') {

                    $oFormValidation->set_rules('image_id', '', 'required');

                } elseif ($this->input->post('type') === 'VIDEO') {

                    $oFormValidation->set_rules('video_url', '', 'required|callback_callbackValidVideoUrl');

                } elseif ($this->input->post('type') === 'AUDIO') {

                    $oFormValidation->set_rules('audio_url', '', 'required|callback_callbackValidAudioUrl');
                }

                $oFormValidation->set_message('required', lang('fv_required'));
                $oFormValidation->set_message('alpha_dash', lang('fv_alpha_dash'));
                $oFormValidation->set_message('unique_if_diff', 'A post using this slug already exists.');
            }

            if (!empty($bIsPreview) || $oFormValidation->run($this)) {

                //  Prepare data
                $aData                     = array();
                $aData['title']            = $this->input->post('title');
                $aData['type']             = $this->input->post('type');
                $aData['slug']             = $this->input->post('slug');
                $aData['excerpt']          = $this->input->post('excerpt');
                $aData['image_id']         = (int) $this->input->post('image_id');
                $aData['image_id']         = $aData['image_id'] ? $aData['image_id'] : null;
                $aData['video_url']        = trim($this->input->post('video_url'));
                $aData['video_url']        = $aData['video_url'] ? $aData['video_url'] : null;
                $aData['audio_url']        = trim($this->input->post('audio_url'));
                $aData['audio_url']        = $aData['audio_url'] ? $aData['audio_url'] : null;
                $aData['body']             = $this->input->post('body');
                $aData['seo_description']  = $this->input->post('seo_description');
                $aData['seo_keywords']     = $this->input->post('seo_keywords');
                $aData['is_published']     = (bool) $this->input->post('is_published');
                $aData['published']        = $this->input->post('published');
                $aData['associations']     = $this->input->post('associations');
                $aData['gallery']          = $this->input->post('gallery');
                $aData['comments_enabled'] = $this->input->post('comments_enabled');
                $aData['comments_expire']  = $this->input->post('comments_expire');

                if (appSetting('categories_enabled', 'blog-' . $this->blog->id)) {

                    $aData['categories'] = $this->input->post('categories');
                }

                if (appSetting('tags_enabled', 'blog-' . $this->blog->id)) {

                    $aData['tags'] = $this->input->post('tags');
                }

                //  Are we running in preview mode?
                if (!empty($bIsPreview)) {

                    //  Previewing, set the preview tables and create a new one
                    $aData['blog_id'] = $this->blog->id;
                    $this->blog_post_model->usePreviewTables(true);
                    $mResult = $this->blog_post_model->create($aData);

                } else {

                    //  Normal behaviour
                    $mResult = $this->blog_post_model->update($iPostId, $aData);
                }

                if (!empty($mResult)) {

                    //  Behave slightly differently depending on whether we're previewing or not
                    if (empty($bIsPreview)) {

                        //  Update admin change log
                        foreach ($aData as $field => $value) {

                            if (isset($this->data['post']->$field)) {

                                switch ($field) {

                                    case 'associations':

                                        //  @TODO: changelog associations
                                        break;

                                    case 'categories':

                                        $aOldCategories = array();
                                        $aNewCategories = array();

                                        foreach ($this->data['post']->$field as $v) {

                                            $aOldCategories[] = $v->label;
                                        }

                                        if (is_array($value)) {

                                            foreach ($value as $v) {

                                                $temp = $this->blog_category_model->getById($v);

                                                if ($temp) {

                                                    $aNewCategories[] = $temp->label;
                                                }
                                            }
                                        }

                                        asort($aOldCategories);
                                        asort($aNewCategories);

                                        $aOldCategories = implode(',', $aOldCategories);
                                        $aNewCategories = implode(',', $aNewCategories);

                                        $this->oChangeLogModel->add(
                                            'updated',
                                            'a',
                                            'blog post',
                                            $iPostId,
                                            $aData['title'],
                                            'admin/blog/post/create/' . $this->blog->id . '/' . $iPostId,
                                            $field,
                                            $aOldCategories,
                                            $aNewCategories,
                                            false
                                        );
                                        break;

                                    case 'tags':

                                        $aOldTags = array();
                                        $aNewTags = array();

                                        foreach ($this->data['post']->$field as $v) {

                                            $aOldTags[] = $v->label;
                                        }

                                        if (is_array($value)) {

                                            foreach ($value as $v) {

                                                $temp = $this->blog_tag_model->getById($v);

                                                if ($temp) {

                                                    $aNewTags[] = $temp->label;
                                                }
                                            }
                                        }

                                        asort($aOldTags);
                                        asort($aNewTags);

                                        $aOldTags = implode(',', $aOldTags);
                                        $aNewTags = implode(',', $aNewTags);

                                        $this->oChangeLogModel->add(
                                            'updated',
                                            'a',
                                            'blog post',
                                            $iPostId,
                                            $aData['title'],
                                            'admin/blog/post/create/' . $this->blog->id . '/' . $iPostId,
                                            $field,
                                            $aOldTags,
                                            $aNewTags,
                                            false
                                        );
                                        break;

                                    default :

                                        $this->oChangeLogModel->add(
                                            'updated',
                                            'a',
                                            'blog post',
                                            $iPostId,
                                            $aData['title'],
                                            'admin/blog/post/create/' . $this->blog->id . '/' . $iPostId,
                                            $field,
                                            $this->data['post']->$field,
                                            $value,
                                            false
                                        );
                                        break;
                                }
                            }
                        }

                        $this->session->set_flashdata('success', ucfirst($this->data['postName']) . ' was updated.');
                        $sRedirectUrl = 'admin/blog/post/edit/' . $this->blog->id . '/' . $iPostId;

                    } else {

                        $sRedirectUrl = $this->blog->url . '/preview/' . $mResult;
                    }

                    redirect($sRedirectUrl);

                } else {

                    $this->data['error']  = 'An error occurred and the post could not be updated. ';
                    $this->data['error'] .= $this->blog_post_model->lastError();
                }

            } else {

                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Load Categories and Tags
        $aData = array(
            'where' => array(
                array('column' => 'blog_id', 'value' => $this->blog->id)
            )
        );

        if (appSetting('categories_enabled', 'blog-' . $this->blog->id)) {

            $this->data['categories'] = $this->blog_category_model->getAll(null, null, $aData);
        }

        if (appSetting('tags_enabled', 'blog-' . $this->blog->id)) {

            $this->data['tags'] = $this->blog_tag_model->getAll(null, null, $aData);
        }

        // --------------------------------------------------------------------------

        //  Load other data
        $oCdn                            = Factory::service('Cdn', 'nails/module-cdn');
        $this->data['associations']      = $this->blog_model->getAssociations($this->data['post']->id);
        $this->data['cdnUrlScaleScheme'] = $oCdn->urlScaleScheme();

        // --------------------------------------------------------------------------

        //  Load assets
        $oAsset = Factory::service('Asset');
        $oAsset->library('uploadify');
        $oAsset->library('MUSTACHE');
        $oAsset->load('moment/moment.js', 'NAILS-BOWER');
        $oAsset->load('admin.post.edit.min.js', 'nails/module-blog');

        if ($this->data['post']->is_published) {

            $oNow = new \DateTime();
            $oPublished = new \DateTime($this->data['post']->published);

            if ($oPublished > $oNow) {
                $sInitalPublishState = 'SCHEDULED';
            } else {
                $sInitalPublishState = 'PUBLISHED';
            }

        } else {
            $sInitalPublishState = 'DRAFT';
        }

        $sInlineJs  = 'var _EDIT;';
        $sInlineJs .= '$(function()';
        $sInlineJs .= '{';
        $sInlineJs .= '    _EDIT = new NAILS_Admin_Blog_Create_Edit(\'EDIT\', \'' . $sInitalPublishState . '\');';
        $sInlineJs .= '    _EDIT.init(' . $this->blog->id . ', "' . $oCdn->generateApiUploadToken() . '");';
        $sInlineJs .= '});';

        $oAsset->inline($sInlineJs, 'JS');

        // --------------------------------------------------------------------------

        Helper::loadView('edit');
    }
875317
public function notifyCreate()
    {
        if (\Yii::$app->reviews2->notifyEmails) {
            foreach (\Yii::$app->reviews2->notifyEmails as $email) {
                \Yii::$app->mailer->compose('@skeeks/cms/reviews2/mail/new-message', [
                    'model' => $this
                ])
                    ->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName])
                    ->setTo($email)
                    ->setSubject(\Yii::t('skeeks/reviews2', "Added a new review") . " #" . $this->id)
                    ->send();
            }
        }
    }
1123123
protected function createEmailPreviewDirectory()
    {
        if (! $this->files->exists($this->previewPath)) {
            $this->files->makeDirectory($this->previewPath);

            $this->files->put($this->previewPath.'/.gitignore', "*\n!.gitignore");
        }
    }
625938
public function render()
	{
		$template = $this->getTemplate(true);

		$params = array('template' => $template->template, 'file' => 'index.php', 'directory' => JPATH_THEMES, 'params' => $template->params);

		// Parse the document.
		$document = JFactory::getDocument();
		$document->parse($params);

		// Trigger the onBeforeRender event.
		JPluginHelper::importPlugin('system');
		$this->triggerEvent('onBeforeRender');

		// Render the document.
		$caching = ($this->getCfg('caching') >= 2) ? true : false;
		JResponse::setBody($document->render($caching, $params));

		// Trigger the onAfterRender event.
		$this->triggerEvent('onAfterRender');
	}
1054823
protected function _prepareRendering()
    {
        $this->view->addDefaultViewParam('_template', $this);

        $structure = $this->getPageStructure();
        if (empty($structure)) {
            $this->setPageStructure(self::$default_page_structure);
        }
    }
1012491
public function actionTemplates()
    {
        $foundTemplates = $this->findTemplatesFiles();

        if (!$foundTemplates) {
            $this->notifyNoTemplatesFound();
        } else {
            $this->notifyTemplatesCanBeGenerated($foundTemplates);
        }
    }
1335414
protected function generateHtml($preview = false)
    {
        if ($this->codeDefinition) {
            if ($preview) {
                return $this->codeDefinition->getPreviewHtml($this);
            }
            return $this->codeDefinition->getHtml($this);
        }

        return "";
    }
196989
def update
      @newsletter_subscription = Cmtool::NewsletterSubscription.find(params[:id])

      respond_to do |format|
        if @newsletter_subscription.update_attributes(newsletter_subscription_params)
          format.html { redirect_to([cmtool, @newsletter_subscription], :notice => I18n.t('cmtool.action.update.successful', :model => Cmtool::NewsletterSubscription.model_name.human)) }
          format.xml  { head :ok }
        else
          format.html { render :action => "edit" }
          format.xml  { render :xml => @newsletter_subscription.errors, :status => :unprocessable_entity }
        end
      end
    end