array(
'label' => 'Headline',
//'tpl' => 'tpls/default/headline.html',
'tpl' => 'string:
Add your headline here..
',
'thumbnail' => 'tpls/default/thumbs/headline.png',
),
'content' => array(
'label' => 'Content',
'tpl' => 'string:Title
{lipsum}
',
'thumbnail' => 'tpls/default/thumbs/content1.png',
),
'content2' => array(
'label' => 'Content with two columns',
'tpl' => 'string:Title | Title |
{lipsum} | {lipsum} |
',
'thumbnail' => 'tpls/default/thumbs/content2.png',
),
'content3' => array(
'label' => 'Content with three columns',
'tpl' => 'string:Title | Title | Title |
{lipsum} | {lipsum} | {lipsum} |
',
'thumbnail' => 'tpls/default/thumbs/content3.png',
),
'image1left' => array(
'label' => 'Content with left image',
'tpl' => 'string:{imageSmall} | Title{lipsum} |
',
'thumbnail' => 'tpls/default/thumbs/image1left.png',
),
'image1right' => array(
'label' => 'Content with right image',
'tpl' => 'string:Title{lipsum} | {imageSmall} |
',
'thumbnail' => 'tpls/default/thumbs/image1right.png',
),
'image2' => array(
'label' => 'Content with two image',
'tpl' => 'string:{imageSmall} | Title{lipsum} | {imageSmall} | Title{lipsum} |
',
'thumbnail' => 'tpls/default/thumbs/image2.png',
),
'image3' => array(
'label' => 'Content with three image',
'tpl' => 'string:{image} | {image} | {image} |
Title{lipsum} | Title{lipsum} | Title{lipsum} |
',
'thumbnail' => 'tpls/default/thumbs/image3.png',
),
'footer' => array(
'label' => 'Footer',
//'tpl' => 'tpls/default/footer.html',
'tpl' => 'string:',
'thumbnail' => 'tpls/default/thumbs/footer.png',
),
);
private $thumbsCache = array();
private $autoInsertThumbnails = true;
private static $devMode = false;
public function __construct()
{
$this->vendorPath = './../../vendor/';
if ($this->autoInsertThumbnails) {
if (count($this->getThumbs())==0 || self::$devMode) {
$ord = 0;
foreach (self::$defaultThumbnails as $thumbName => $thumbData) {
$templateSectionLine = BeanFactory::newBean('TemplateSectionLine');
$templateSectionLine->name = $thumbData['label'];
$templateSectionLine->description = preg_replace('/^string:/', '', $thumbData['tpl']);
$templateSectionLine->description = str_replace('{lipsum}', $this->getContentLipsum(), $templateSectionLine->description);
$templateSectionLine->description = str_replace('{imageSmall}', $this->getContentImageSample(130), $templateSectionLine->description);
$templateSectionLine->description = str_replace('{image}', $this->getContentImageSample(), $templateSectionLine->description);
$templateSectionLine->thumbnail = file_exists($this->mozaikPath . '/' . $thumbData['thumbnail']) ? $this->mozaikPath . '/' . $thumbData['thumbnail'] : null;
$templateSectionLine->ord = ++$ord;
$templateSectionLine->save();
}
}
$this->thumbsCache = array();
}
}
private function getContentLipsum()
{
return 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempus odio ante, in feugiat ex pretium eu. In pharetra tincidunt urna et malesuada. Etiam aliquet auctor justo eu placerat. In nec sollicitudin enim. Nulla facilisi. In viverra velit turpis, et lobortis nunc eleifend id. Curabitur semper tincidunt vulputate. Nullam fermentum pellentesque ullamcorper.';
}
private function getContentImageSample($width = null)
{
if (is_numeric($width)) {
$width = ' width="' . $width . '"';
} else {
$width = '';
}
$splits = explode('index.php', $_SERVER['REQUEST_URI']);
$url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $splits[0];
$image = '
';
return $image;
}
public function getDependenciesHTML()
{
$html = <<
HTML;
return $html;
}
public function getIncludeHTML()
{
$html = <<
HTML;
return $html;
}
private function tinyMCESetupArgumentFixer($tinyMCESetup = '{}')
{
if (!$tinyMCESetup) {
$tinyMCESetup = '{}';
}
if (is_array($tinyMCESetup) || is_object($tinyMCESetup)) {
$tinyMCESetup = json_encode($tinyMCESetup);
}
if (!preg_match('/^tinyMCE\s*:\s*/', $tinyMCESetup)) {
$tinyMCESetup = "tinyMCE: $tinyMCESetup";
}
return $tinyMCESetup;
}
public function getElementHTML($contents = '', $textareaId = null, $elementId = 'mozaik', $width = '600', $thumbs = array(), $tinyMCESetup = '{}')
{
if (is_numeric($width)) {
$width .= 'px';
}
if (!$thumbs) {
$thumbs = self::$defaultThumbnails;
}
$thumbsJSON = json_encode($thumbs);
$tinyMCESetup = $this->tinyMCESetupArgumentFixer($tinyMCESetup);
$refreshTextareaScript = '';
if ($textareaId) {
$refreshTextareaScript = $this->getRefreshTextareaScript($textareaId, $elementId, $width);
}
$html = <<
#{$elementId} {position: relative; top: 0; left: 0;}
#{$elementId} ul.mozaik-thumbs li.mozaik-thumbnail {padding: 5px 0;}
#{$elementId} ul.mozaik-thumbs li.mozaik-thumbnail:hover {background-color: lightgray;}
#{$elementId} .mozaik-thumbnail.ui-draggable.ui-draggable-handle {cursor: -webkit-grab;}
#{$elementId} .mozaik-thumbnail.ui-draggable.ui-draggable-handle * {cursor: -webkit-grab;}
#{$elementId} .mozaik-thumbnail.ui-draggable.ui-draggable-handle.ui-draggable-dragging {cursor: -webkit-grabbing;}
#{$elementId} .mozaik-thumbnail.ui-draggable.ui-draggable-handle.ui-draggable-dragging * {cursor: -webkit-grabbing;}
#{$elementId} .mozaik-inner a {text-decoration: underline;}
{$contents}
HTML;
return $html;
}
public function getAllHTML($contents = '', $textareaId = null, $elementId = 'mozaik', $width = '600', $group = '', $tinyMCESetup = '{}')
{
if (is_numeric($width)) {
$width .= 'px';
}
$tinyMCESetup = $this->tinyMCESetupArgumentFixer($tinyMCESetup);
$mozaikHTML = $this->getDependenciesHTML();
$mozaikHTML .= $this->getIncludeHTML();
$thumbs = $this->getThumbs($group);
$mozaikHTML .= $this->getElementHTML($contents, $textareaId, $elementId, $width, $thumbs, $tinyMCESetup);
return $mozaikHTML;
}
private function getRefreshTextareaScript($textareaId, $elementId, $width = 'initial')
{
if (is_numeric($width)) {
$width .= 'px';
}
$js = <<