ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
+318
View File
@@ -0,0 +1,318 @@
<?php
namespace Olegnax\Athlete2\Model;
use Closure;
use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Component\ComponentRegistrarInterface;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Olegnax\Core\Helper\Helper;
class Api
{
const THEME_PATH = 'frontend/Olegnax/athlete2';
public static function activate(Client $a, Closure $b, $c)
{
// Prepare
$d = $b();
if (!is_a($d, Request::class)) {
throw new Exception(__('Closure must return an object instance of Request.'));
}
// Call
if (!array_key_exists('domain', $d->request) || empty($d->request['domain'])) {
$d->request['domain'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Unknown';
}
$d->request['domain'] = preg_replace('/^(www|dev)\./i', '', $d->request['domain']);
$d->request['meta'] = static::getMeta();
$d->request['meta']['activate_user_ip'] = $d->request['meta']['user_ip'];
unset($d->request['meta']['user_ip']);
static::log(1000);
$e = $a->call(base64_decode('bGljZW5zZV9rZXlfYWN0aXZhdGU='), $d);
if ($e && isset($e->error)
&& $e->error === false
) {
if (isset($e->notices)) {
$d->notices = (array)$e->notices;
}
$d->data = (array)$e->data;
$d->touch();
call_user_func($c, (string)$d);
static::log(2000);
} elseif ($d) {
static::log(4000, [(array)$d->errors]);
} else {
static::log(3000);
}
return $e;
}
private static function getMeta()
{
return [
'user_ip' => static::getClientIp(),
'magento_version' => static::getMagentoVersion(),
'theme_version' => static::getThemeVersion(static::THEME_PATH),
];
}
public static function getClientIp()
{
return isset($_SERVER['HTTP_CLIENT_IP'])
? $_SERVER['HTTP_CLIENT_IP']
: (
isset($_SERVER['REMOTE_ADDR'])
? $_SERVER['REMOTE_ADDR']
: (
isset($_SERVER['REMOTE_HOST'])
? $_SERVER['REMOTE_HOST']
: 'UNKNOWN'
)
);
}
private static function getMagentoVersion()
{
return ObjectManager::getInstance()->get(ProductMetadataInterface::class)->getVersion();
}
private static function getThemeVersion($a)
{
/** @var ComponentRegistrarInterface $b */
$b = ObjectManager::getInstance()->get(ComponentRegistrarInterface::class);
$c = $b->getPath(ComponentRegistrar::THEME, $a);
if ($c) {
/** @var ReadFactory $d */
$d = ObjectManager::getInstance()->get(ReadFactory::class);
$e = $d->create($c);
if ($e->isExist('composer.json')) {
$f = (string)$e->readFile('composer.json');
$f = json_decode($f, true);
if (isset($f['version'])) {
return $f['version'];
}
}
}
return '';
}
protected static function log($message, array $context = [])
{
$level = (int)(floor($message / 1000) * 100);
static::_log($level, $message, $context);
}
protected static function _log($level, $message, array $context = [])
{
ObjectManager::getInstance()->get(Helper::class)->log($level, 'Athlete2', $message, $context);
}
public static function validate(
Client $a,
Closure $b,
$c,
$d = null,
$f = false,
$g = false,
$h = 2,
$i = '+1 hour'
) {
// Prepare
$j = $b();
if (!is_a($j, Request::class)) {
static::log(3010);
throw new Exception(' \Closure must return an object instance of Request.');
}
$j->updateVersion();
// Check j data
if ($j->isEmpty || empty($j->data['the_key'])) {
static::log(3020);
return false;
}
// No need to check if j already expired.
if ('active' != $j->data['status']) {
static::log(1010);
return false;
}
// Validate cached j data
if (!$f
&& time() < $j->nextCheck
&& $j->isValid
) {
return true;
}
// Call
if (empty($d)) {
$d = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Unknown';
}
$j->request['domain'] = preg_replace('/^(www|dev)\./i', '', $d);
$j->request['meta'] = static::getMeta();
$k = null;
try {
static::log(1000);
$k = $a->call(base64_decode('bGljZW5zZV9rZXlfdmFsaWRhdGU='), $j);
} catch (Exception $e) {
static::_log(400, $e->getMessage());
$k = null;
}
if (empty($k)) {
static::log(3000);
if ($g && $j->retries < $h) {
$j->addRetryAttempt($i);
static::log(3020,
[$j->retries . '/' . $h]);
call_user_func($c, (string)$j);
return true;
} else {
static::log(3030);
}
} elseif (isset($k->error)) {
$j->data = isset($k->data) ? (array)$k->data : [];
if ($k->error && isset($k->errors)) {
static::log(4010, [(array)$k->errors]);
$j->data = ['errors' => $k->errors];
} else {
static::log(2020);
}
$j->touch();
call_user_func($c, (string)$j);
return $k->error === false;
}
return false;
}
public static function deactivate(Client $a, Closure $b, $c, $d = null)
{
// Prepare
$e = $b();
if (!is_a($e, Request::class)) {
static::log(3010);
throw new Exception(' \Closure must return an object instance of Request.');
}
$e->updateVersion();
// Call
if (empty($d)) {
$d = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Unknown';
}
$e->request['domain'] = preg_replace('/^(www|dev)\./i', '', $d);
$e->request['meta'] = static::getMeta();
static::log(1000);
$f = $a->call(base64_decode('bGljZW5zZV9rZXlfZGVhY3RpdmF0ZQ=='), $e);
// Remove e
if ($f && isset($f->error)) {
if ($f->error === false) {
call_user_func($c, null);
static::log(2010);
} else {
if (isset($f->errors)) {
foreach ($f->errors as $key => $message) {
if ($key === base64_decode('YWN0aXZhdGlvbl9pZA==')) {
call_user_func($c, null);
static::log(2010);
break;
}
}
}
}
} else {
static::log(3000);
}
return $f;
}
public static function softValidate(Closure $a)
{
// Prepare
$b = $a();
if (!is_a($b, Request::class)) {
static::log(3010);
throw new Exception(' \Closure must return an object instance of Request.');
}
$b->updateVersion();
// Check b data
if ($b->isEmpty || !$b->data['the_key']) {
static::log(3020);
return false;
}
if ('active' != $b->data['status']) {
static::log(1010);
return false;
}
// Validate cached b data
return $b->isValid;
}
public static function check(
Client $a,
Closure $b,
$c,
$j,
$g = false,
$h = 2,
$i = '+1 hour'
) {
// Prepare
$d = $b();
if (!is_a($d, Request::class)) {
static::log(3010);
throw new Exception(' \Closure must return an object instance of Request.');
}
$d->updateVersion();
// Check d data
if ($d->isEmpty || !$d->data['the_key']) {
static::log(3020);
return false;
}
if ('active' != $d->data['status']) {
static::log(1010);
return false;
}
// Call
if (empty($j)) {
$j = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Unknown';
}
$d->request['domain'] = preg_replace('/^(www|dev)\./i', '', $j);
$f = null;
try {
static::log(1000);
$f = $a->call('license_key_validate', $d);
} catch (Exception $e) {
static::_log(400, $e->getMessage());
$f = null;
}
if (empty($f)) {
static::log(3000);
if ($g && $d->retries < $h) {
$d->addRetryAttempt($i);
static::log(3020,
[$d->retries . '/' . $h]);
call_user_func($c, (string)$d);
return true;
} else {
static::log(3030);
}
} elseif (isset($f->error)) {
$d->data = isset($f->data) ? (array)$f->data : [];
if ($f->error && isset($f->errors)) {
static::log(4010, [(array)$f->errors]);
$d->data = ['errors' => $f->errors];
} else {
static::log(2020);
}
$d->touch();
call_user_func($c, (string)$d);
return $f->error === false;
}
return $f;
}
}
+138
View File
@@ -0,0 +1,138 @@
<?php
namespace Olegnax\Athlete2\Model;
use Exception;
class Client
{
protected static $instance;
protected $a;
protected $b = [];
private $c;
public static function instance()
{
if (isset(static::$instance)) {
return static::$instance;
}
static::$instance = new self;
return static::$instance;
}
public function on($a, $b)
{
if (!is_array($this->b)) {
$this->b = [];
}
if (is_callable($b)) {
$this->b[$a] = $b;
}
return $this;
}
public function call($a, Request $b, $c = 'POST')
{
$d = microtime(true);
$this->trigger('start', [$d]);
// Begin
$this->setCurl($b);
$this->resolveEndpoint($a, $b);
// Make call
$url = $b->url . $a;
$this->trigger('endpoint', [$a, $url]);
curl_setopt($this->c, CURLOPT_URL, $url);
// Set method
$this->trigger('request', [$b->request]);
switch ($c) {
case 'GET':
curl_setopt($this->c, CURLOPT_POST, 0);
break;
case 'POST':
curl_setopt($this->c, CURLOPT_POST, 1);
if ($b->request && count($b->request) > 0) {
curl_setopt($this->c, CURLOPT_POSTFIELDS, http_build_query($b->request));
}
break;
case 'JPOST':
case 'JPUT':
case 'JGET':
case 'JDELETE':
$json = json_encode($b->request);
curl_setopt($this->c, CURLOPT_CUSTOMREQUEST, preg_replace('/J/', '', $c, -1));
curl_setopt($this->c, CURLOPT_POSTFIELDS, $json);
// Rewrite headers
curl_setopt($this->c, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($json),
]);
break;
}
// Get response
$this->a = curl_exec($this->c);
if (curl_errno($this->c)) {
$error = curl_error($this->c);
curl_close($this->c);
if (!empty($error)) {
throw new Exception($error);
}
} else {
curl_close($this->c);
}
$this->trigger('response', [$this->a]);
$this->trigger('finish', [microtime(true), $d]);
return empty($this->a) ? null : json_decode($this->a);
}
private function trigger($a, $b = [])
{
if (array_key_exists($a, $this->b)) {
call_user_func_array($this->b[$a], $b);
}
}
private function setCurl($a)
{
// Init
$this->c = curl_init();
// Sets basic parameters
curl_setopt($this->c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->c, CURLOPT_CONNECTTIMEOUT, 1);
if (isset($b->settings['timeout'])) {
curl_setopt($this->с, CURLOPT_TIMEOUT, $b->settings['timeout']);
}
// Set parameters to maintain cookies across sessions
curl_setopt($this->c, CURLOPT_COOKIESESSION, true);
curl_setopt($this->c, CURLOPT_COOKIEFILE, sys_get_temp_dir() . '/cookies_file');
curl_setopt($this->c, CURLOPT_COOKIEJAR, sys_get_temp_dir() . '/cookies_file');
curl_setopt($this->c, CURLOPT_USERAGENT, 'OLEGNAX-PURCHASE-VERIFY');
if (preg_match('/https\:/', $a)) {
$this->setSSL();
}
}
private function setSSL()
{
curl_setopt($this->c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->c, CURLOPT_RETURNTRANSFER, 1);
}
private function resolveEndpoint(&$a, Request $b)
{
switch ($b->handler) {
case 'wp_rest':
$a = base64_decode('L3dwLWpzb24vd29vLWxpY2Vuc2Uta2V5cy92MS8=')
. str_replace(base64_decode('bGljZW5zZV9rZXlf'), '', $a);
break;
default:
$a = '?action=' . $a;
break;
}
}
}
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* System config Logo image field backend model
*/
namespace Olegnax\Athlete2\Model\Config\Backend\Image;
use Magento\Config\Model\Config\Backend\Image;
class Logo extends Image
{
/**
* The tail part of directory path for uploading
*
*/
const UPLOAD_DIR = 'athlete2';
/**
* Return path to directory for upload file
*
* @return string
* @throw \Magento\Framework\Exception\LocalizedException
*/
protected function _getUploadDir()
{
return $this->_mediaDirectory->getAbsolutePath($this->_appendScopeInfo(self::UPLOAD_DIR));
}
/**
* Makes a decision about whether to add info about the scope.
*
* @return boolean
*/
protected function _addWhetherScopeInfo()
{
return true;
}
/**
* Getter for allowed extensions of uploaded files.
*
* @return string[]
*/
protected function _getAllowedExtensions()
{
return ['jpg', 'jpeg', 'gif', 'png', 'svg'];
}
}
@@ -0,0 +1,46 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Backend;
use Magento\Config\Model\Config\Backend\Serialized as BackendSerialized;
class Serialized extends BackendSerialized
{
/**
* @return $this
*/
public function beforeSave()
{
$groups = $this->getData('groups');
$fieldConfig = $this->getData('field_config');
$depends = true;
if (isset($fieldConfig['depends'])) {
foreach ($fieldConfig['depends']['fields'] as $field) {
$value = $field['value'];
$dependPath = $field['dependPath'];
array_shift($dependPath);
if (isset($groups[$dependPath[0]]['fields'][$dependPath[1]]['value'])
&& $groups[$dependPath[0]]['fields'][$dependPath[1]]['value'] != $value
) {
$depends = false;
}
}
}
if (is_array($this->getValue())) {
$value = $this->getValue();
if (array_key_exists('__empty', $value)) {
unset($value['__empty']);
}
if (empty($value) && !$depends) {
$value = $this->getOldValue();
}
$this->setValue($value);
}
parent::beforeSave();
return $this;
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class BgPositionX implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'center' => __( 'Center' ),
'left' => __( 'Left' ),
'right' => __( 'Right' ),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class BgPositionY implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'center' => __( 'Center' ),
'top' => __( 'Top' ),
'bottom' => __( 'Bottom' ),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class BgRepeat implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'repeat' => __( 'Repeat' ),
'no-repeat' => __( 'No Repeat' ),
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class BgSize implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'auto' => __( 'Auto' ),
'cover' => __( 'Cover' ),
'contain' => __( 'Contain' ),
];
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
use Magento\Framework\Option\ArrayInterface;
class Blocks implements ArrayInterface {
protected $_options;
/**
* Block collection factory
*
* @var CollectionFactory
*/
protected $_blockCollectionFactory;
/**
* Construct
*
* @param CollectionFactory $blockCollectionFactory
*/
public function __construct( CollectionFactory $blockCollectionFactory ) {
$this->_blockCollectionFactory = $blockCollectionFactory;
}
/**
* {@inheritdoc}
*/
public function toOptionArray() {
if ( !$this->_options ) {
$this->_options = [];
$colection = $this->_blockCollectionFactory->create()->load();
foreach ( $colection as $block ) {
$this->_options[] = [ 'value' => $block->getIdentifier(), 'label' => $block->getTitle() ];
}
array_unshift( $this->_options, [ 'value' => '', 'label' => __( 'Please select a static block.' ) ] );
}
return $this->_options;
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Blog;
use Magento\Framework\Option\ArrayInterface;
class Columns implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'1' => __('1'),
'2' => __('2'),
'3' => __('3'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Blog;
use Magento\Framework\Option\ArrayInterface;
class ListStyle implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'image-top' => __('Image Top'),
'image-left' => __('Image Left'),
'above-image' => __('Content Above Image, Fullwidth'),
'overlay' => __('Content Above Image, Normal'),
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Blog;
use Magento\Framework\Option\ArrayInterface;
class PageLayout implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'' => __('Use Default'),
'1column' => __('1 Column'),
'2columns-left' => __('2 Columns with Left bar'),
'2columns-right' => __('2 Columns with Right bar'),
'1column-fullwidth' => __('1 Column, Full Width '),
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Blog;
use Magento\Framework\Option\ArrayInterface;
class PostListStyle implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'' => __('Use Global'),
'image-top' => __('Image Top'),
'image-left' => __('Image Left'),
'above-image' => __('Content Above Image, Fullwidth'),
'overlay' => __('Content Above Image, Normal'),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Blog;
use Magento\Framework\Option\ArrayInterface;
class RelatedColumns implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'2' => __('2'),
'3' => __('3'),
'4' => __('4'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Blog;
use Magento\Framework\Option\ArrayInterface;
class RelatedColumnsProductPage implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'1' => __('1'),
'2' => __('2'),
'3' => __('3'),
'4' => __('4'),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class ButtonStyle implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'' => __( 'Athlete Default (Slide from Left)' ),
'simple' => __( 'Simple (Fade)' ),
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Carousel;
use Magento\Framework\Option\ArrayInterface;
class Align implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'left' => __('Left'),
'center' => __('Center'),
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Carousel;
use Magento\Framework\Option\ArrayInterface;
class Arrows implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'title' => __('Title'),
'hover' => __('Left/Right on Hover'),
];
}
}
@@ -0,0 +1,30 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Catalog\Products;
use Magento\Framework\Option\ArrayInterface;
class Columns implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'2' => __('2'),
'3' => __('3'),
'4' => __('4'),
'5' => __('5'),
'6' => __('6'),
'7' => __('7'),
'8' => __('8'),
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Catalog\Products;
use Magento\Framework\Option\ArrayInterface;
class ColumnsMobile implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'2' => __('2'),
'1' => __('1'),
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Catalog\Products;
use Magento\Framework\Option\ArrayInterface;
class ColumnsTablet implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'2' => __('2'),
'3' => __('3'),
'4' => __('4'),
'5' => __('5'),
'6' => __('6'),
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Catalog\Products;
use Magento\Framework\Option\ArrayInterface;
class ProductsLayout implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'1' => __('All Actions Above Image - Centered'),
'3' => __('Add to cart Bottom, Secondary Above Image - Centered'),
'2' => __('Quickview Above Image - Bottom Left, Secondary Bottom'),
'4' => __('Actions Bottom, Always Visible'),
'5' => __('Add to cart Bottom, Secondary Above Image - Top Right'),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Catalog\Products;
use Magento\Framework\Option\ArrayInterface;
class QuickviewPosition implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'' => __('Default to Layout'),
'bottom-left' => __('Bottom Left'),
'bottom-full' => __('Bottom Full Width'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Catalog\Products;
use Magento\Framework\Option\ArrayInterface;
class RelatedPosition implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'' => __('Default, In Content'),
'oxbottom' => __('Before Page Bottom, After Content'),
'bottom' => __('Page Bottom'),
'gallery' => __('Below Gallery')
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Contacts;
use Magento\Framework\Option\ArrayInterface;
class FirstBlockType implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'content' => __('Content'),
'image' => __('Image'),
'google_map' => __('Google Map'),
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Contacts;
use Magento\Framework\Option\ArrayInterface;
class Layout implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'default' => __('Standard'),
'left-right' => __('One Half Split'),
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class FontDisplay implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'fallback' => __( 'Fallback' ),
'auto' => __( 'Auto' ),
'block' => __( 'Block' ),
'swap' => __( 'Swap' ),
'optional' => __( 'Optional' ),
];
}
}
@@ -0,0 +1,32 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Footer;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class CopyrightLayout implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'1' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/copyright-layout-01.png' ),
'2' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/copyright-layout-02.png' ),
];
}
}
@@ -0,0 +1,34 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Footer;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class FooterLayout implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'1' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/footer-layout-01.png' ),
'2' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/footer-layout-02.png' ),
'4' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/footer-layout-04.jpg' ),
'3' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/footer-layout-03.png' ),
];
}
}
@@ -0,0 +1,32 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Footer;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class NewsletterStyle implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'small' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/newsletter_small.png' ),
'big' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/newsletter_big.png' ),
];
}
}
@@ -0,0 +1,25 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Footer;
use Magento\Framework\Option\ArrayInterface;
class StoreSwitcherPosition implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'below-newsletter' => __('Below Footer Newsletter Block'),
'footer-content' => __('Below Footer Content'),
'custom' => __('Custom/Do not display'),
];
}
}
@@ -0,0 +1,70 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class GoogleFonts implements ArrayInterface {
private $font_api = 'https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha&key=AIzaSyAELicRrZCL8Refz-D2-FeyahisL1hUoYc';
private function _getApiFonts() {
$ch = curl_init();
curl_setopt_array( $ch, array(
CURLOPT_URL => $this->font_api,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_RETURNTRANSFER => 1,
) );
$result = curl_exec( $ch );
curl_close( $ch );
if ( empty( $result ) ) {
return [ ];
}
$fonts = json_decode( (string) $result, true );
if ( array_key_exists( 'items', $fonts ) ) {
return $fonts[ 'items' ];
}
return [ ];
}
public function _mapFonts( $font ) {
if ( array_key_exists( 'family', $font ) ) {
return [
'value' => $font[ 'family' ],
'label' => $font[ 'family' ],
'variants' => $font[ 'variants' ],
];
}
return [ ];
}
private function _prepareFonts() {
$fonts = $this->_getApiFonts();
if ( !empty( $fonts ) && is_array( $fonts ) ) {
$fonts = array_map( [$this, '_mapFonts' ], $fonts );
$fonts = array_filter( $fonts );
}
return $fonts;
}
public function toOptionArray() {
$fonts = $this->_prepareFonts();
return $fonts;
}
public function toArray() {
$fonts = $this->_prepareFonts();
$_fonts = [];
foreach ( $fonts as $font ) {
$_fonts[$font['value']] = $font['label'];
}
return $_fonts;
}
}
@@ -0,0 +1,69 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class GoogleFontsVariants implements ArrayInterface {
private $font_api = 'https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha&key=AIzaSyAELicRrZCL8Refz-D2-FeyahisL1hUoYc';
private function _getApiFonts() {
$ch = curl_init();
curl_setopt_array( $ch, array(
CURLOPT_URL => $this->font_api,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_RETURNTRANSFER => 1,
) );
$result = curl_exec( $ch );
curl_close( $ch );
if ( empty( $result ) ) {
return [ ];
}
$fonts = json_decode( (string)$result, true );
if ( array_key_exists( 'items', $fonts ) ) {
return $fonts[ 'items' ];
}
return [ ];
}
public function _mapVariant( $variant ) {
return [
'value' => $variant,
'label' => $variant,
];
}
private function _prepareFonts() {
$fonts = $this->_getApiFonts();
$variants = [];
foreach( $fonts as $font ){
$variants = array_merge( $variants, $font['variants'] );
}
$variants = array_unique( $variants );
sort( $variants );
$variants = array_map([$this, '_mapVariant'], $variants);
return $variants;
}
public function toOptionArray() {
$fonts = $this->_prepareFonts();
return $fonts;
}
public function toArray() {
$fonts = $this->toOptionArray();
$_fonts = [ ];
foreach ( $fonts as $font ) {
$_fonts[ $font[ 'value' ] ] = $font[ 'label' ];
}
return $_fonts;
}
}
@@ -0,0 +1,23 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class AccountAction implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Open Login/My Acount page')],
['value' => 'simple', 'label' => __('Simple Drop Down with Links')],
['value' => 'login', 'label' => __('Drop Down/Slideout with Login Form')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,22 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class BannerColumns implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('1')],
['value' => '2', 'label' => __('2')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,22 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class BannerType implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => 'textfield', 'label' => __('Custom HTML')],
['value' => 'custom_block', 'label' => __('Static Block')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,22 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class HeaderBannerMode implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => 'always', 'label' => __('Always')],
['value' => 'once', 'label' => __('Once')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,23 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class HeaderItemPosition implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Don\'t Show')],
['value' => 'topline', 'label' => __('in Top Line/My Account Drop')],
['value' => 'main', 'label' => __('in Main Header')],
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,23 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class HeaderItemPositionAccount implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => 'none', 'label' => __('Don\'t Show')],
['value' => 'topline', 'label' => __('in Top Line')],
['value' => 'main', 'label' => __('in Main Header')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,24 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class HeaderItemPositionMobile implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Inherit, Same as Desktop')],
['value' => 'none', 'label' => __('Don\'t Show')],
['value' => 'main', 'label' => __('in Main Header')],
['value' => 'slideout', 'label' => __('in Navigation Slideout')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,35 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class Layout implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'header_1' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-layout-01.png' ),
'header_2' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-layout-02.png' ),
'header_4' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-layout-04.png' ),
'header_5' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-layout-05.png' ),
'header_6' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-layout-06.png' ),
];
}
}
@@ -0,0 +1,23 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class MenuAlign implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => 'left', 'label' => __('Left')],
['value' => 'center', 'label' => __('Center')],
['value' => 'right', 'label' => __('Right')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,24 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class MenuAlignSticky implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Same as Header (inherit)')],
['value' => 'left', 'label' => __('Left')],
['value' => 'center', 'label' => __('Center')],
['value' => 'right', 'label' => __('Right')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,23 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class MenuPosition implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('In Header')],
['value' => '2', 'label' => __('Below Header')],
];
}
public function toArray()
{
return [
'1' => __('In Header'),
'2' => __('Below Header'),
];
}
}
@@ -0,0 +1,35 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class MenuStyle implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'menu-style-1' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-menu-v1.png' ),
'menu-style-2' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-menu-v2.png' ),
'menu-style-3' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-menu-v3.png' ),
'menu-style-4' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-menu-v4.png' ),
'menu-style-5' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/header-menu-v5.png' ),
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class MinicartStyle implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => 'classic', 'label' => __('Athlete Classic')],
['value' => 'modern', 'label' => __('Modern')],
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class MinicartType implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'dropdown-click' => __( 'Dropdown Click' ),
'dropdown-hover' => __( 'Dropdown Hover' ),
'slideout' => __( 'Slideout' ),
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header\Mobile;
use Magento\Framework\Option\ArrayInterface;
class Layout implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'1' => __('Logo Left'),
'2' => __('Logo Above'),
/*'3' => __('Menu, Logo, Search, Wishlist, Cart'),*/
'4' => __('Search + Menu, Logo Centered, Wishlist + Cart'),
'5' => __('Menu + Search, Logo Centered, Wishlist + Cart'),
/*'6' => __('Menu, Logo Centered, Other Items'),*/
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class SearchStyle implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Default - No border')],
['value' => 'border-single', 'label' => __('Single Border')],
['value' => 'border-double', 'label' => __('Double Border')],
['value' => 'underlined', 'label' => __('Underlined')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,27 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Header;
use Magento\Framework\Option\ArrayInterface;
class SearchType implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'panel' => __( 'Simple Input' ),
'overlay' => __( 'Fullscreen' ),
'slideout' => __( 'Slideout' ),
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class PageLayouts implements ArrayInterface
{
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'' => __('Use Default'),
'1column' => __('1 Column'),
'1column-fullwidth' => __('1 Column, Full Width '),
'2columns-left' => __('2 Columns with Left bar'),
'2columns-right' => __('2 Columns with Right bar'),
'3columns' => __('3 Columns'),
];
}
}
@@ -0,0 +1,46 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class PageLocation implements ArrayInterface {
const HOMEPAGE = 'cms_index_index';
const CATEGORY = 'catalog_category_view';
const PRODUCT = 'catalog_product_view';
const PAGE = 'cms_page_view';
const CHECKOUT = 'checkout_cart_index';
public function toOptionArray() {
$options = [
[
'label' => __( 'All Pages' ),
'value' => '',
],
[
'label' => __( 'Home Page' ),
'value' => self::HOMEPAGE,
],
[
'label' => __( 'Category pages' ),
'value' => self::CATEGORY,
],
[
'label' => __( 'Product pages' ),
'value' => self::PRODUCT,
],
[
'label' => __( 'CMS Pages' ),
'value' => self::PAGE,
],
[
'label' => __( 'Shopping Cart' ),
'value' => self::CHECKOUT,
]
];
return $options;
}
}
@@ -0,0 +1,32 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Product;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class ActionsPosition implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'1' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/actions-layout-1.jpg' ),
'2' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/actions-layout-2.jpg' ),
];
}
}
@@ -0,0 +1,33 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Product;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class GalleryLayout implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'fast' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/gallery-layout-02.png' ),
'1col' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/gallery-layout-01.jpg' ),
'2cols' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/gallery-layout-03.jpg' ),
];
}
}
@@ -0,0 +1,23 @@
<?php /**/
namespace Olegnax\Athlete2\Model\Config\Settings\Product;
use Magento\Framework\Option\ArrayInterface;
class ImageBehavior implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Default')],
['value' => 'center', 'label' => __('Align center in block')],
['value' => 'stretch', 'label' => __('Stretch to the block size')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Product;
use Magento\Framework\Option\ArrayInterface;
class ReviewPosition implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Default. In Content, Below Tabs')],
['value' => 'intabs', 'label' => __('Move Reviews in Tabs')],
['value' => 'oxbottom', 'label' => __('Before Page Bottom, After Content')],
['value' => 'bottom', 'label' => __('Page Bottom')],
['value' => 'gallery', 'label' => __('Below Gallery')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Product;
use Magento\Framework\Option\ArrayInterface;
class TabsPosition implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Default, In Content')],
['value' => 'info', 'label' => __('Move Tabs to Product Info block')],
['value' => 'oxbottom', 'label' => __('Before Page Bottom, After Content')],
['value' => 'bottom', 'label' => __('Page Bottom')],
['value' => 'gallery', 'label' => __('Below Gallery')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,33 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Product;
use Magento\Framework\Option\ArrayInterface;
use Magento\Framework\View\Asset\Repository;
class TabsStyle implements ArrayInterface
{
protected $_assetRepo;
public function __construct(
Repository $assetRepo
) {
$this->_assetRepo = $assetRepo;
}
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray()
{
return [
'' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/tabs-style-01.png' ),
'minimal' => $this->_assetRepo->getUrl( 'Olegnax_Athlete2::images/tabs-style-02.png' ),
];
}
}
@@ -0,0 +1,12 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings\Radio;
use Magento\Framework\Option\ArrayInterface;
class Radio implements ArrayInterface
{
public function toOptionArray()
{
return [['value' => 'left', 'label' => __('Left')], ['value' => 'right', 'label' => __('Right')]];
}
}
@@ -0,0 +1,28 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class TextTransform implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'' => __( 'Choose Text Transform...' ),
'uppercase' => __( 'Uppercase' ),
'capitalize' => __( 'Capitalize' ),
'initial' => __( 'Initial' ),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Olegnax\Athlete2\Model\Config\Settings;
use Magento\Framework\Option\ArrayInterface;
class TitleSize implements ArrayInterface {
public function toOptionArray() {
$optionArray = [ ];
$array = $this->toArray();
foreach ( $array as $key => $value ) {
$optionArray[] = [ 'value' => $key, 'label' => $value ];
}
return $optionArray;
}
public function toArray() {
return [
'h1' => __( 'Big (H1)' ),
'h2' => __( 'Medium (H2,H3)' ),
];
}
}
+180
View File
@@ -0,0 +1,180 @@
<?php
namespace Olegnax\Athlete2\Model\DynamicStyle;
use Exception;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Message\ManagerInterface as MessageManager;
use Magento\Framework\Registry;
use Magento\Framework\View\LayoutInterface as ViewLayout;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface as StoreManager;
use Olegnax\Athlete2\Block\Template;
use Olegnax\Athlete2\Helper\CssFiles;
use Olegnax\Athlete2\Helper\Helper;
class Generator
{
/**
* Store Manager
*
* @var StoreManager
*/
private $_storeManager;
/**
* Theme css files
*
* @var CssFiles
*/
private $_cssFiles;
/**
* Registry
*
* @var Registry
*/
private $_registry;
/**
* File
*
* @var File
*/
private $_file;
/**
* View Layout
*
* @var ViewLayout
*/
private $_viewLayout;
/**
* Store Manager
*
* @var MessageManager
*/
private $_messageManager;
/**
* @var Helper
*/
private $_helper;
/**
* Generator constructor.
* @param StoreManager $storeManager
* @param CssFiles $cssFiles
* @param Registry $registry
* @param File $file
* @param ViewLayout $viewLayout
* @param MessageManager $messageManager
* @param Helper $helper
*/
public function __construct(
StoreManager $storeManager,
CssFiles $cssFiles,
Registry $registry,
File $file,
ViewLayout $viewLayout,
MessageManager $messageManager,
Helper $helper
) {
$this->_storeManager = $storeManager;
$this->_cssFiles = $cssFiles;
$this->_registry = $registry;
$this->_file = $file;
$this->_viewLayout = $viewLayout;
$this->_messageManager = $messageManager;
$this->_helper = $helper;
}
public function generate($type, $website, $store)
{
$this->generateCSS($type, $website, $store);
}
public function generateCSS($type, $website, $store)
{
if (!empty($website)) {
$this->generateWebsite($type, $website, 'css');
} elseif (!empty($store)) {
$this->generateStore($type, $store, 'css');
} else {
$this->generateAll($type, 'css');
}
}
private function generateWebsite($type, $id, $format)
{
$website = $this->_storeManager->getWebsite($id);
$stores = $website->getStoreIds();
if (!empty($stores) && is_array($stores)) {
foreach ($stores as $store) {
$this->generateStore($type, $store, $format);
}
}
}
private function generateStore($type, $id, $format)
{
$store = $this->_storeManager->getStore($id);
if (!$store->isActive()) {
return;
}
$storeCode = $store->getCode();
$dynamicTemplate = sprintf('dynamic_%s/%s.phtml', $format, $type);
$dynamicFile = sprintf('%s/%s_%s.%s', $this->_cssFiles->getDymanicDir(), $type, $storeCode, $format);
try {
$this->_file->createDirectory(dirname($dynamicFile), 0775);
$block = $this->_viewLayout->getBlock($type . $storeCode . $format);
if (!$block) {
$block = $this->_viewLayout->createBlock(
Template::class,
$type . $storeCode . $format
);
}
$content = $block->setData([
'area' => 'frontend',
'dynamic_store_code' => $storeCode
])
->setTemplate($dynamicTemplate)
->toHtml();
if (!empty($content)) {
$content = preg_replace('/[\r\n\t]/', ' ', $content);
$content = preg_replace('/[\r\n\t ]{2,}/', ' ', $content);
$content = preg_replace('/\s+(\:|\;|\{|\})\s+/', '\1', $content);
$content = preg_replace('/<[^<>]+>(.*?)<\/[^<>]+>/m', '/* Forbidden tags in styles */', $content);
}
$this->_file->filePutContents($dynamicFile, $content);
$dynamic_file_arg = $this->_helper->getSystemValue(
'athlete2_design/appearance_custom/dynamic_file_arg'
);
$dynamic_file_arg = abs((int) $dynamic_file_arg);
$dynamic_file_arg++;
$this->_helper->setSystemValue(
'athlete2_design/appearance_custom/dynamic_file_arg',
$dynamic_file_arg,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
} catch (Exception $e) {
$this->_messageManager->addError(sprintf(__('Failed generaing file: %s<br/>Message: %s'),
str_replace(BP, '', $dynamicFile), $e->getMessage()));
}
}
private function generateAll($type, $format)
{
$websites = $this->_storeManager->getWebsites(false, false);
if (!empty($websites) && is_array($websites)) {
foreach ($websites as $website => $value) {
$this->generateWebsite($type, $website, $format);
}
}
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace Olegnax\Athlete2\Model;
class Encryption
{
public static function a($a, $b)
{
return trim(self::b($a));
}
public static function b($a)
{
$b = base64_encode($a);
$b = str_replace(array('+', '/', '='), array('-', '_', ''), $b);
return $b;
}
public static function c($a, $b)
{
return trim(self::d($a));
}
public static function d($a)
{
$b = str_replace(array('-', '_'), array('+', '/'), $a);
$c = strlen($b) % 4;
if ($c) {
$b .= substr('====', $c);
}
return base64_decode($b);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace Olegnax\Athlete2\Model;
use Exception;
use Magento\Framework\Notification\MessageInterface;
use Olegnax\Athlete2\Helper\Helper;
class Message implements MessageInterface
{
const MESSAGE_IDENTITY = 'ox_athlete2';
protected $_text;
protected $_helper;
public function __construct(Helper $helper)
{
$this->_helper = $helper;
$license = $helper->get();
if ($this->_helper->isEnabled()
&& !empty($license)
&& isset($license->data->the_key)
&& $license->data->the_key == $helper->getSystemDefaultValue('athlete2_license/general/code')
&& $license->data->status == "active"
) {
try {
if (!$this->_helper->validate()) {
throw new Exception('License validate failed');
}
} catch (Exception $e) {
$this->_text = sprintf(__('Olegnax Athlete2: %s'), $e->getMessage());
}
}
}
public function getIdentity()
{
return static::MESSAGE_IDENTITY;
}
public function getSeverity()
{
return MessageInterface::SEVERITY_CRITICAL;
}
public function isDisplayed()
{
$text = $this->getText();
return !empty($text);
}
public function getText()
{
return $this->_text;
}
}
+258
View File
@@ -0,0 +1,258 @@
<?php
namespace Olegnax\Athlete2\Model;
use Exception;
class Request
{
const DAILY_FREQUENCY = 'daily';
const HOURLY_FREQUENCY = 'hourly';
const WEEKLY_FREQUENCY = 'weekly';
protected $settings = [];
protected $request = [];
protected $data = [];
protected $notices = [];
protected $meta = [];
public function __construct($a)
{
$a = json_decode((string)$a);
if (isset($a->settings)) {
$this->settings = (array)$a->settings;
}
if (isset($a->request)) {
$this->request = (array)$a->request;
}
if (isset($a->data)) {
$this->data = (array)$a->data;
}
if (isset($a->meta)) {
$this->meta = (array)$a->meta;
}
// Check for activation_id
if (!isset($this->request['activation_id'])
&& isset($this->data['activation_id'])
) {
$this->request['activation_id'] = $this->data['activation_id'];
}
if (!isset($this->request['license_key'])
&& isset($this->data['the_key'])
) {
$this->request['license_key'] = $this->data['the_key'];
}
}
public static function create($a, $b, $c, $d, $e = '', $f = self::DAILY_FREQUENCY, $g = null)
{
$h = [
'settings' => [
'url' => $a,
'frequency' => $f === null ? self::DAILY_FREQUENCY : $f,
'next_check' => 0,
'version' => '1.2.0',
'retries' => 0,
'handler' => $g,
],
'request' => [
'store_code' => $b,
'sku' => $c,
'license_key' => $d,
'domain' => $e,
],
'data' => [],
'meta' => [],
];
return new self(json_encode($h));
}
public function &__get($a)
{
$b = null;
switch ($a) {
case 'url':
if (isset($this->settings['url'])) {
return $this->settings['url'];
}
break;
case 'frequency':
if (isset($this->settings['frequency'])) {
return $this->settings['frequency'];
}
break;
case 'nextCheck':
if (isset($this->settings['next_check'])) {
return $this->settings['next_check'];
}
break;
case 'request':
return $this->request;
case 'data':
return $this->data;
case 'notices':
return $this->notices;
case 'isOffline':
$b = isset($this->settings['offline']);
break;
case 'isOfflineValid':
$b = $this->settings['offline']
&& ($this->settings['offline'] === true
|| time() < $this->settings['offline']
);
break;
case 'isValid':
$b = false;
if (isset($this->settings['frequency'])
&& !empty($this->settings['frequency'])
&& isset($this->data)
&& !empty($this->data)
&& isset($this->data['activation_id'])
&& is_numeric($this->data['activation_id'])
) {
$b = $this->data['the_key'] !== null && 'active' === $this->data['status'];
}
break;
case 'isEmpty':
$b = empty($this->data);
break;
case 'version':
if (isset($this->settings['version'])) {
return $this->settings['version'];
}
break;
case 'retries':
if (isset($this->settings['retries'])) {
return $this->settings['retries'];
}
break;
case 'handler':
if (isset($this->settings['handler'])) {
return $this->settings['handler'];
}
break;
}
return $b;
}
public function __set($a, $b)
{
switch ($a) {
case 'data':
$this->data = $b;
break;
case 'notices':
$this->notices = $b;
break;
}
}
public function __toString()
{
return json_encode([
'settings' => $this->settings,
'request' => $this->request,
'data' => $this->data,
'notices' => $this->notices,
'notice' => $this->getNotice(),
'meta' => $this->meta,
]);
}
public function getNotice()
{
$a = '';
if (isset($this->notices)) {
foreach ($this->notices as $notice_group => $notices) {
$a .= sprintf('<span data-group="%s">%s</span> ', $notice_group, implode(' ', $notices));
}
$a = trim($a);
}
return $a;
}
public function enableOffline()
{
$this->settings['offline'] = $this->data['offline_interval'] === 'unlimited'
? true
: strtotime('+' . ((int)$this->data['offline_value']) . ' ' . $this->data['offline_interval']);
$this->touch(false);
}
public function touch($a = true)
{
$this->settings['retries'] = 0;
if ($a && isset($this->settings['offline'])) {
unset($this->settings['offline']);
}
if (!isset($this->settings['frequency'])) {
return;
}
switch ($this->settings['frequency']) {
case self::DAILY_FREQUENCY:
$this->settings['next_check'] = strtotime('+1 days');
break;
case self::HOURLY_FREQUENCY:
$this->settings['next_check'] = strtotime('+1 hour');
break;
case self::WEEKLY_FREQUENCY:
$this->settings['next_check'] = strtotime('+1 week');
break;
default:
$this->settings['next_check'] = strtotime($this->settings['frequency']);
break;
}
}
public function addRetryAttempt($a)
{
$this->settings['retries']++;
$this->settings['next_check'] = strtotime($a);
}
public function updateVersion()
{
switch ($this->settings['version']) {
case null:
$this->settings['version'] = '1.0.6';
$this->settings['retries'] = 0;
break;
case '1.0.6':
$this->settings['version'] = '1.1.0';
$this->meta = [];
break;
case '1.1.0':
$this->settings['version'] = '1.2.0';
$this->settings['handler'] = null;
break;
}
}
public function add($a, $b = null)
{
if (!is_string($a)) {
throw new Exception('Meta key must be a string.');
}
if (!is_array($this->meta)) {
$this->meta = [];
}
$this->meta[$a] = is_object($b) ? (array)$b : $b;
}
public function get($a, $b = null)
{
if (!is_string($a)) {
throw new Exception('Meta key must be a string.');
}
return array_key_exists($a, $this->meta) ? $this->meta[$a] : $b;
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
/**
* @author Olegnax
* @package Olegnax_Athlete2
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\Athlete2\Model;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
class Spacer extends Field {
public function __construct(
Context $context, array $data = []
) {
parent::__construct($context, $data);
}
protected function _decorateRowHtml( AbstractElement $element, $html)
{
return '<tr id="row_' . $element->getHtmlId() . '"><td></td><td colspan="2"><hr class="ox-settings-spacer"></td></tr>';
}
}