Navigation Menu

Skip to content

Commit

Permalink
Dev: added some array functions to Twig
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 9, 2018
1 parent d69915c commit 153f834
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
7 changes: 7 additions & 0 deletions application/config/internal.php
Expand Up @@ -241,6 +241,9 @@
'empty' => 'empty',
'count' => 'count',
'reset' => 'reset',
'in_array' => 'in_array',
'in_multiarray' => 'LS_Twig_Extension::in_multiarray',
'array_search' => 'array_search',
'renderCaptcha' => 'LS_Twig_Extension::renderCaptcha',
'getPost' => 'LS_Twig_Extension::getPost',
'getParam' => 'LS_Twig_Extension::getParam',
Expand Down Expand Up @@ -287,6 +290,7 @@
'json_encode',
'replace',
'last',
'first',
'capitalize',
'lower',
'upper',
Expand Down Expand Up @@ -337,6 +341,9 @@
'empty',
'count',
'reset',
'in_array',
'array_search',
'in_multiarray',
'renderCaptcha',
'getPost',
'getParam',
Expand Down
30 changes: 23 additions & 7 deletions application/core/LS_Twig_Extension.php
Expand Up @@ -257,7 +257,7 @@ public static function image($sImagePath, $alt = '', $htmlOptions = array( ))
if (@is_array(getimagesize(Yii::app()->getConfig('rootdir').'/'.$sImagePath))) {
$sUrlImgAsset = self::assetPublish(Yii::app()->getConfig('rootdir').'/'.$sImagePath);
}


return CHtml::image($sUrlImgAsset, $alt, $htmlOptions);
}
Expand All @@ -273,11 +273,11 @@ public static function imageSrc($sImagePath, $default = './files/pattern.png')
// Reccurence on templates to find the file
$oTemplate = self::getTemplateForRessource($sImagePath);
$sUrlImgAsset = $sImagePath;


if ($oTemplate) {
$sUrlImgAsset = self::assetPublish($oTemplate->path.$sImagePath);
}
}

if (@is_array(getimagesize(Yii::app()->getConfig('rootdir').'/'.$sImagePath))) {
$sUrlImgAsset = self::assetPublish(Yii::app()->getConfig('rootdir').'/'.$sImagePath);
Expand Down Expand Up @@ -493,12 +493,28 @@ public static function darkencss($cssColor, $grade=10, $alpha=1){
}

return 'rgba('.join(', ', $return).','.$alpha.')';
}

/**
* Check if a needle is in a multidimensional array
* @param mixed $needle The searched value.
* @param array $haystack The array.
* @param bool $strict If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
*/
function in_multiarray($needle, $haystack, $strict = false) {

foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}

return false;
}

public static function lightencss($cssColor, $grade=10, $alpha=1){


public static function lightencss($cssColor, $grade=10, $alpha=1)
{
$aColors = str_split(substr($cssColor,1), 2);
$return = [];
foreach ($aColors as $color) {
Expand Down

0 comments on commit 153f834

Please sign in to comment.