This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,138 @@
<?php
namespace Nextend\Framework\Parser;
/**
*
* Color values manipulation utilities. Provides methods to convert from and to
* Hex, RGB, HSV and HSL color representattions.
*
* Several color conversion logic are based on pseudo-code from
* http://www.easyrgb.com/math.php
*
* @category Lux
*
* @package Lux_Color
*
* @author Rodrigo Moraes <rodrigo.moraes@gmail.com>
*
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*
* @version $Id$
*
*/
class Color {
public static function colorToRGBA($value) {
$rgba = self::hex2rgba($value);
return 'RGBA(' . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ',' . round($rgba[3] / 127, 2) . ')';
}
public static function hex2alpha($value) {
if (strlen($value) == 6) {
return 127;
}
return intval(hexdec(substr($value, 6, 2)) / 2);
}
public static function hex2opacity($value) {
return self::hex2alpha($value) / 127;
}
public static function colorToSVG($value) {
$rgba = self::hex2rgba($value);
return array(
substr($value, 0, 6),
round($rgba[3] / 127, 2)
);
}
/**
*
* Converts hexadecimal colors to RGB.
*
* @param string $hex Hexadecimal value. Accepts values with 3 or 6 numbers,
* with or without #, e.g., CCC, #CCC, CCCCCC or #CCCCCC.
*
* @return array RGB values: 0 => R, 1 => G, 2 => B
*
*/
public static function hex2rgb($hex) {
// Remove #.
if (strpos($hex, '#') === 0) {
$hex = substr($hex, 1);
}
if (strlen($hex) == 3) {
$hex .= $hex;
}
if (strlen($hex) != 6) {
return false;
}
// Convert each tuple to decimal.
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
return array(
$r,
$g,
$b
);
}
public static function hex2rgba($hex) {
// Remove #.
if (strpos($hex, '#') === 0) {
$hex = substr($hex, 1);
}
if (strlen($hex) == 6) {
$hex .= 'ff';
}
if (strlen($hex) != 8) {
$hex = '00000000';
}
// Convert each tuple to decimal.
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
$a = intval(hexdec(substr($hex, 6, 2)) / 2);
return array(
$r,
$g,
$b,
$a
);
}
public static function hex82hex($hex) {
// Remove #.
if (strpos($hex, '#') === 0) {
$hex = substr($hex, 1);
}
if (strlen($hex) == 6) {
$hex .= 'ff';
}
if (strlen($hex) != 8) {
$hex = '00000000';
}
return array(
substr($hex, 0, 6),
substr($hex, 6, 2)
);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Nextend\Framework\Parser;
class Common {
/**
* @param $str
* @param bool $concat
*
* @return array
*/
public static function parse($str, $concat = false) {
$v = explode("|*|", $str);
for ($i = 0; $i < count($v); $i++) {
if (strpos($v[$i], "||") !== false) {
if ($concat === false) $v[$i] = explode("||", $v[$i]); else $v[$i] = str_replace("||", $concat, $v[$i]);
}
}
return count($v) == 1 ? $v[0] : $v;
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace Nextend\Framework\Parser;
use Nextend\Framework\Parser\Link\ParserInterface;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
class Link {
/**
* @var ParserInterface[]
*/
private static $parsers = array();
public static $registeredNamespaces = array(
'\\Nextend\\Framework\\Parser\\Link\\',
'\\Nextend\\SmartSlider3\\Parser\\Link\\'
);
public static function parse($url, &$attributes, $isEditor = false) {
if ($url == '#' || $isEditor) {
$attributes['onclick'] = "return false;";
} else {
$url = trim($url);
if (substr($url, 0, 11) === "javascript:") {
return '#';
} else {
preg_match('/^([a-zA-Z]+)\[(.*)]$/', $url, $matches);
if (!empty($matches)) {
$matches[1] = ucfirst($matches[1]);
$parser = self::getParser($matches[1]);
if ($parser) {
$url = $parser->parse($matches[2], $attributes);
}
} else {
$url = ResourceTranslator::toUrl($url);
}
}
}
return $url;
}
public static function getParser($className) {
if (!isset(self::$parsers[$className])) {
foreach (self::$registeredNamespaces as $namespace) {
$class = $namespace . $className;
if (class_exists($class)) {
self::$parsers[$className] = new $class();
break;
}
}
if (!isset(self::$parsers[$className])) {
self::$parsers[$className] = false;
}
}
return self::$parsers[$className];
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace Nextend\Framework\Parser\Link;
interface ParserInterface {
public function parse($argument, &$attributes);
}

View File

@ -0,0 +1,48 @@
<?php
namespace Nextend\Framework\Parser\Link;
use Nextend\Framework\Asset\Js\Js;
use Nextend\SmartSlider3\Settings;
class ScrollTo implements ParserInterface {
public function __construct() {
Js::addInline('window.n2ScrollSpeed=' . json_encode(intval(Settings::get('smooth-scroll-speed', 400))) . ';');
}
public function parse($argument, &$attributes) {
switch ($argument) {
case 'top':
$onclick = 'n2ss.scroll(event, "top");';
break;
case 'bottom':
$onclick = 'n2ss.scroll(event, "bottom");';
break;
case 'beforeSlider':
$onclick = 'n2ss.scroll(event, "before", this.closest(".n2-ss-slider"));';
break;
case 'afterSlider':
$onclick = 'n2ss.scroll(event, "after", this.closest(".n2-ss-slider"));';
break;
case 'nextSlider':
$onclick = 'n2ss.scroll(event, "next", this, ".n2-section-smartslider");';
break;
case 'previousSlider':
$onclick = 'n2ss.scroll(event, "previous", this, ".n2-section-smartslider");';
break;
default:
if (is_numeric($argument)) {
$onclick = 'n2ss.scroll(event, "element", "#n2-ss-' . $argument . '");';
} else {
$onclick = 'n2ss.scroll(event, "element", "' . $argument . '");';
}
break;
}
$attributes['onclick'] = $onclick;
return '#';
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Nextend\Framework\Parser\Link;
use Nextend\Framework\Parser\Link;
class ScrollToAlias implements ParserInterface {
public function parse($argument, &$attributes) {
return Link::getParser('ScrollTo')
->parse('[data-alias=\"' . $argument . '\"]', $attributes);
}
}