mirror of
https://github.com/e107inc/e107.git
synced 2025-07-25 17:01:43 +02:00
Fixed corruption of carousel attributes and other 'data-' keys. Test added.
This commit is contained in:
@@ -70,6 +70,7 @@ class e_form
|
|||||||
private $_inline_token;
|
private $_inline_token;
|
||||||
public $_snippets = false; // use snippets or not. - experimental, and may be removed - use at own risk.
|
public $_snippets = false; // use snippets or not. - experimental, and may be removed - use at own risk.
|
||||||
private $_fontawesome = false;
|
private $_fontawesome = false;
|
||||||
|
private $_bootstrap;
|
||||||
private $_helptip = 1;
|
private $_helptip = 1;
|
||||||
/**
|
/**
|
||||||
* @var user_class
|
* @var user_class
|
||||||
@@ -96,6 +97,11 @@ class e_form
|
|||||||
$this->_fontawesome = true;
|
$this->_fontawesome = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(deftrue('BOOTSTRAP'))
|
||||||
|
{
|
||||||
|
$this->_bootstrap = (int) BOOTSTRAP;
|
||||||
|
}
|
||||||
|
|
||||||
$this->_helptip = (int) e107::getPref('admin_helptip', 1);
|
$this->_helptip = (int) e107::getPref('admin_helptip', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,19 +655,35 @@ class e_form
|
|||||||
$navigation = isset($options['navigation']) ? $options['navigation'] : true;
|
$navigation = isset($options['navigation']) ? $options['navigation'] : true;
|
||||||
$indicate = isset($options['indicators']) ? $options['indicators'] : true;
|
$indicate = isset($options['indicators']) ? $options['indicators'] : true;
|
||||||
|
|
||||||
|
$prefix = ($this->_bootstrap > 4) ? 'data-bs-' : 'data-';
|
||||||
|
|
||||||
|
$att = [
|
||||||
|
'id' => $name,
|
||||||
|
'class' => 'carousel slide'
|
||||||
|
];
|
||||||
|
|
||||||
|
$att[$prefix.'ride'] = 'carousel';
|
||||||
|
|
||||||
|
if(isset($options['wrap']))
|
||||||
|
{
|
||||||
|
$att[$prefix.'wrap'] = (bool) $options['wrap'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($options['interval']))
|
||||||
|
{
|
||||||
|
$att[$prefix.'interval'] = (int) $options['interval'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($options['pause']))
|
||||||
|
{
|
||||||
|
$att[$prefix.'pause'] = (string) $options['pause'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$start = '
|
$start = '
|
||||||
<!-- Carousel -->
|
<!-- Carousel -->
|
||||||
|
|
||||||
<div' . $this->attributes([
|
<div' .$this->attributes($att) . '>';
|
||||||
'id' => $name,
|
|
||||||
'class' => 'carousel slide',
|
|
||||||
'data-ride' => 'carousel',
|
|
||||||
'data-bs-ride' => 'carousel',
|
|
||||||
'data-interval' => isset($options['interval']) ? $options['interval'] : null,
|
|
||||||
'data-wrap' => isset($options['wrap']) ? $options['wrap'] : null,
|
|
||||||
'data-pause' => isset($options['pause']) ? $options['pause'] : null,
|
|
||||||
]) . '>';
|
|
||||||
|
|
||||||
if($indicate && (count($array) > 1))
|
if($indicate && (count($array) > 1))
|
||||||
{
|
{
|
||||||
@@ -674,7 +696,7 @@ class e_form
|
|||||||
foreach($array as $key=>$tab)
|
foreach($array as $key=>$tab)
|
||||||
{
|
{
|
||||||
$active = ($c == $act) ? ' class="active"' : '';
|
$active = ($c == $act) ? ' class="active"' : '';
|
||||||
$indicators .= '<li data-target="#'.$name.'" data-slide-to="'.$c.'" data-bs-target="#'.$name.'" data-bs-slide-to="'.$c.'" '.$active.'></li>';
|
$indicators .= '<li '.$prefix.'target="#'.$name.'" '.$prefix.'slide-to="'.$c.'" '.$active.'></li>';
|
||||||
$c++;
|
$c++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,7 +714,7 @@ class e_form
|
|||||||
foreach($array as $key=>$tab)
|
foreach($array as $key=>$tab)
|
||||||
{
|
{
|
||||||
$active = ($c == $act) ? ' active' : '';
|
$active = ($c == $act) ? ' active' : '';
|
||||||
$label = !empty($tab['label']) ? ' data-label="'.$tab['label'].'"' : '';
|
$label = !empty($tab['label']) ? ' '.$prefix.'label="'.$tab['label'].'"' : '';
|
||||||
$inner .= '<div class="carousel-item item'.$active.'" id="'.$key.'"'.$label.'>';
|
$inner .= '<div class="carousel-item item'.$active.'" id="'.$key.'"'.$label.'>';
|
||||||
$inner .= $tab['text'];
|
$inner .= $tab['text'];
|
||||||
|
|
||||||
@@ -711,10 +733,10 @@ class e_form
|
|||||||
if($navigation && (count($array) > 1))
|
if($navigation && (count($array) > 1))
|
||||||
{
|
{
|
||||||
$controls = '
|
$controls = '
|
||||||
<a class="left carousel-control carousel-left" href="#'.$name.'" role="button" data-slide="prev" data-bs-slide="prev">
|
<a class="left carousel-control carousel-left" href="#'.$name.'" role="button" '.$prefix.'slide="prev">
|
||||||
<span class="glyphicon glyphicon-chevron-left"></span>
|
<span class="glyphicon glyphicon-chevron-left"></span>
|
||||||
</a>
|
</a>
|
||||||
<a class="right carousel-control carousel-right" href="#'.$name.'" role="button" data-slide="next" data-bs-slide="next">
|
<a class="right carousel-control carousel-right" href="#'.$name.'" role="button" '.$prefix.'slide="next">
|
||||||
<span class="glyphicon glyphicon-chevron-right"></span>
|
<span class="glyphicon glyphicon-chevron-right"></span>
|
||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
@@ -3999,8 +4021,12 @@ var_dump($select_options);*/
|
|||||||
|
|
||||||
foreach ($attributes as $key => $value)
|
foreach ($attributes as $key => $value)
|
||||||
{
|
{
|
||||||
if ($value === true) $value = $key;
|
|
||||||
if (!empty($value) || is_numeric($value) || $key === "value")
|
if ($value === true && (strpos($key,'data-') !== 0))
|
||||||
|
{
|
||||||
|
$value = $key;
|
||||||
|
}
|
||||||
|
if (!empty($value) || is_numeric($value) || $key === "value" || strpos($key,'data-') === 0)
|
||||||
{
|
{
|
||||||
$stringifiedAttributes[] = $key . "='" . htmlspecialchars($value, ENT_QUOTES) . "'";
|
$stringifiedAttributes[] = $key . "='" . htmlspecialchars($value, ENT_QUOTES) . "'";
|
||||||
}
|
}
|
||||||
|
@@ -304,12 +304,28 @@ class e_formTest extends \Codeception\Test\Unit
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
public function testCarousel()
|
public function testCarousel()
|
||||||
{
|
{
|
||||||
|
$slides = [
|
||||||
|
1 => ['caption'=>'Slide 1', 'text'=>'slide 1'],
|
||||||
|
2 => ['caption'=>'Slide 2', 'text' => 'slide 2'],
|
||||||
|
3 => ['caption' => 'Slide 3', 'text'=> 'slide 3']
|
||||||
|
];
|
||||||
|
|
||||||
|
$parms = ['default'=>12, 'indicators'=>false, 'navigation'=>false, 'wrap'=>true, 'interval'=>false, 'data'=>false];
|
||||||
|
$result = $this->_frm->carousel('test-carousel', $slides, $parms);
|
||||||
|
$expected = "<div id='test-carousel' class='carousel slide' data-ride='carousel' data-wrap='1' data-interval='0'>";
|
||||||
|
$this->assertStringContainsString($expected, $result);
|
||||||
|
|
||||||
|
|
||||||
|
$parms = ['default'=>12, 'indicators'=>false, 'navigation'=>false, 'wrap'=>false, 'interval'=>false, 'data'=>false];
|
||||||
|
$result = $this->_frm->carousel('test-carousel', $slides, $parms);
|
||||||
|
$expected = "<div id='test-carousel' class='carousel slide' data-ride='carousel' data-wrap='' data-interval='0'>";
|
||||||
|
$this->assertStringContainsString($expected, $result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public function testUrl()
|
public function testUrl()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user