1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Rewrote getTemplate test and added example theme template override (bootstrap3) of plugin template (gallery)

This commit is contained in:
Cameron 2021-01-22 15:43:57 -08:00
parent acc1a9af0d
commit 7557d07622
4 changed files with 256 additions and 38 deletions

View File

@ -3196,7 +3196,7 @@ class e107
*
* @param string $plug_name if null getCoreTemplate method will be called
* @param string $id - file prefix, e.g. calendar for calendar_template.php
* @param string|null $key
* @param string|null $key $YOURTEMPLATE_TEMPLATE[$key]
* @param boolean $override see {@link getThemeInfo()}
* @param boolean $merge merge theme with plugin templates, default is false
* @param boolean $info retrieve template info only
@ -3208,10 +3208,12 @@ class e107
{
return self::getCoreTemplate($id, $key, $override, $merge, $info);
}
if($id == null || $id === true) // loads {$plug_name}/templates/{$plug_name}_template.php and an array ${PLUG_NAME}_TEMPLATE
{
$id = $plug_name;
}
$reg_path = 'plugin/'.$plug_name.'/templates/'.$id;
$reg_path .= ($override) ? '/ext' : '';
@ -3494,7 +3496,7 @@ class e107
return $ret;
}
return ($ret && is_array($ret) && isset($ret[$key]) ? $ret[$key] : false);
return ($ret && is_array($ret) && isset($ret[$key])) ? $ret[$key] : false;
}
/**

View File

@ -812,48 +812,70 @@ class e107Test extends \Codeception\Test\Unit
}
*/
public function testGetTemplateOverride()
{
// Loads e107_themes/bootstrap3/templates/gallery/gallery_template.php
$template = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true)
$this->assertEquals("My Gallery", $template['list']['caption']);
// Duplicate to load registry
$template2 = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true)
$this->assertEquals("My Gallery", $template2['list']['caption']);
$this->assertSame($template, $template2);
}
public function testGetTemplateOverrideMerge()
{
// Loads e107_plugins/gallery/templates/gallery_template.php then overwrites it with e107_themes/bootstrap3/templates/gallery/gallery_template.php
$template = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled.
$this->assertArrayHasKey('merged-example', $template);
$this->assertEquals("My Gallery", $template['list']['caption']); // ie. from the original
$this->assertNotEmpty($template['merged-example']);
// duplicate to load registry
$template2 = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled.
$this->assertArrayHasKey('merged-example', $template2);
$this->assertEquals("My Gallery", $template2['list']['caption']); // ie. from the original
$this->assertNotEmpty($template2['merged-example']);
$this->assertSame($template, $template2);
}
public function testGetTemplateMerge()
{
// // ie. should be from plugin template, not theme.
$template = e107::getTemplate('gallery', null, null, false, true); // theme override is disabled, theme merge is enabled.
$this->assertEquals("Gallery", $template['list']['caption']);
$this->assertArrayNotHasKey('merged-example', $template);
// duplicate to load registry.
$template2 = e107::getTemplate('gallery', null, null, false, true); // theme override is disabled, theme merge is enabled.
$this->assertEquals("Gallery", $template2['list']['caption']);
$this->assertArrayNotHasKey('merged-example', $template2);
$this->assertSame($template, $template2);
}
/**
* This test checks getTemplate() use on loading between the core download plugin template and the _blank theme download template
* This test checks getTemplate() with no merging or override.
*/
public function testGetTemplate()
{
// clear all template related registry entries.
// $cleared = $this->clearRelatedRegistry('templates/download');
return null; // FIXME - getTemplate() registry issue.
// cached with bootstrap3 theme template.
//FIXME Remove 'false' from the line below to see Undefined 'header' issue with registry.
$template = e107::getTemplate('download', null, null, false); // theme override is enabled by default.
// e107::getConfig()->set('sitetheme', '_blank');
e107::plugLan('download', 'front', true);
// FIXME getTemplate registry doesn't handle the theme change correctly.
/*
$template = e107::getTemplate('download', null, null); // theme override is enabled by default.
$this->assertEquals('{DOWNLOAD_BREADCRUMB} Custom', $template['header']); // ie. should be from _blank theme download template (override of plugin).
$footer = empty($template['footer']); // theme overrides everything, since merge is not enabled. theme does not contain 'footer'.
$this->assertTrue($footer);*/
$template = e107::getTemplate('download', null, null, false); // theme override is disabled.
$this->assertEquals("{DOWNLOAD_BREADCRUMB}", $template['header']); // ie. should be from plugin template, not theme.
$this->assertEquals('', $template['footer']); // main plugin template is active, since override is false. 'footer' is set.
/*
$template = e107::getTemplate('download', null, null, true, true); // theme override is enabled, and theme merge is enabled.
$this->assertEquals("{DOWNLOAD_BREADCRUMB} Custom", $template['header']); //from theme
$this->assertEquals("", $template['footer']); // 'footer' missing from theme, so plugin template used. ie. arrays have been merged.
*/
$template = e107::getTemplate('download', null, null, false, true); // theme override is disabled, theme merge is enabled.
$this->assertEquals("{DOWNLOAD_BREADCRUMB}", $template['header']); // ie. should be from plugin template, not theme.
// $this->assertEquals("test", $template['other']); // 'test' is missing from plugin template, but merge is enabled. Not an override of plugin template key so merge is okay.
// FIXME above..
// var_dump($template['other']);
// e107::getConfig()->set('sitetheme', 'bootstrap3');
// Loads e107_plugins/gallery/templates/gallery_template.php
$template = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled.
$this->assertEquals("Gallery", $template['list']['caption']);
// Duplicate to load registry.
$template2 = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled.
$this->assertEquals("Gallery", $template2['list']['caption']);
$this->assertSame($template, $template2);
}
/*

View File

@ -0,0 +1,195 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2016 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Templates for "gallery" plugin.
*/
$GALLERY_TEMPLATE['list']['caption'] = "My Gallery";
$GALLERY_TEMPLATE['list']['start'] = '{GALLERY_BREADCRUMB}
<div class="row gallery">
';
$GALLERY_TEMPLATE['list']['item'] = '
<div class="span2 col-xs-6 col-md-3">
<div class="thumbnail">
{GALLERY_THUMB=w=300&h=200}
<h5>{GALLERY_CAPTION}</h5>
</div>
</div>
';
$GALLERY_TEMPLATE['list']['end'] = '
</div>
<div class="center">
<div class="gallery-list-nextprev">{GALLERY_NEXTPREV}</div>
<div class="gallery-list-back">
<a class="btn btn-default btn-secondary" href="{GALLERY_BASEURL}">' . LAN_BACK . '</a>
</div>
</div>
';
// Bootstrap3 Compatible.
$GALLERY_TEMPLATE['cat']['caption'] = LAN_PLUGIN_GALLERY_TITLE;
$GALLERY_TEMPLATE['cat']['start'] = '{GALLERY_BREADCRUMB}
<div class="row gallery-cat">
';
$GALLERY_TEMPLATE['cat']['item'] = '
<div class="span3 col-xs-6 col-md-3">
<div>
{GALLERY_CAT_THUMB}
<h3>{GALLERY_CAT_TITLE}</h3>
</div>
</div>
';
$GALLERY_TEMPLATE['cat']['end'] = '
</div>
';
// {GALLERY_SLIDESHOW=X} X = Gallery Category. Default: 1 (ie. 'gallery_1') Overrides preference in admin.
// {GALLERY_SLIDES=X} X = number of items per slide.
// {GALLERY_JUMPER=space} will remove numbers and just leave spaces.
$GALLERY_TEMPLATE['slideshow_wrapper'] = '
<div id="gallery-slideshow-wrapper">
<div id="gallery-slideshow-content">
{GALLERY_SLIDES=4}
</div>
</div>
<div class="gallery-slideshow-controls">
<a href="#" class="gallery-control gal-next btn btn-sm btn-xs btn-default btn-secondary pull-right float-right">
' . LAN_NEXT . ' {GLYPH=fa-chevron-right}
</a>
<a href="#" class="gallery-control gal-prev btn btn-sm btn-xs btn-default btn-secondary">
{GLYPH=fa-chevron-left} ' . LAN_PREVIOUS . '
</a>
<span class="gallery-slide-jumper-container">
{GALLERY_JUMPER}
</span>
</div>
';
$GALLERY_TEMPLATE['slideshow_slide_item'] = '<span class="gallery-slide-item">{GALLERY_THUMB: w=150&h=120}</span>';
$GALLERY_TEMPLATE['prettyphoto']['content'] = '
<div class="pp_pic_holder">
<div class="ppt">&nbsp;</div>
<div class="pp_top">
<div class="pp_left"></div>
<div class="pp_middle"></div>
<div class="pp_right"></div>
</div>
<div class="pp_content_container">
<div class="pp_left">
<div class="pp_right">
<div class="pp_content">
<div class="pp_loaderIcon"></div>
<div class="pp_fade">
<a href="#" class="pp_expand" title="'.LAN_EXPAND.'">'.LAN_EXPAND.'</a>
<div class="pp_hoverContainer">
<a class="pp_next" href="#">' . LAN_NEXT . '</a>
<a class="pp_previous" href="#">' . LAN_PREVIOUS . '</a>
</div>
<div id="pp_full_res"></div>
<div class="pp_details">
<div class="pp_nav">
<a href="#" class="pp_arrow_previous">' . LAN_PREVIOUS . '</a>
<p class="currentTextHolder">0/0</p>
<a href="#" class="pp_arrow_next">' . LAN_NEXT . '</a>
</div>
<p class="pp_description"></p>
{pp_social}
<a class="pp_close" href="#">' . LAN_CLOSE . '</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="pp_bottom">
<div class="pp_left"></div>
<div class="pp_middle"></div>
<div class="pp_right"></div>
</div>
</div>
<div class="pp_overlay"></div>
';
$GALLERY_TEMPLATE['prettyphoto']['gallery_item'] = '
<div class="pp_gallery">
<a href="#" class="pp_arrow_previous">' . LAN_PREVIOUS . '</a>
<div>
<ul>
{gallery}
</ul>
</div>
<a href="#" class="pp_arrow_next">' . LAN_NEXT . '</a>
</div>
';
$GALLERY_TEMPLATE['prettyphoto']['image_item'] = '
<img id="fullResImage" src="{path}" />
';
$GALLERY_TEMPLATE['prettyphoto']['flash_item'] = '
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}">
<param name="wmode" value="{wmode}" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="{path}" />
<embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed>
</object>
';
$GALLERY_TEMPLATE['prettyphoto']['quicktime_item'] = '
<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}">
<param name="src" value="{path}">
<param name="autoplay" value="{autoplay}">
<param name="type" value="video/quicktime">
<embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed>
</object>
';
$GALLERY_TEMPLATE['prettyphoto']['iframe_item'] = '
<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>
';
$GALLERY_TEMPLATE['prettyphoto']['inline_item'] = '
<div class="pp_inline">{content}</div>
';
$GALLERY_TEMPLATE['prettyphoto']['custom_item'] = '';
$GALLERY_TEMPLATE['prettyphoto']['social_item'] = '
<div class="pp_social">
<div class="twitter">
<a href="http://twitter.com/share" class="twitter-share-button" data-count="none">' . LAN_SHARE . '</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</div>
<div class="facebook">
<iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href=\'+location.href+\'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe>
</div>
</div>
';
$GALLERY_TEMPLATE['merged-example'] = 'Example';
/*
$GALLERY_TEMPLATE['portfolio']['start'] = '<-- start portfolio -->';
$GALLERY_TEMPLATE['portfolio']['item'] = '<img src="{GALLERY_THUMB: w=1080&h=720&thumbsrc}" class="img-responsive" alt="{GALLERY_CAPTION=text}">';
$GALLERY_TEMPLATE['portfolio']['end'] = '<-- end portfolio -->';
*/

View File

@ -50,4 +50,3 @@
?>