protected function actionEdit()
    {
        $mm = new MessageModel($_GET['id'], $this->dao);
        $row = $this->dao->messageById($_GET['id']);
        $tm = new TemplateModel($this->dao->templateBody($row['template']));
        $ref = Reference::decode(stripslashes($_GET['field']));
        $area = ContentAreaBase::createContentArea($tm->namedNode($ref->name));
        $result = $area->display($ref, $mm->messageAreas());
        $html = <<<END
<html>
<body>{$result}</body>
</html>
END;
        ob_end_clean();
        echo $html;
        exit;
    }
    /**
     * @test
     */
    public function createsRepeatContentArea()
    {
        $html = <<<'END'
<html>
    <body>
        <div data-repeatable="repeat1">
            <div data-edit="article" data-type="textarea"></div>
        </div>
    </body>
</html>
END;
        $tm = new TemplateModel();
        $tm->loadHtml($html);
        $node = $tm->namedNode('repeat1');
        $area = ContentAreaBase::createContentArea($node);
        $this->assertInstanceOf('phpList\\plugin\\ContentAreas\\ContentAreaRepeat', $area);
        $this->assertEquals('repeat1', $area->name);
        $this->assertEquals('repeat1', $area->reference);
    }
 /**
  * @test
  */
 public function doesNotMergeIfNotTemplate()
 {
     $daoStub = $this->getMockBuilder('phpList\\plugin\\ContentAreas\\DAO')->disableOriginalConstructor()->getMock();
     $daoStub->method('messageData')->willReturn('SER:' . serialize(['article' => '<p>here is the article</p>']));
     $template = '<html><body><div></div></body></html>';
     $this->assertEquals(false, TemplateModel::mergeIfTemplate($template, 123, $daoStub));
 }
 /**
  * Called by ViewBrowser plugin to manipulate template and message.
  * Sets the message content to the merged template and message areas.
  * 
  * @param string &$templateBody the body of the template
  * @param array  &$messageData  the message data
  */
 public function viewBrowserHook(&$templateBody, array &$messageData)
 {
     if ($merged = TemplateModel::mergeIfTemplate($templateBody, $messageData['id'])) {
         $messageData['message'] = str_ireplace('[CONTENT]', $messageData['message'], $merged);
         $messageData['template'] = 0;
         $messageData['htmlformatted'] = true;
         $templateBody = '';
     }
 }