820715be by Jeff Balicki

ee

1 parent 40e9d171
Showing 900 changed files with 5032 additions and 0 deletions
<?php
if (!defined('NEXTEND_SMARTSLIDER_3_URL_PATH')) {
define('NEXTEND_SMARTSLIDER_3_URL_PATH', 'smart-slider3');
}
define('N2WORDPRESS', 1);
define('N2JOOMLA', 0);
define('N2GSAP', 0);
define('N2SSPRO', 0);
\ No newline at end of file
<?php
namespace Nextend;
class Autoloader {
private static $instance = null;
private $aliases = array(
'N2Data' => '\\Nextend\\Framework\\Data\\Data',
'N2SmartSliderBackup' => '\\Nextend\\SmartSlider3\\BackupSlider\\BackupData',
'N2SmartSliderImport' => '\\Nextend\\SmartSlider3\\BackupSlider\\ImportSlider',
'N2SmartSliderExport' => '\\Nextend\\SmartSlider3\\BackupSlider\\ExportSlider',
);
/**
* An associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected $prefixes = array();
public function __construct() {
$this->addNamespace('Nextend\\', dirname(__FILE__));
$this->register();
$currentPath = dirname(__FILE__) . '/';
foreach (scandir($currentPath) as $file) {
if ($file == '.' || $file == '..') continue;
$path = $currentPath . $file;
if (is_dir($path)) {
$className = '\\Nextend\\' . $file . '\\' . $file;
if (class_exists($className) && is_callable(array(
$className,
'getInstance'
))) {
call_user_func_array(array(
$className,
'getInstance'
), array());
}
}
}
Nextend::getInstance();
}
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new Autoloader();
}
return self::$instance;
}
/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register() {
spl_autoload_register(array(
$this,
'loadClass'
));
}
/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $base_dir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
*
* @return void
*/
public function addNamespace($prefix, $base_dir, $prepend = false) {
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/';
// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = array();
}
// retain the base directory for the namespace prefix
if ($prepend) {
array_unshift($this->prefixes[$prefix], $base_dir);
} else {
array_push($this->prefixes[$prefix], $base_dir);
}
}
/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
*
* @return mixed The mapped file name on success, or boolean false on
* failure.
*/
public function loadClass($class) {
// the current namespace prefix
$prefix = $class;
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (false !== $pos = strrpos($prefix, '\\')) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
// the rest is the relative class name
$relative_class = substr($class, $pos + 1);
// try to load a mapped file for the prefix and relative class
$mapped_file = $this->loadMappedFile($prefix, $relative_class);
if ($mapped_file) {
return $mapped_file;
}
// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
}
if (isset($this->aliases[$class]) && class_exists($this->aliases[$class])) {
/**
* Create class alias for old class names
*/
class_alias($this->aliases[$class], $class);
return true;
}
// never found a mapped file
return false;
}
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
*
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function loadMappedFile($prefix, $relative_class) {
// are there any base directories for this namespace prefix?
if (isset($this->prefixes[$prefix]) === false) {
return false;
}
// look through base directories for this namespace prefix
foreach ($this->prefixes[$prefix] as $base_dir) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// if the mapped file exists, require it
if ($this->requireFile($file)) {
// yes, we're done
return $file;
}
}
// never found it
return false;
}
/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
*
* @return bool True if the file exists, false if not.
*/
protected function requireFile($file) {
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
}
Autoloader::getInstance();
\ No newline at end of file
<?php
namespace Nextend\Framework\Acl;
use Nextend\Framework\Pattern\MVCHelperTrait;
abstract class AbstractPlatformAcl {
/**
* @param $action
* @param MVCHelperTrait $MVCHelper
*
* @return bool
*/
abstract public function authorise($action, $MVCHelper);
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Acl;
use Nextend\Framework\Acl\Joomla\JoomlaAcl;
use Nextend\Framework\Acl\WordPress\WordPressAcl;
use Nextend\Framework\Pattern\MVCHelperTrait;
class Acl {
/**
* @var AbstractPlatformAcl
*/
private static $instance;
public function __construct() {
self::$instance = new WordPressAcl();
}
/**
* @param $action
* @param MVCHelperTrait $MVCHelper
*
* @return bool
*/
public static function canDo($action, $MVCHelper) {
return self::$instance->authorise($action, $MVCHelper);
}
}
new Acl();
\ No newline at end of file
<?php
namespace Nextend\Framework\Acl\WordPress;
use Nextend\Framework\Acl\AbstractPlatformAcl;
use function current_user_can;
class WordPressAcl extends AbstractPlatformAcl {
public function authorise($action, $MVCHelper) {
return current_user_can($action) && current_user_can('unfiltered_html');
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework;
use Exception;
use JHttp;
use Nextend\Framework\Misc\Base64;
use Nextend\Framework\Misc\HttpClient;
use Nextend\Framework\Notification\Notification;
use Nextend\Framework\Platform\Platform;
use Nextend\Framework\Url\Url;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\Application\ApplicationSmartSlider3;
use WP_HTTP_Proxy;
class Api {
private static $api = 'https://api.nextendweb.com/v1/';
public static function getApiUrl() {
return self::$api;
}
public static function api($posts, $returnUrl = false) {
$api = self::getApiUrl();
$posts_default = array(
'platform' => Platform::getName()
);
$posts = $posts + $posts_default;
if ($returnUrl) {
return $api . '?' . http_build_query($posts, '', '&');
}
if (!isset($data)) {
if (function_exists('curl_init') && function_exists('curl_exec') && Settings::get('curl', 1)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($posts, '', '&'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
$proxy = new WP_HTTP_Proxy();
if ($proxy->is_enabled() && $proxy->send_through_proxy($api)) {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy->host());
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy->port());
if ($proxy->use_authentication()) {
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy->authentication());
}
}
if (Settings::get('curl-clean-proxy', 0)) {
curl_setopt($ch, CURLOPT_PROXY, '');
}
$data = curl_exec($ch);
$errorNumber = curl_errno($ch);
if ($errorNumber == 60 || $errorNumber == 77) {
curl_setopt($ch, CURLOPT_CAINFO, HttpClient::getCacertPath());
$data = curl_exec($ch);
}
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$error = curl_error($ch);
$curlErrorNumber = curl_errno($ch);
curl_close($ch);
if ($curlErrorNumber) {
$href = ApplicationSmartSlider3::getInstance()
->getApplicationTypeAdmin()
->getUrlHelpCurl();
Notification::error(Html::tag('a', array(
'href' => $href . '#support-form'
), n2_('Debug error')));
Notification::error($curlErrorNumber . $error);
return array(
'status' => 'ERROR_HANDLED'
);
}
} else {
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($posts, '', '&')
)
);
$context = stream_context_create($opts);
$data = file_get_contents($api, false, $context);
if ($data === false) {
Notification::error(n2_('CURL disabled in your php.ini configuration. Please enable it!'));
return array(
'status' => 'ERROR_HANDLED'
);
}
$headers = self::parseHeaders($http_response_header);
if ($headers['status'] != '200') {
Notification::error(n2_('Unable to contact with the licensing server, please try again later!'));
return array(
'status' => 'ERROR_HANDLED'
);
}
if (isset($headers['content-type'])) {
$contentType = $headers['content-type'];
}
}
}
switch ($contentType) {
case 'text/html; charset=UTF-8':
Notification::error(sprintf('Unexpected response from the API.<br>Contact us (support@nextendweb.com) with the following log:') . '<br><textarea style="width: 100%;height:200px;font-size:8px;">' . Base64::encode($data) . '</textarea>');
return array(
'status' => 'ERROR_HANDLED'
);
break;
case 'application/json':
return json_decode($data, true);
}
return $data;
}
private static function parseHeaders(array $headers, $header = null) {
$output = array();
if ('HTTP' === substr($headers[0], 0, 4)) {
list(, $output['status'], $output['status_text']) = explode(' ', $headers[0]);
unset($headers[0]);
}
foreach ($headers as $v) {
$h = preg_split('/:\s*/', $v);
if (count($h) >= 2) {
$output[strtolower($h[0])] = $h[1];
}
}
if (null !== $header) {
if (isset($output[strtolower($header)])) {
return $output[strtolower($header)];
}
return null;
}
return $output;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Application;
use Nextend\Framework\Pattern\SingletonTrait;
use Nextend\Framework\Plugin;
abstract class AbstractApplication {
use SingletonTrait;
protected $key = '';
protected function init() {
//PluggableApplication\Nextend\SmartSlider3\Application\ApplicationSmartSlider3
Plugin::doAction('PluggableApplication\\' . get_class($this), array($this));
}
public function getKey() {
return $this->key;
}
public function enqueueAssets() {
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Application;
use Exception;
use Nextend\Framework\Controller\AbstractController;
use Nextend\Framework\Pattern\GetAssetsPathTrait;
use Nextend\Framework\Pattern\MVCHelperTrait;
use Nextend\Framework\Plugin;
use Nextend\Framework\Request\Request;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
use Nextend\Framework\Router\Router;
use Nextend\Framework\View\AbstractLayout;
abstract class AbstractApplicationType {
use GetAssetsPathTrait, MVCHelperTrait;
/** @var AbstractApplication */
protected $application;
/** @var Router */
protected $router;
protected $key = '';
/** @var AbstractLayout */
protected $layout;
protected $externalControllers = array();
/**
* AbstractApplicationType constructor.
*
* @param AbstractApplication $application
*
* @throws Exception
*/
public function __construct($application) {
$this->setMVCHelper($this);
$this->application = $application;
ResourceTranslator::createResource('$' . $this->getKey() . '$', self::getAssetsPath(), self::getAssetsUri());
$this->createRouter();
//PluggableApplicationType\Nextend\SmartSlider3\Application\Admin\ApplicationTypeAdmin
Plugin::doAction('PluggableApplicationType\\' . get_class($this), array($this));
}
public function getKey() {
return $this->application->getKey() . '-' . $this->key;
}
protected function createRouter() {
}
public function processRequest($defaultControllerName, $defaultActionName, $ajax = false, $args = array()) {
$controllerName = trim(Request::$REQUEST->getCmd("nextendcontroller"));
if (empty($controllerName)) {
$controllerName = $defaultControllerName;
}
$actionName = trim(Request::$REQUEST->getCmd("nextendaction"));
if (empty($actionName)) {
$actionName = $defaultActionName;
}
$this->process($controllerName, $actionName, $ajax, $args);
}
public function process($controllerName, $actionName, $ajax = false, $args = array()) {
if ($ajax) {
Request::$isAjax = true;
}
/** @var AbstractController $controller */
$controller = $this->getController($controllerName, $ajax);
$controller->doAction($actionName, $args);
}
/**
* @param $controllerName
* @param bool $ajax
*
* @return AbstractController
*/
protected function getController($controllerName, $ajax = false) {
$methodName = 'getController' . ($ajax ? 'Ajax' : '') . $controllerName;
if (method_exists($this, $methodName)) {
return call_user_func(array(
$this,
$methodName
));
} else if (isset($this->externalControllers[$controllerName])) {
return call_user_func(array(
$this->externalControllers[$controllerName],
$methodName
));
}
return $this->getDefaultController($controllerName, $ajax);
}
protected abstract function getDefaultController($controllerName, $ajax = false);
public function getApplication() {
return $this->application;
}
public function getApplicationType() {
return $this;
}
/**
* @return Router
*/
public function getRouter() {
return $this->router;
}
public function enqueueAssets() {
$this->application->enqueueAssets();
}
/**
* @param AbstractLayout $layout
*/
public function setLayout($layout) {
$this->layout = $layout;
}
public function addExternalController($name, $source) {
$this->externalControllers[$name] = $source;
}
public function getLogo() {
return file_get_contents(self::getAssetsPath() . '/images/logo.svg');
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset;
use Nextend\Framework\Misc\Base64;
class AbstractAsset {
/**
* @var AbstractCache
*/
protected $cache;
protected $files = array();
protected $urls = array();
protected $codes = array();
protected $globalInline = array();
protected $firstCodes = array();
protected $inline = array();
protected $staticGroupPreload = array();
protected $staticGroup = array();
protected $groups = array();
public function addFile($pathToFile, $group) {
$this->addGroup($group);
$this->files[$group][] = $pathToFile;
}
public function addFiles($path, $files, $group) {
$this->addGroup($group);
foreach ($files as $file) {
$this->files[$group][] = $path . DIRECTORY_SEPARATOR . $file;
}
}
public function addStaticGroupPreload($file, $group) {
$this->staticGroupPreload[$group] = $file;
}
public function addStaticGroup($file, $group) {
$this->staticGroup[$group] = $file;
}
private function addGroup($group) {
if (!isset($this->files[$group])) {
$this->files[$group] = array();
}
}
public function addCode($code, $group, $unshift = false) {
if (!isset($this->codes[$group])) {
$this->codes[$group] = array();
}
if (!$unshift) {
$this->codes[$group][] = $code;
} else {
array_unshift($this->codes[$group], $code);
}
}
public function addUrl($url) {
$this->urls[] = $url;
}
public function addFirstCode($code, $unshift = false) {
if ($unshift) {
array_unshift($this->firstCodes, $code);
} else {
$this->firstCodes[] = $code;
}
}
public function addInline($code, $name = null, $unshift = false) {
if ($unshift) {
array_unshift($this->inline, $code);
} else {
if ($name) {
$this->inline[$name] = $code;
} else {
$this->inline[] = $code;
}
}
}
public function addGlobalInline($code, $unshift = false) {
if ($unshift) {
array_unshift($this->globalInline, $code);
} else {
$this->globalInline[] = $code;
}
}
public function loadedFilesEncoded() {
return Base64::encode(json_encode(call_user_func_array('array_merge', $this->files) + $this->urls));
}
protected function uniqueFiles() {
foreach ($this->files as $group => &$files) {
$this->files[$group] = array_values(array_unique($files));
}
$this->initGroups();
}
public function removeFiles($notNeededFiles) {
foreach ($this->files as $group => &$files) {
$this->files[$group] = array_diff($files, $notNeededFiles);
}
}
public function initGroups() {
$this->groups = array_unique(array_merge(array_keys($this->files), array_keys($this->codes)));
$skeleton = array_map(array(
AbstractAsset::class,
'emptyArray'
), array_flip($this->groups));
$this->files += $skeleton;
$this->codes += $skeleton;
}
private static function emptyArray() {
return array();
}
public function getFiles() {
$this->uniqueFiles();
$files = array();
if (AssetManager::$cacheAll) {
foreach ($this->groups as $group) {
if (isset($this->staticGroup[$group])) continue;
$files[$group] = $this->cache->getAssetFile($group, $this->files[$group], $this->codes[$group]);
}
} else {
foreach ($this->groups as $group) {
if (isset($this->staticGroup[$group])) continue;
if (in_array($group, AssetManager::$cachedGroups)) {
$files[$group] = $this->cache->getAssetFile($group, $this->files[$group], $this->codes[$group]);
} else {
foreach ($this->files[$group] as $file) {
$files[] = $file;
}
foreach ($this->codes[$group] as $code) {
array_unshift($this->inline, $code);
}
}
}
}
if (isset($files['n2'])) {
return array('n2' => $files['n2']) + $this->staticGroup + $files;
}
return array_merge($files, $this->staticGroup);
}
public function serialize() {
return array(
'staticGroupPreload' => $this->staticGroupPreload,
'staticGroup' => $this->staticGroup,
'files' => $this->files,
'urls' => $this->urls,
'codes' => $this->codes,
'firstCodes' => $this->firstCodes,
'inline' => $this->inline,
'globalInline' => $this->globalInline
);
}
public function unSerialize($array) {
$this->staticGroupPreload = array_merge($this->staticGroupPreload, $array['staticGroupPreload']);
$this->staticGroup = array_merge($this->staticGroup, $array['staticGroup']);
foreach ($array['files'] as $group => $files) {
if (!isset($this->files[$group])) {
$this->files[$group] = $files;
} else {
$this->files[$group] = array_merge($this->files[$group], $files);
}
}
$this->urls = array_merge($this->urls, $array['urls']);
foreach ($array['codes'] as $group => $codes) {
if (!isset($this->codes[$group])) {
$this->codes[$group] = $codes;
} else {
$this->codes[$group] = array_merge($this->codes[$group], $codes);
}
}
$this->firstCodes = array_merge($this->firstCodes, $array['firstCodes']);
$this->inline = array_merge($this->inline, $array['inline']);
$this->globalInline = array_merge($this->globalInline, $array['globalInline']);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset;
use Nextend\Framework\Cache\Manifest;
use Nextend\Framework\Filesystem\Filesystem;
abstract class AbstractCache {
public $outputFileType;
protected $group, $files, $codes;
public function getAssetFile($group, &$files = array(), &$codes = array()) {
$this->group = $group;
$this->files = $files;
$this->codes = $codes;
$cache = new Manifest($group, true, true);
$hash = $this->getHash();
return $cache->makeCache($group . "." . $this->outputFileType, $hash, array(
$this,
'getCachedContent'
));
}
protected function getHash() {
$hash = '';
foreach ($this->files as $file) {
$hash .= $this->makeFileHash($file);
}
foreach ($this->codes as $code) {
$hash .= $code;
}
return md5($hash);
}
protected function getCacheFileName() {
$hash = '';
foreach ($this->files as $file) {
$hash .= $this->makeFileHash($file);
}
foreach ($this->codes as $code) {
$hash .= $code;
}
return md5($hash) . "." . $this->outputFileType;
}
/**
* @param Manifest $cache
*
* @return string
*/
public function getCachedContent($cache) {
$fileContents = '';
foreach ($this->files as $file) {
$fileContents .= $this->parseFile($cache, Filesystem::readFile($file), $file) . "\n";
}
foreach ($this->codes as $code) {
$fileContents .= $code . "\n";
}
return $fileContents;
}
protected function makeFileHash($file) {
return $file . filemtime($file);
}
/**
* @param Manifest $cache
* @param $content
* @param $originalFilePath
*
* @return mixed
*/
protected function parseFile($cache, $content, $originalFilePath) {
return $content;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset;
use Nextend\Framework\Data\Data;
use Nextend\Framework\PageFlow;
use Nextend\Framework\Plugin;
use Nextend\Framework\View\Html;
/**
* Class Manager
*
*/
class AssetManager {
/**
* Helper to safely store AssetManager related optimization data
*
* @var Data
*/
public static $stateStorage;
/**
* @var CSS\Asset
*/
public static $css;
private static $cssStack = array();
/**
* @var Css\Less\Asset
*/
public static $less;
private static $lessStack = array();
/**
* @var Js\Asset
*/
public static $js;
private static $jsStack = array();
/**
* @var Fonts\Google\Asset
*/
public static $googleFonts;
/**
* @var Image\Asset
*/
public static $image;
private static $imageStack = array();
private static $googleFontsStack = array();
public static $cacheAll = true;
public static $cachedGroups = array();
public static function getInstance() {
static $instance = null;
if (null === $instance) {
$instance = new self();
self::createStack();
Plugin::doAction('n2_assets_manager_started');
}
return $instance;
}
public static function createStack() {
self::$stateStorage = new Data();
self::$css = new Css\Asset();
array_unshift(self::$cssStack, self::$css);
self::$less = new Css\Less\Asset();
array_unshift(self::$lessStack, self::$less);
self::$js = new Js\Asset();
array_unshift(self::$jsStack, self::$js);
self::$googleFonts = new Fonts\Google\Asset();
array_unshift(self::$googleFontsStack, self::$googleFonts);
self::$image = new Image\Asset();
array_unshift(self::$imageStack, self::$image);
}
public static function removeStack() {
if (count(self::$cssStack) > 0) {
self::$stateStorage = new Data();
/**
* @var $previousCSS Css\Asset
* @var $previousLESS Css\Less\Asset
* @var $previousJS Js\Asset
* @var $previousGoogleFons Fonts\Google\Asset
* @var $previousImage Image\Asset
*/
$previousCSS = array_shift(self::$cssStack);
self::$css = self::$cssStack[0];
$previousLESS = array_shift(self::$lessStack);
self::$less = self::$lessStack[0];
$previousJS = array_shift(self::$jsStack);
self::$js = self::$jsStack[0];
$previousGoogleFons = array_shift(self::$googleFontsStack);
self::$googleFonts = self::$googleFontsStack[0];
$previousImage = array_shift(self::$imageStack);
self::$image = self::$imageStack[0];
return array(
'css' => $previousCSS->serialize(),
'less' => $previousLESS->serialize(),
'js' => $previousJS->serialize(),
'googleFonts' => $previousGoogleFons->serialize(),
'image' => $previousImage->serialize()
);
}
echo "Too much remove stack on the asset manager...";
PageFlow::exitApplication();
}
public static function enableCacheAll() {
self::$cacheAll = true;
}
public static function disableCacheAll() {
self::$cacheAll = false;
}
public static function addCachedGroup($group) {
if (!in_array($group, self::$cachedGroups)) {
self::$cachedGroups[] = $group;
}
}
public static function loadFromArray($array) {
self::$css->unSerialize($array['css']);
self::$less->unSerialize($array['less']);
self::$js->unSerialize($array['js']);
self::$googleFonts->unSerialize($array['googleFonts']);
self::$image->unSerialize($array['image']);
}
public static function getCSS($path = false) {
if (self::$css) {
if ($path) {
return self::$css->get();
}
return self::$css->getOutput();
}
return '';
}
public static function getJs($path = false) {
if (self::$js) {
if ($path) {
return self::$js->get();
}
return self::$js->getOutput();
}
return '';
}
public static function generateAjaxCSS() {
return Html::style(self::$css->getAjaxOutput());
}
public static function generateAjaxJS() {
return self::$js->getAjaxOutput();
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css;
use Nextend\Framework\Asset\AbstractAsset;
use Nextend\Framework\Asset\Fonts\Google\Google;
use Nextend\Framework\Platform\Platform;
use Nextend\Framework\Plugin;
use Nextend\Framework\Settings;
use Nextend\Framework\Url\Url;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\SmartSlider3Info;
class Asset extends AbstractAsset {
public function __construct() {
$this->cache = new Cache();
}
public function getOutput() {
$headerPreload = !!Settings::get('header-preload', '0');
$needProtocol = !Settings::get('protocol-relative', '1');
Google::build();
Less\Less::build();
$output = "";
$this->urls = array_unique($this->urls);
foreach ($this->staticGroupPreload as $file) {
$url = $this->filterSrc(Url::pathToUri($file, $needProtocol) . '?ver=' . SmartSlider3Info::$revisionShort);
$output .= Html::style($url, true, array(
'media' => 'all'
)) . "\n";
if ($headerPreload) {
header('Link: <' . $url . '>; rel=preload; as=style', false);
}
}
$linkAttributes = array(
'media' => 'all'
);
if (!Platform::isAdmin() && Settings::get('async-non-primary-css', 0)) {
$linkAttributes = array(
'media' => 'print',
'onload' => "this.media='all'"
);
}
foreach ($this->urls as $url) {
$url = $this->filterSrc($url);
$output .= Html::style($url, true, $linkAttributes) . "\n";
}
foreach ($this->getFiles() as $file) {
if (substr($file, 0, 2) == '//') {
$url = $this->filterSrc($file);
} else {
$url = $this->filterSrc(Url::pathToUri($file, $needProtocol) . '?ver=' . SmartSlider3Info::$revisionShort);
}
$output .= Html::style($url, true, $linkAttributes) . "\n";
}
$inlineText = '';
foreach ($this->inline as $key => $value) {
if (!is_numeric($key)) {
$output .= Html::style($value, false, array(
'data-related' => $key
)) . "\n";
} else {
$inlineText .= $value;
}
}
if (!empty($inlineText)) {
$output .= Html::style($inlineText) . "\n";
}
return $output;
}
private function filterSrc($src) {
return Plugin::applyFilters('n2_style_loader_src', $src);
}
public function get() {
Google::build();
Less\Less::build();
return array(
'url' => $this->urls,
'files' => array_merge($this->staticGroupPreload, $this->getFiles()),
'inline' => implode("\n", $this->inline)
);
}
public function getAjaxOutput() {
$output = implode("\n", $this->inline);
return $output;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css;
use Nextend\Framework\Asset\AbstractCache;
use Nextend\Framework\Filesystem\Filesystem;
use Nextend\Framework\Url\Url;
class Cache extends AbstractCache {
public $outputFileType = "css";
private $baseUrl = '';
private $basePath = '';
public function getAssetFileFolder() {
return Filesystem::getWebCachePath() . DIRECTORY_SEPARATOR . $this->group . DIRECTORY_SEPARATOR;
}
protected function parseFile($cache, $content, $originalFilePath) {
$this->basePath = dirname($originalFilePath);
$this->baseUrl = Filesystem::pathToAbsoluteURL($this->basePath);
return preg_replace_callback('#url\([\'"]?([^"\'\)]+)[\'"]?\)#', array(
$this,
'makeAbsoluteUrl'
), $content);
}
private function makeAbsoluteUrl($matches) {
if (substr($matches[1], 0, 5) == 'data:') return $matches[0];
if (substr($matches[1], 0, 4) == 'http') return $matches[0];
if (substr($matches[1], 0, 2) == '//') return $matches[0];
$exploded = explode('?', $matches[1]);
$realPath = realpath($this->basePath . '/' . $exploded[0]);
if ($realPath === false) {
return 'url(' . str_replace(array(
'http://',
'https://'
), '//', $this->baseUrl) . '/' . $matches[1] . ')';
}
$realPath = Filesystem::convertToRealDirectorySeparator($realPath);
return 'url(' . Url::pathToUri($realPath, false) . (isset($exploded[1]) ? '?' . $exploded[1] : '') . ')';
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css;
use Nextend\Framework\Asset\AssetManager;
class Css {
public static function addFile($pathToFile, $group) {
AssetManager::$css->addFile($pathToFile, $group);
}
public static function addFiles($path, $files, $group) {
AssetManager::$css->addFiles($path, $files, $group);
}
public static function addStaticGroupPreload($file, $group) {
AssetManager::$css->addStaticGroupPreload($file, $group);
}
public static function addStaticGroup($file, $group) {
AssetManager::$css->addStaticGroup($file, $group);
}
public static function addCode($code, $group, $unshift = false) {
AssetManager::$css->addCode($code, $group, $unshift);
}
public static function addUrl($url) {
AssetManager::$css->addUrl($url);
}
public static function addInline($code, $name = null) {
AssetManager::$css->addInline($code, $name);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css\Less;
use Nextend\Framework\Asset\AbstractAsset;
class Asset extends AbstractAsset {
public function __construct() {
$this->cache = new Cache();
}
protected function uniqueFiles() {
$this->initGroups();
}
public function getFiles() {
$this->uniqueFiles();
$files = array();
foreach ($this->groups as $group) {
$files[$group] = $this->cache->getAssetFile($group, $this->files[$group], $this->codes[$group]);
}
return $files;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css\Less;
use Exception;
use Nextend\Framework\Cache\Manifest;
class Cache extends \Nextend\Framework\Asset\Css\Cache {
public $outputFileType = "less.css";
public function getAssetFile($group, &$files = array(), &$codes = array()) {
$this->group = $group;
$this->files = $files;
$this->codes = $codes;
$cache = new Manifest($group, false, true);
$hash = $this->getHash();
return $cache->makeCache($group . "." . $this->outputFileType, $hash, array(
$this,
'getCachedContent'
));
}
/**
* @param Manifest $cache
*
* @return string
* @throws Exception
*/
public function getCachedContent($cache) {
$fileContents = '';
foreach ($this->files as $parameters) {
$compiler = new LessCompiler();
if (!empty($parameters['importDir'])) {
$compiler->addImportDir($parameters['importDir']);
}
$compiler->setVariables($parameters['context']);
$fileContents .= $compiler->compileFile($parameters['file']);
}
return $fileContents;
}
protected function makeFileHash($parameters) {
return json_encode($parameters) . filemtime($parameters['file']);
}
protected function parseFile($cache, $content, $lessParameters) {
return parent::parseFile($cache, $content, $lessParameters['file']);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css\Less\Formatter;
class Classic {
public $indentChar = " ";
public $break = "\n";
public $open = " {";
public $close = "}";
public $selectorSeparator = ", ";
public $assignSeparator = ":";
public $openSingle = " { ";
public $closeSingle = " }";
public $disableSingle = false;
public $breakSelectors = false;
public $compressColors = false;
public function __construct() {
$this->indentLevel = 0;
}
public function indentStr($n = 0) {
return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
}
public function property($name, $value) {
return $name . $this->assignSeparator . $value . ";";
}
protected function isEmpty($block) {
if (empty($block->lines)) {
foreach ($block->children as $child) {
if (!$this->isEmpty($child)) return false;
}
return true;
}
return false;
}
public function block($block) {
$ret = '';
if ($this->isEmpty($block)) return $ret;
$inner = $pre = $this->indentStr();
$isSingle = !$this->disableSingle && is_null($block->type) && count($block->lines) == 1;
if (!empty($block->selectors)) {
$this->indentLevel++;
if ($this->breakSelectors) {
$selectorSeparator = $this->selectorSeparator . $this->break . $pre;
} else {
$selectorSeparator = $this->selectorSeparator;
}
$ret .= $pre . implode($selectorSeparator, $block->selectors);
if ($isSingle) {
$ret .= $this->openSingle;
$inner = "";
} else {
$ret .= $this->open . $this->break;
$inner = $this->indentStr();
}
}
if (!empty($block->lines)) {
$glue = $this->break . $inner;
$ret .= $inner . implode($glue, $block->lines);
if (!$isSingle && !empty($block->children)) {
$ret .= $this->break;
}
}
foreach ($block->children as $child) {
$ret .= $this->block($child);
}
if (!empty($block->selectors)) {
if (!$isSingle && empty($block->children)) $ret .= $this->break;
if ($isSingle) {
$ret .= $this->closeSingle . $this->break;
} else {
$ret .= $pre . $this->close . $this->break;
}
$this->indentLevel--;
}
return $ret;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css\Less\Formatter;
class Compressed extends Classic {
public $disableSingle = true;
public $open = "{";
public $selectorSeparator = ",";
public $assignSeparator = ":";
public $break = "";
public $compressColors = true;
public function indentStr($n = 0) {
return "";
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css\Less\Formatter;
class Debug extends Classic {
public $disableSingle = true;
public $breakSelectors = true;
public $assignSeparator = ": ";
public $selectorSeparator = ",";
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Css\Less;
use Nextend\Framework\Asset\AssetManager;
use Nextend\Framework\Asset\Css\Css;
class Less {
public static function addFile($pathToFile, $group, $context = array(), $importDir = null) {
AssetManager::$less->addFile(array(
'file' => $pathToFile,
'context' => $context,
'importDir' => $importDir
), $group);
}
public static function build() {
foreach (AssetManager::$less->getFiles() as $group => $file) {
if (substr($file, 0, 2) == '//') {
Css::addUrl($file);
} else if (!realpath($file)) {
// For database cache the $file contains the content of the generated CSS file
Css::addCode($file, $group, true);
} else {
Css::addFile($file, $group);
}
}
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Fonts\Google;
use Nextend\Framework\Asset\AbstractAsset;
use Nextend\Framework\Asset\Css\Css;
use Nextend\Framework\Url\UrlHelper;
class Asset extends AbstractAsset {
public function getLoadedFamilies() {
return array_keys($this->files);
}
function addFont($family, $style = '400') {
$style = (string)$style;
if (!isset($this->files[$family])) {
$this->files[$family] = array();
}
if (!in_array($style, $this->files[$family])) {
$this->files[$family][] = $style;
}
}
public function loadFonts() {
if (!empty($this->files)) {
//https://fonts.googleapis.com/css?display=swap&family=Montserrat:400%7CRoboto:100italic,300,400
$families = array();
foreach ($this->files as $name => $styles) {
if (count($styles) && !in_array($name, Google::$excludedFamilies)) {
$families[] = $name . ':' . implode(',', $styles);
}
}
if (count($families)) {
$params = array(
'display' => 'swap',
'family' => urlencode(implode('|', $families))
);
Css::addUrl(UrlHelper::add_query_arg($params, 'https://fonts.googleapis.com/css'));
}
}
return true;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Fonts\Google;
use Nextend\Framework\Asset\AssetManager;
class Google {
public static $enabled = false;
public static $excludedFamilies = array();
public static function addFont($family, $style = '400') {
AssetManager::$googleFonts->addFont($family, $style);
}
public static function addFontExclude($family) {
self::$excludedFamilies[] = $family;
}
public static function build() {
if (self::$enabled) {
AssetManager::$googleFonts->loadFonts();
}
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Image;
class Asset {
protected $images = array();
public function add($images) {
if (!is_array($images)) {
$images = array($images);
}
$this->images = array_unique(array_merge($this->images, $images));
}
public function get() {
return $this->images;
}
public function match($url) {
return in_array($url, $this->images);
}
public function serialize() {
return array(
'images' => $this->images
);
}
public function unSerialize($array) {
if (!empty($array['images'])) {
$this->add($array['images']);
}
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Js;
use Nextend\Framework\Asset\AbstractAsset;
use Nextend\Framework\Localization\Localization;
use Nextend\Framework\Platform\Platform;
use Nextend\Framework\Plugin;
use Nextend\Framework\Settings;
use Nextend\Framework\Url\Url;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\SmartSlider3Info;
class Asset extends AbstractAsset {
public function __construct() {
$this->cache = new Cache();
}
public function getOutput() {
$output = "";
$needProtocol = !Settings::get('protocol-relative', '1');
$globalInline = $this->getGlobalInlineScripts();
if (!empty($globalInline)) {
$output .= Html::script(self::minify_js($globalInline . "\n"));
}
$async = !Platform::isAdmin();
$scriptAttributes = array();
if ($async) {
$scriptAttributes['defer'] = 1;
$scriptAttributes['async'] = 1;
}
foreach ($this->urls as $url) {
$output .= Html::scriptFile($this->filterSrc($url), $scriptAttributes) . "\n";
}
foreach ($this->getFiles() as $file) {
if (substr($file, 0, 2) == '//') {
$output .= Html::scriptFile($this->filterSrc($file), $scriptAttributes) . "\n";
} else {
$output .= Html::scriptFile($this->filterSrc(Url::pathToUri($file, $needProtocol) . '?ver=' . SmartSlider3Info::$revisionShort), $scriptAttributes) . "\n";
}
}
$output .= Html::script(self::minify_js(Localization::toJS() . "\n" . $this->getInlineScripts() . "\n"));
return $output;
}
private function filterSrc($src) {
return Plugin::applyFilters('n2_script_loader_src', $src);
}
public function get() {
return array(
'url' => $this->urls,
'files' => $this->getFiles(),
'inline' => $this->getInlineScripts(),
'globalInline' => $this->getGlobalInlineScripts()
);
}
public function getAjaxOutput() {
$output = $this->getInlineScripts();
return $output;
}
private function getGlobalInlineScripts() {
return implode('', $this->globalInline);
}
private function getInlineScripts() {
$scripts = '';
foreach ($this->firstCodes as $script) {
$scripts .= $script . "\n";
}
foreach ($this->inline as $script) {
$scripts .= $script . "\n";
}
return $this->serveJquery($scripts);
}
public static function serveJquery($script) {
if (empty($script)) {
return "";
}
$inline = "_N2.r('documentReady', function(){\n";
$inline .= $script;
$inline .= "});\n";
return $inline;
}
public static function minify_js($input) {
if (trim($input) === "") return $input;
return preg_replace(array(
// Remove comment(s)
'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
// Remove white-space(s) outside the string and regex
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
// Remove the last semicolon
'#;+\}#',
// Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
// --ibid. From `foo['bar']` to `foo.bar`
'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
), array(
'$1',
'$1$2',
'}',
'$1$3',
'$1.$3'
), $input);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Js;
use Nextend\Framework\Asset\AbstractCache;
use Nextend\Framework\Cache\Manifest;
class Cache extends AbstractCache {
public $outputFileType = "js";
/**
* @param Manifest $cache
*
* @return string
*/
public function getCachedContent($cache) {
$content = '(function(){this._N2=this._N2||{_r:[],_d:[],r:function(){this._r.push(arguments)},d:function(){this._d.push(arguments)}}}).call(window);';
$content .= parent::getCachedContent($cache);
$content .= "_N2.d('" . $this->group . "');";
return $content;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset\Js;
use Nextend\Framework\Asset\AssetManager;
use Nextend\Framework\Filesystem\Filesystem;
class Js {
public static function addFile($pathToFile, $group) {
AssetManager::$js->addFile($pathToFile, $group);
}
public static function addFiles($path, $files, $group) {
AssetManager::$js->addFiles($path, $files, $group);
}
public static function addStaticGroup($file, $group) {
AssetManager::$js->addStaticGroup($file, $group);
}
public static function addCode($code, $group) {
AssetManager::$js->addCode($code, $group);
}
public static function addUrl($url) {
AssetManager::$js->addUrl($url);
}
public static function addFirstCode($code, $unshift = false) {
AssetManager::$js->addFirstCode($code, $unshift);
}
public static function addInline($code, $unshift = false) {
AssetManager::$js->addInline($code, null, $unshift);
}
public static function addGlobalInline($code, $unshift = false) {
AssetManager::$js->addGlobalInline($code, $unshift);
}
public static function addInlineFile($path, $unshift = false) {
static $loaded = array();
if (!isset($loaded[$path])) {
AssetManager::$js->addInline(Filesystem::readFile($path), null, $unshift);
$loaded[$path] = 1;
}
}
public static function addGlobalInlineFile($path, $unshift = false) {
static $loaded = array();
if (!isset($loaded[$path])) {
AssetManager::$js->addGlobalInline(Filesystem::readFile($path), $unshift);
$loaded[$path] = 1;
}
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Asset;
use JHtml;
use Nextend\Framework\Asset\Css\Css;
use Nextend\Framework\Asset\Fonts\Google\Google;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Font\FontSources;
use Nextend\Framework\Form\Form;
use Nextend\Framework\Platform\Platform;
use Nextend\Framework\Plugin;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
use Nextend\SmartSlider3\Application\Frontend\ApplicationTypeFrontend;
use Nextend\SmartSlider3\Settings;
class Predefined {
public static function backend($force = false) {
static $once;
if ($once != null && !$force) {
return;
}
$once = true;
wp_enqueue_script('jquery');
$jQueryFallback = site_url('wp-includes/js/jquery/jquery.js');
Js::addGlobalInline('_N2._jQueryFallback=\'' . $jQueryFallback . '\';');
$family = n2_x('Montserrat', 'Default Google font family for admin');
Google::addFont($family);
Js::addFirstCode("_N2.r(['AjaxHelper'],function(){_N2.AjaxHelper.addAjaxArray(" . json_encode(Form::tokenizeUrl()) . ");});");
Plugin::addAction('afterApplicationContent', array(
FontSources::class,
'onFontManagerLoadBackend'
));
}
public static function frontend($force = false) {
static $once;
if ($once != null && !$force) {
return;
}
$once = true;
AssetManager::getInstance();
if (Platform::isAdmin()) {
Js::addGlobalInline('window.N2GSAP=' . N2GSAP . ';');
Js::addGlobalInline('window.N2PLATFORM="' . Platform::getName() . '";');
}
Js::addGlobalInline('(function(){this._N2=this._N2||{_r:[],_d:[],r:function(){this._r.push(arguments)},d:function(){this._d.push(arguments)}}}).call(window);');
/*
* +1px needed for Safari to fix: https://bugs.webkit.org/show_bug.cgi?id=225962
(function(ua){
if(ua.indexOf('Safari') > 0 && ua.indexOf('Chrome') === -1){
document.documentElement.style.setProperty('--ss-safari-fix-225962', '1px');
}
})(navigator.userAgent);
*/
Js::addGlobalInline('!function(a){a.indexOf("Safari")>0&&-1===a.indexOf("Chrome")&&document.documentElement.style.setProperty("--ss-safari-fix-225962","1px")}(navigator.userAgent);');
Js::addStaticGroup(ApplicationTypeFrontend::getAssetsPath() . "/dist/n2.min.js", 'n2');
FontSources::onFontManagerLoad($force);
}
public static function loadLiteBox() {
}
}
<?php
namespace Nextend\Framework\Browse\Block\BrowseManager;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\View\AbstractBlock;
use Nextend\SmartSlider3\Application\Admin\TraitAdminUrl;
class BlockBrowseManager extends AbstractBlock {
use TraitAdminUrl;
public function display() {
Js::addFirstCode("new _N2.NextendBrowse('" . $this->getAjaxUrlBrowse() . "', " . (defined('N2_IMAGE_UPLOAD_DISABLE') ? 0 : 1) . ");");
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Browse;
use Nextend\Framework\Browse\Block\BrowseManager\BlockBrowseManager;
use Nextend\Framework\Pattern\VisualManagerTrait;
class BrowseManager {
use VisualManagerTrait;
public function display() {
$fontManagerBlock = new BlockBrowseManager($this->MVCHelper);
$fontManagerBlock->display();
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Browse\BulletProof;
class Exception extends \Exception {
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Browse;
use Exception;
use Nextend\Framework\Browse\BulletProof\BulletProof;
use Nextend\Framework\Controller\Admin\AdminAjaxController;
use Nextend\Framework\Filesystem\Filesystem;
use Nextend\Framework\Image\Image;
use Nextend\Framework\Notification\Notification;
use Nextend\Framework\Request\Request;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
class ControllerAjaxBrowse extends AdminAjaxController {
public function actionIndex() {
$this->validateToken();
$root = Filesystem::convertToRealDirectorySeparator(Filesystem::getImagesFolder());
$path = Filesystem::realpath($root . '/' . ltrim(rtrim(Request::$REQUEST->getVar('path', ''), '/'), '/'));
if (strpos($path, $root) !== 0) {
$path = $root;
}
$_directories = glob($path . '/*', GLOB_ONLYDIR);
$directories = array();
for ($i = 0; $i < count($_directories); $i++) {
$directories[basename($_directories[$i])] = Filesystem::toLinux($this->relative($_directories[$i], $root));
}
$extensions = array(
'jpg',
'jpeg',
'png',
'gif',
'mp4',
'mp3',
'svg',
'webp'
);
$_files = scandir($path);
$files = array();
for ($i = 0; $i < count($_files); $i++) {
$_files[$i] = $path . DIRECTORY_SEPARATOR . $_files[$i];
$ext = strtolower(pathinfo($_files[$i], PATHINFO_EXTENSION));
if (self::check_utf8($_files[$i]) && in_array($ext, $extensions)) {
$files[basename($_files[$i])] = ResourceTranslator::urlToResource(Filesystem::pathToAbsoluteURL($_files[$i]));
}
}
$relativePath = Filesystem::toLinux($this->relative($path, $root));
if (!$relativePath) {
$relativePath = '';
}
$this->response->respond(array(
'fullPath' => $path,
'path' => $relativePath,
'directories' => (object)$directories,
'files' => (object)$files
));
}
private static function check_utf8($str) {
$len = strlen($str);
for ($i = 0; $i < $len; $i++) {
$c = ord($str[$i]);
if ($c > 128) {
if (($c > 247)) return false; elseif ($c > 239) $bytes = 4;
elseif ($c > 223) $bytes = 3;
elseif ($c > 191) $bytes = 2;
else return false;
if (($i + $bytes) > $len) return false;
while ($bytes > 1) {
$i++;
$b = ord($str[$i]);
if ($b < 128 || $b > 191) return false;
$bytes--;
}
}
}
return true;
}
public function actionUpload() {
if (defined('N2_IMAGE_UPLOAD_DISABLE')) {
Notification::error(n2_('You are not allowed to upload!'));
$this->response->error();
}
$this->validateToken();
$root = Filesystem::getImagesFolder();
$folder = ltrim(rtrim(Request::$REQUEST->getVar('path', ''), '/'), '/');
$path = Filesystem::realpath($root . '/' . $folder);
if ($path === false || $path == '') {
$folder = preg_replace("/[^A-Za-z0-9]/", '', $folder);
if (empty($folder)) {
Notification::error(n2_('Folder is missing!'));
$this->response->error();
} else {
Filesystem::createFolder($root . '/' . $folder);
$path = Filesystem::realpath($root . '/' . $folder);
}
}
$relativePath = Filesystem::toLinux($this->relative($path, $root));
if (!$relativePath) {
$relativePath = '';
}
$response = array(
'path' => $relativePath
);
try {
if (isset($_FILES) && isset($_FILES['image']) && isset($_FILES['image']['name'])) {
$info = pathinfo($_FILES['image']['name']);
$fileName = preg_replace('/[^a-zA-Z0-9_-]/', '', $info['filename']);
if (strlen($fileName) == 0) {
$fileName = '';
}
$upload = new BulletProof();
$file = $upload->uploadDir($path)
->upload($_FILES['image'], $fileName);
$response['name'] = basename($file);
$response['url'] = ResourceTranslator::urlToResource(Filesystem::pathToAbsoluteURL($file));
Image::onImageUploaded($file);
}
} catch (Exception $e) {
Notification::error($e->getMessage());
$this->response->error();
}
$this->response->respond($response);
}
private function relative($path, $root) {
return substr(Filesystem::convertToRealDirectorySeparator($path), strlen($root));
}
}
<?php
namespace Nextend\Framework\Cache;
use Nextend\Framework\Cache\Storage\AbstractStorage;
abstract class AbstractCache {
protected $group = '';
protected $isAccessible = false;
/** @var AbstractStorage */
public $storage;
protected $_storageEngine = 'filesystem';
/**
* @param string $engine
*
* @return AbstractStorage
*/
public static function getStorage($engine = "filesystem") {
static $storage = null;
if ($storage === null) {
$storage = array(
'filesystem' => new Storage\Filesystem(),
'database' => new Storage\Database()
);
}
return $storage[$engine];
}
public static function clearAll() {
self::getStorage('filesystem')
->clearAll();
self::getStorage('filesystem')
->clearAll('web');
}
public static function clearGroup($group) {
self::getStorage('filesystem')
->clear($group);
self::getStorage('filesystem')
->clear($group, 'web');
self::getStorage('database')
->clear($group);
self::getStorage('database')
->clear($group, 'web');
}
public function __construct($group, $isAccessible = false) {
$this->group = $group;
$this->isAccessible = $isAccessible;
$this->storage = self::getStorage($this->_storageEngine);
}
protected function clearCurrentGroup() {
$this->storage->clear($this->group, $this->getScope());
}
protected function getScope() {
if ($this->isAccessible) {
return 'web';
}
return 'notweb';
}
protected function exists($key) {
return $this->storage->exists($this->group, $key, $this->getScope());
}
protected function get($key) {
return $this->storage->get($this->group, $key, $this->getScope());
}
protected function set($key, $value) {
$this->storage->set($this->group, $key, $value, $this->getScope());
}
protected function getPath($key) {
return $this->storage->getPath($this->group, $key, $this->getScope());
}
protected function remove($key) {
return $this->storage->remove($this->group, $key, $this->getScope());
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Cache;
use DateTime;
class CacheImage extends AbstractCache {
protected $_storageEngine = 'filesystem';
protected $lazy = false;
public function __construct($group) {
parent::__construct($group, true);
}
protected function getScope() {
return 'image';
}
public function setLazy($lazy) {
$this->lazy = $lazy;
}
/**
* @param $fileExtension
* @param callable $callable
* @param array $parameters
* @param bool $hash
*
* @return mixed
*/
public function makeCache($fileExtension, $callable, $parameters = array(), $hash = false) {
if (!$hash) {
$hash = $this->generateHash($fileExtension, $callable, $parameters);
}
if (strpos($parameters[1], '?') !== false) {
$fileNameParts = explode('?', $parameters[1]);
$keepFileName = pathinfo($fileNameParts[0], PATHINFO_FILENAME);
} else {
$keepFileName = pathinfo($parameters[1], PATHINFO_FILENAME);
}
$fileName = $hash . (!empty($keepFileName) ? '/' . $keepFileName : '');
$fileNameWithExtension = $fileName . '.' . $fileExtension;
$isCached = $this->exists($fileNameWithExtension);
if ($isCached) {
if (!$this->testManifestFile($fileName, $parameters[1])) {
$isCached = false;
}
}
if (!$isCached) {
if ($this->lazy) {
return $parameters[1];
}
array_unshift($parameters, $this->getPath($fileNameWithExtension));
call_user_func_array($callable, $parameters);
$this->createManifestFile($fileName, $parameters[2]);
}
return $this->getPath($fileNameWithExtension);
}
private function generateHash($fileExtension, $callable, $parameters) {
return md5(json_encode(array(
$fileExtension,
$callable,
$parameters
)));
}
protected function testManifestFile($fileName, $originalFile) {
$manifestKey = $this->getManifestKey($fileName);
if ($this->exists($manifestKey)) {
$manifestData = json_decode($this->get($manifestKey), true);
$newManifestData = $this->getManifestData($originalFile);
if ($manifestData['mtime'] == $newManifestData['mtime']) {
return true;
}
} else {
// Backward compatibility
$this->createManifestFile($fileName, $originalFile);
return true;
}
return false;
}
protected function createManifestFile($fileName, $originalFile) {
$this->set($this->getManifestKey($fileName), json_encode($this->getManifestData($originalFile)));
}
private function getManifestData($originalFile) {
$manifestData = array();
if (strpos($originalFile, '//') !== false) {
$manifestData['mtime'] = $this->getRemoteMTime($originalFile);
} else {
$manifestData['mtime'] = filemtime($originalFile);
}
return $manifestData;
}
private function getRemoteMTime($url) {
$h = get_headers($url, 1);
if (!$h || strpos($h[0], '200') !== false) {
foreach ($h as $k => $v) {
if (strtolower(trim($k)) == "last-modified") {
return (new DateTime($v))->getTimestamp();
}
}
}
return 0;
}
protected function getManifestKey($fileName) {
return $fileName . '.manifest';
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Cache;
class Manifest extends AbstractCache {
private $isRaw = false;
private $manifestData;
public function __construct($group, $isAccessible = false, $isRaw = false) {
parent::__construct($group, $isAccessible);
$this->isRaw = $isRaw;
}
protected function decode($data) {
return $data;
}
/**
* @param $fileName
* @param $hash
* @param callback $callable
*
* @return bool
*/
public function makeCache($fileName, $hash, $callable) {
if (!$this->isCached($fileName, $hash)) {
$return = call_user_func($callable, $this);
if ($return === false) {
return false;
}
return $this->createCacheFile($fileName, $hash, $return);
}
if ($this->isAccessible) {
return $this->getPath($fileName);
}
return $this->decode($this->get($fileName));
}
private function isCached($fileName, $hash) {
$manifestKey = $this->getManifestKey($fileName);
if ($this->exists($manifestKey)) {
$this->manifestData = json_decode($this->get($manifestKey), true);
if (!$this->isCacheValid($this->manifestData) || $this->manifestData['hash'] != $hash || !$this->exists($fileName)) {
$this->clean($fileName);
return false;
}
return true;
}
return false;
}
protected function createCacheFile($fileName, $hash, $content) {
$this->manifestData = array();
$this->manifestData['hash'] = $hash;
$this->addManifestData($this->manifestData);
$this->set($this->getManifestKey($fileName), json_encode($this->manifestData));
$this->set($fileName, $this->isRaw ? $content : json_encode($content));
if ($this->isAccessible) {
return $this->getPath($fileName);
}
return $content;
}
protected function isCacheValid(&$manifestData) {
return true;
}
protected function addManifestData(&$manifestData) {
}
public function clean($fileName) {
$this->remove($this->getManifestKey($fileName));
$this->remove($fileName);
}
protected function getManifestKey($fileName) {
return $fileName . '.manifest';
}
public function getData($key, $default = 0) {
return isset($this->manifestData[$key]) ? $this->manifestData[$key] : $default;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Cache\Storage;
abstract class AbstractStorage {
protected $paths = array();
public function isFilesystem() {
return false;
}
public abstract function clearAll($scope = 'notweb');
public abstract function clear($group, $scope = 'notweb');
public abstract function exists($group, $key, $scope = 'notweb');
public abstract function set($group, $key, $value, $scope = 'notweb');
public abstract function get($group, $key, $scope = 'notweb');
public abstract function remove($group, $key, $scope = 'notweb');
public abstract function getPath($group, $key, $scope = 'notweb');
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Cache\Storage;
use Nextend\Framework\Model\ApplicationSection;
use Nextend\Framework\Platform\Platform;
class Database extends AbstractStorage {
protected $db;
public function __construct() {
$this->paths['web'] = 'web';
$this->paths['notweb'] = 'notweb';
$this->paths['image'] = 'image';
$this->db = new ApplicationSection('cache');
}
public function clearAll($scope = 'notweb') {
}
public function clear($group, $scope = 'notweb') {
$this->db->delete($scope . '/' . $group);
}
public function exists($group, $key, $scope = 'notweb') {
if ($this->db->get($scope . '/' . $group, $key)) {
return true;
}
return false;
}
public function set($group, $key, $value, $scope = 'notweb') {
$this->db->set($scope . '/' . $group, $key, $value);
}
public function get($group, $key, $scope = 'notweb') {
return $this->db->get($scope . '/' . $group, $key);
}
public function remove($group, $key, $scope = 'notweb') {
$this->db->delete($scope . '/' . $group, $key);
}
public function getPath($group, $key, $scope = 'notweb') {
return Platform::getSiteUrl() . '?nextendcache=1&g=' . urlencode($group) . '&k=' . urlencode($key);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Cache\Storage;
class Filesystem extends AbstractStorage {
public function __construct() {
$this->paths['web'] = \Nextend\Framework\Filesystem\Filesystem::getWebCachePath();
$this->paths['notweb'] = \Nextend\Framework\Filesystem\Filesystem::getNotWebCachePath();
$this->paths['image'] = \Nextend\Framework\Filesystem\Filesystem::getImagesFolder();
}
public function isFilesystem() {
return true;
}
public function clearAll($scope = 'notweb') {
if (\Nextend\Framework\Filesystem\Filesystem::existsFolder($this->paths[$scope])) {
\Nextend\Framework\Filesystem\Filesystem::deleteFolder($this->paths[$scope]);
}
}
public function clear($group, $scope = 'notweb') {
if (\Nextend\Framework\Filesystem\Filesystem::existsFolder($this->paths[$scope] . '/' . $group)) {
\Nextend\Framework\Filesystem\Filesystem::deleteFolder($this->paths[$scope] . '/' . $group);
}
}
public function exists($group, $key, $scope = 'notweb') {
if (\Nextend\Framework\Filesystem\Filesystem::existsFile($this->paths[$scope] . '/' . $group . '/' . $key)) {
return true;
}
return false;
}
public function set($group, $key, $value, $scope = 'notweb') {
$path = $this->paths[$scope] . '/' . $group . '/' . $key;
$dir = dirname($path);
if (!\Nextend\Framework\Filesystem\Filesystem::existsFolder($dir)) {
\Nextend\Framework\Filesystem\Filesystem::createFolder($dir);
}
\Nextend\Framework\Filesystem\Filesystem::createFile($path, $value);
}
public function get($group, $key, $scope = 'notweb') {
return \Nextend\Framework\Filesystem\Filesystem::readFile($this->paths[$scope] . '/' . $group . '/' . $key);
}
public function remove($group, $key, $scope = 'notweb') {
if ($this->exists($group, $key, $scope)) {
@unlink($this->paths[$scope] . '/' . $group . '/' . $key);
}
}
public function getPath($group, $key, $scope = 'notweb') {
return $this->paths[$scope] . DIRECTORY_SEPARATOR . $group . DIRECTORY_SEPARATOR . $key;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Cache;
class StoreImage extends AbstractCache {
protected $_storageEngine = 'filesystem';
protected function getScope() {
return 'image';
}
public function makeCache($fileName, $content) {
if (!$this->isImage($fileName)) {
return false;
}
if (!$this->exists($fileName)) {
$this->set($fileName, $content);
}
return $this->getPath($fileName);
}
private function isImage($fileName) {
$supported_image = array(
'gif',
'jpg',
'jpeg',
'png',
'mp4',
'mp3',
'webp',
'svg'
);
$ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
if (in_array($ext, $supported_image)) {
return true;
}
return false;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework;
class Cast {
/**
* @param $number
*
* @return string the JavaScript float representation of the string
*/
public static function floatToString($number) {
return json_encode(floatval($number));
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Content;
abstract class AbstractPlatformContent {
/**
* @param $keyword
*
* @return array links
* $links[] = array(
* 'title' => '',
* 'link' => '',
* 'info' => ''
* );
*/
abstract public function searchLink($keyword);
/**
* @param $keyword
*
* @return array links
* $links[] = array(
* 'title' => '',
* 'description' => '',
* 'image' => '',
* 'link' => '',
* 'info' => ''
* );
*/
abstract public function searchContent($keyword);
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Content;
use Nextend\Framework\Content\Joomla\JoomlaContent;
use Nextend\Framework\Content\WordPress\WordPressContent;
class Content {
/**
* @var AbstractPlatformContent
*/
private static $platformContent;
public function __construct() {
self::$platformContent = new WordPressContent();
}
public static function searchLink($keyword) {
return self::$platformContent->searchLink($keyword);
}
public static function searchContent($keyword) {
return self::$platformContent->searchContent($keyword);
}
}
new Content();
\ No newline at end of file
<?php
namespace Nextend\Framework\Content;
use Nextend\Framework\Controller\Admin\AdminAjaxController;
use Nextend\Framework\Request\Request;
class ControllerAjaxContent extends AdminAjaxController {
public function actionSearchLink() {
$this->validateToken();
$keyword = Request::$REQUEST->getVar('keyword', '');
$this->response->respond(Content::searchLink($keyword));
}
public function actionSearchContent() {
$this->validateToken();
$keyword = Request::$REQUEST->getVar('keyword', '');
$this->response->respond(Content::searchContent($keyword));
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Content\WordPress;
use Nextend\Framework\Content\AbstractPlatformContent;
use WP_Query;
use function get_post_thumbnail_id;
use function get_post_type;
use function get_post_type_object;
use function get_the_excerpt;
use function get_the_ID;
use function get_the_permalink;
use function get_the_title;
use function wp_get_attachment_url;
class WordPressContent extends AbstractPlatformContent {
public function searchLink($keyword) {
$the_query = new WP_Query('post_type=any&posts_per_page=20&post_status=publish&s=' . $keyword);
$links = array();
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
$link = array(
'title' => get_the_title(),
'link' => get_the_permalink(),
'info' => get_post_type_object(get_post_type())->labels->singular_name
);
$links[] = $link;
}
}
/* Restore original Post Data */
wp_reset_postdata();
return $links;
}
public function searchContent($keyword) {
$the_query = new WP_Query('post_type=any&posts_per_page=20&post_status=publish&s=' . $keyword);
$links = array();
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
$link = array(
'title' => get_the_title(),
'description' => get_the_excerpt(),
'image' => wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())),
'link' => get_the_permalink(),
'info' => get_post_type_object(get_post_type())->labels->singular_name
);
$links[] = $link;
}
}
/* Restore original Post Data */
wp_reset_postdata();
return $links;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Controller;
use Exception;
use Nextend\Framework\Acl\Acl;
use Nextend\Framework\Application\AbstractApplication;
use Nextend\Framework\Application\AbstractApplicationType;
use Nextend\Framework\Asset\AssetManager;
use Nextend\Framework\Asset\Predefined;
use Nextend\Framework\Form\Form;
use Nextend\Framework\Notification\Notification;
use Nextend\Framework\Pattern\GetPathTrait;
use Nextend\Framework\Pattern\MVCHelperTrait;
use Nextend\Framework\Plugin;
use Nextend\Framework\Request\Request;
use Nextend\SmartSlider3\Application\ApplicationSmartSlider3;
abstract class AbstractController {
use GetPathTrait;
use MVCHelperTrait;
/**
* @var AbstractApplicationType
*/
protected $applicationType;
/** @var callback[] */
protected $externalActions = array();
/**
* AbstractController constructor.
*
* @param AbstractApplicationType $applicationType
*/
public function __construct($applicationType) {
//PluggableController\Nextend\SmartSlider3\Application\Admin\Slider\ControllerSlider
Plugin::doAction('PluggableController\\' . get_class($this), array($this));
$this->applicationType = $applicationType;
$this->setMVCHelper($this->applicationType);
AssetManager::getInstance();
$this->initialize();
}
/**
* @param $actionName
* @param callback $callable
*/
public function addExternalAction($actionName, $callable) {
$this->externalActions[$actionName] = $callable;
}
/**
* @return AbstractApplication
*/
public function getApplication() {
return $this->applicationType->getApplication();
}
/**
* @return AbstractApplicationType
*/
public function getApplicationType() {
return $this->applicationType;
}
public function getRouter() {
return $this->applicationType->getRouter();
}
/**
* @param $actionName
* @param array $args
*
* @throws Exception
*/
final public function doAction($actionName, $args = array()) {
$originalActionName = $actionName;
if (method_exists($this, 'action' . $actionName)) {
call_user_func_array(array(
$this,
'action' . $actionName
), $args);
} else if (isset($this->externalActions[$actionName]) && is_callable($this->externalActions[$actionName])) {
call_user_func_array($this->externalActions[$actionName], $args);
} else {
$actionName = $this->missingAction($this, $actionName);
if (method_exists($this, 'action' . $actionName)) {
call_user_func_array(array(
$this,
'action' . $actionName
), $args);
} else {
throw new Exception(sprintf('Missing action (%s) for controller (%s)', $originalActionName, static::class));
}
}
}
protected function missingAction($controllerName, $actionName) {
return 'index';
}
public function initialize() {
Predefined::frontend();
}
/**
* Check ACL permissions
*
* @param $action
*
* @return bool
*/
public function canDo($action) {
return Acl::canDo($action, $this);
}
public function redirect($url, $statusCode = 302, $terminate = true) {
Request::redirect($url, $statusCode, $terminate);
}
public function validatePermission($permission) {
if (!$this->canDo($permission)) {
Notification::error(n2_('You are not authorised to view this resource.'));
ApplicationSmartSlider3::getInstance()
->getApplicationTypeAdmin()
->process('sliders', 'index');
return false;
}
return true;
}
public function validateVariable($condition, $property) {
if (!$condition) {
Notification::error(sprintf(n2_('Missing parameter: %s'), $property));
ApplicationSmartSlider3::getInstance()
->getApplicationTypeAdmin()
->process('sliders', 'index');
return false;
}
return true;
}
public function validateDatabase($condition, $showError = true) {
if (!$condition) {
if ($showError) {
Notification::error(n2_('Database error'));
ApplicationSmartSlider3::getInstance()
->getApplicationTypeAdmin()
->process('sliders', 'index');
}
return false;
}
return true;
}
public function validateToken() {
if (!Form::checkToken()) {
Notification::error(n2_('Security token mismatch'));
return false;
}
return true;
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Controller\Admin;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Asset\Predefined;
use Nextend\Framework\Controller\AbstractController;
abstract class AbstractAdminController extends AbstractController {
public function initialize() {
// Prevent browser from cache on backward button.
header("Cache-Control: no-store");
Js::addGlobalInline('window.N2DISABLESCHEDULER=1;');
parent::initialize();
Predefined::frontend();
Predefined::backend();
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Controller\Admin;
use Nextend\Framework\Controller\AjaxController;
class AdminAjaxController extends AjaxController {
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Controller\Admin;
use Nextend\Framework\Notification\Notification;
use Nextend\Framework\Request\Request;
use Nextend\Framework\Visual\ModelVisual;
abstract class AdminVisualManagerAjaxController extends AdminAjaxController {
protected $type = '';
/**
* @return ModelVisual
*/
public abstract function getModel();
public function actionCreateSet() {
$this->validateToken();
$this->validatePermission('smartslider_edit');
$name = Request::$REQUEST->getVar('name');
$this->validateVariable(!empty($name), 'set name');
$model = $this->getModel();
if (($set = $model->createSet($name))) {
$this->response->respond(array(
'set' => $set
));
}
Notification::error(n2_('Unexpected error'));
$this->response->error();
}
public function actionRenameSet() {
$this->validateToken();
$this->validatePermission('smartslider_edit');
$setId = Request::$REQUEST->getInt('setId');
$this->validateVariable($setId > 0, 'set');
$name = Request::$REQUEST->getVar('name');
$this->validateVariable(!empty($name), 'set name');
$model = $this->getModel();
if (($set = $model->renameSet($setId, $name))) {
$this->response->respond(array(
'set' => $set
));
}
Notification::error(n2_('Set is not editable'));
$this->response->error();
}
public function actionDeleteSet() {
$this->validateToken();
$this->validatePermission('smartslider_delete');
$setId = Request::$REQUEST->getInt('setId');
$this->validateVariable($setId > 0, 'set');
$model = $this->getModel();
if (($set = $model->deleteSet($setId))) {
$this->response->respond(array(
'set' => $set
));
}
Notification::error(n2_('Set is not editable'));
$this->response->error();
}
public function actionLoadVisualsForSet() {
$this->validateToken();
$setId = Request::$REQUEST->getInt('setId');
$this->validateVariable($setId > 0, 'set');
$model = $this->getModel();
$visuals = $model->getVisuals($setId);
if (is_array($visuals)) {
$this->response->respond(array(
'visuals' => $visuals
));
}
Notification::error(n2_('Unexpected error'));
$this->response->error();
}
public function actionLoadSetByVisualId() {
$this->validateToken();
$visualId = Request::$REQUEST->getInt('visualId');
$this->validateVariable($visualId > 0, 'visual');
$model = $this->getModel();
$set = $model->getSetByVisualId($visualId);
if (is_array($set) && is_array($set['visuals'])) {
$this->response->respond(array(
'set' => $set
));
}
Notification::error(n2_('Visual do not exists'));
$this->response->error();
}
public function actionAddVisual() {
$this->validateToken();
$this->validatePermission('smartslider_edit');
$setId = Request::$REQUEST->getInt('setId');
$this->validateVariable($setId > 0, 'set');
$model = $this->getModel();
if (($visual = $model->addVisual($setId, Request::$REQUEST->getVar('value')))) {
$this->response->respond(array(
'visual' => $visual
));
}
Notification::error(n2_('Not editable'));
$this->response->error();
}
public function actionDeleteVisual() {
$this->validateToken();
$this->validatePermission('smartslider_delete');
$visualId = Request::$REQUEST->getInt('visualId');
$this->validateVariable($visualId > 0, 'visual');
$model = $this->getModel();
if (($visual = $model->deleteVisual($visualId))) {
$this->response->respond(array(
'visual' => $visual
));
}
Notification::error(n2_('Not editable'));
$this->response->error();
}
public function actionChangeVisual() {
$this->validateToken();
$this->validatePermission('smartslider_edit');
$visualId = Request::$REQUEST->getInt('visualId');
$this->validateVariable($visualId > 0, 'visual');
$model = $this->getModel();
if (($visual = $model->changeVisual($visualId, Request::$REQUEST->getVar('value')))) {
$this->response->respond(array(
'visual' => $visual
));
}
Notification::error(n2_('Unexpected error'));
$this->response->error();
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Controller;
use Nextend\Framework\Form\Form;
use Nextend\Framework\Notification\Notification;
use Nextend\Framework\PageFlow;
use Nextend\Framework\Response\ResponseAjax;
class AjaxController extends AbstractController {
/** @var ResponseAjax */
protected $response;
public function __construct($applicationType) {
PageFlow::cleanOutputBuffers();
$this->response = new ResponseAjax($applicationType);
parent::__construct($applicationType);
}
/**
* @return ResponseAjax
*/
public function getResponse() {
return $this->response;
}
public function validateToken() {
if (!Form::checkToken()) {
Notification::error(n2_('Security token mismatch. Please refresh the page!'));
$this->response->error();
}
}
public function validatePermission($permission) {
if (!$this->canDo($permission)) {
Notification::error(n2_('You are not authorised to view this resource.'));
$this->response->error();
}
}
public function validateVariable($condition, $property) {
if (!$condition) {
Notification::error(sprintf(n2_('Missing parameter: %s'), $property));
$this->response->error();
}
}
public function validateDatabase($condition, $showError = true) {
if (!$condition) {
Notification::error(n2_('Database error'));
$this->response->error();
}
}
public function redirect($url, $statusCode = 302, $terminate = true) {
$this->response->redirect($url);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Data;
class Data {
/**
* @var array
*/
public $_data = array();
public function __construct($data = null, $json = false) {
if ($data) {
if (is_array($data)) {
$this->loadArray($data);
} else {
$this->loadJSON($data);
}
}
}
/**
* @param $json
*/
public function loadJSON($json) {
$array = json_decode($json, true);
if (is_array($array)) $this->_data = array_merge($this->_data, $array);
}
/**
* @param $array
*/
public function loadArray($array) {
if (!$this->_data) $this->_data = array();
if (is_array($array)) $this->_data = array_merge($this->_data, $array);
}
/**
* @return mixed|string
*/
public function toJSON() {
return json_encode($this->_data);
}
/**
* @return array
*/
public function toArray() {
return (array)$this->_data;
}
public function has($key) {
return isset($this->_data[$key]);
}
/**
* @param string $key
* @param string $default
*
* @return mixed
*/
public function get($key, $default = '') {
if (isset($this->_data[$key])) return $this->_data[$key];
return $default;
}
public function getIfEmpty($key, $default = '') {
if (isset($this->_data[$key]) && !empty($this->_data[$key])) return $this->_data[$key];
return $default;
}
/**
* @param string $key
* @param mixed $value
*/
public function set($key, $value) {
$this->_data[$key] = $value;
}
public function un_set($key) {
if (isset($this->_data[$key])) {
unset($this->_data[$key]);
}
}
public function fillDefault($defaults) {
$this->_data = array_merge($defaults, $this->_data);
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Database;
abstract class AbstractPlatformConnector {
protected $_prefixJoker = '#__';
protected $_prefix = '';
public function getPrefix() {
return $this->_prefix;
}
public function parsePrefix($query) {
return str_replace($this->_prefixJoker, $this->_prefix, $query);
}
abstract public function insertId();
abstract public function query($query, $attributes = false);
/**
* Return with one row by query string
*
* @param string $query
* @param array|bool $attributes for parameter binding
*
* @return mixed
*/
abstract public function queryRow($query, $attributes = false);
abstract public function queryAll($query, $attributes = false, $type = "assoc", $key = null);
/**
* @param string $text
* @param bool $escape
*
* @return string
*/
abstract public function quote($text, $escape = true);
/**
* @param string $name
* @param null $as
*
* @return mixed
*/
abstract public function quoteName($name, $as = null);
public function checkError($result) {
return $result;
}
/**
* @return string
*/
abstract public function getCharsetCollate();
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Database;
abstract class AbstractPlatformConnectorTable {
protected $primaryKeyColumn = "id";
/** @var AbstractPlatformConnector */
protected static $connector;
protected $tableName;
public function __construct($tableName) {
$this->tableName = self::$connector->getPrefix() . $tableName;
}
public function getTableName() {
return $this->tableName;
}
abstract public function findByPk($primaryKey);
abstract public function findByAttributes(array $attributes, $fields = false, $order = false);
abstract public function findAll($order = false);
/**
* Return with all row by attributes
*
* @param array $attributes
* @param bool|array $fields
* @param bool|string $order
*
* @return mixed
*/
abstract public function findAllByAttributes(array $attributes, $fields = false, $order = false);
/**
* Insert new row
*
* @param array $attributes
*
* @return mixed|void
*/
abstract public function insert(array $attributes);
abstract public function insertId();
/**
* Update row(s) by param(s)
*
* @param array $attributes
* @param array $conditions
*
* @return mixed
*/
abstract public function update(array $attributes, array $conditions);
/**
* Update one row by primary key with $attributes
*
* @param mixed $primaryKey
* @param array $attributes
*
* @return mixed
*/
abstract public function updateByPk($primaryKey, array $attributes);
/**
* Delete one with by primary key
*
* @param mixed $primaryKey
*
* @return mixed
*/
abstract public function deleteByPk($primaryKey);
/**
* Delete all rows by attributes
*
* @param array $conditions
*
* @return mixed
*/
abstract public function deleteByAttributes(array $conditions);
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Database;
use Nextend\Framework\Database\Joomla\JoomlaConnector;
use Nextend\Framework\Database\Joomla\JoomlaConnectorTable;
use Nextend\Framework\Database\WordPress\WordPressConnector;
use Nextend\Framework\Database\WordPress\WordPressConnectorTable;
use Nextend\Framework\Pattern\SingletonTrait;
class Database {
use SingletonTrait;
/**
* @var AbstractPlatformConnector
*/
private static $platformConnector;
protected function init() {
self::$platformConnector = new WordPressConnector();
}
/**
* @param $tableName
*
* @return AbstractPlatformConnectorTable
*/
public static function getTable($tableName) {
return new WordPressConnectorTable($tableName);
}
public static function getPrefix() {
return self::$platformConnector->getPrefix();
}
public static function parsePrefix($query) {
return self::$platformConnector->parsePrefix($query);
}
public static function insertId() {
return self::$platformConnector->insertId();
}
public static function query($query, $attributes = false) {
return self::$platformConnector->query($query, $attributes);
}
/**
* Return with one row by query string
*
* @param string $query
* @param array|bool $attributes for parameter binding
*
* @return mixed
*/
public static function queryRow($query, $attributes = false) {
return self::$platformConnector->queryRow($query, $attributes);
}
public static function queryAll($query, $attributes = false, $type = "assoc", $key = null) {
return self::$platformConnector->queryAll($query, $attributes, $type, $key);
}
/**
* @param string $text
* @param bool $escape
*
* @return string
*/
public static function quote($text, $escape = true) {
return self::$platformConnector->quote($text, $escape);
}
/**
* @param string $name
* @param null $as
*
* @return mixed
*/
public static function quoteName($name, $as = null) {
return self::$platformConnector->quoteName($name, $as);
}
/**
* @return string
*/
public static function getCharsetCollate() {
return self::$platformConnector->getCharsetCollate();
}
}
Database::getInstance();
\ No newline at end of file
<?php
namespace Nextend\Framework\Database\WordPress;
use Nextend\Framework\Database\AbstractPlatformConnector;
use Nextend\Framework\Notification\Notification;
use Nextend\SmartSlider3\Platform\SmartSlider3Platform;
use wpdb;
class WordPressConnector extends AbstractPlatformConnector {
/** @var wpdb $wpdb */
private $db;
public function __construct() {
/** @var wpdb $wpdb */ global $wpdb;
$this->db = $wpdb;
$this->_prefix = $wpdb->prefix;
WordPressConnectorTable::init($this, $this->db);
}
public function query($query, $attributes = false) {
if ($attributes) {
foreach ($attributes as $key => $value) {
$replaceTo = is_numeric($value) ? $value : $this->db->prepare('%s', $value);
$query = str_replace($key, $replaceTo, $query);
}
}
return $this->checkError($this->db->query($query));
}
public function insertId() {
return $this->db->insert_id;
}
private function _querySQL($query, $attributes = false) {
$args = array('');
if ($attributes) {
foreach ($attributes as $key => $value) {
$replaceTo = is_numeric($value) ? '%d' : '%s';
$query = str_replace($key, $replaceTo, $query);
$args[] = $value;
}
}
if (count($args) > 1) {
$args[0] = $query;
return call_user_func_array(array(
$this->db,
'prepare'
), $args);
} else {
return $query;
}
}
public function queryRow($query, $attributes = false) {
return $this->checkError($this->db->get_row($this->_querySQL($query, $attributes), ARRAY_A));
}
public function queryAll($query, $attributes = false, $type = "assoc", $key = null) {
$result = $this->checkError($this->db->get_results($this->_querySQL($query, $attributes), $type == 'assoc' ? ARRAY_A : OBJECT_K));
if (!$key) {
return $result;
}
$realResult = array();
for ($i = 0; $i < count($result); $i++) {
$key = $type == 'assoc' ? $result[i][$key] : $result[i]->{$key};
$realResult[$key] = $result[i];
}
return $realResult;
}
public function quote($text, $escape = true) {
return '\'' . (esc_sql($text)) . '\'';
}
public function quoteName($name, $as = null) {
if (strpos($name, '.') !== false) {
return $name;
} else {
$q = '`';
if (strlen($q) == 1) {
return $q . $name . $q;
} else {
return $q[0] . $name . $q[1];
}
}
}
public function checkError($result) {
if (!empty($this->db->last_error)) {
if (is_admin()) {
$lastError = $this->db->last_error;
$lastQuery = $this->db->last_query;
$possibleErrors = array(
'Duplicate entry' => 'Your table column doesn\'t have auto increment, while it should have.',
'command denied' => 'Your database user has limited access and isn\'t able to run all commands which are necessary for our code to work.',
'Duplicate key name' => 'Your database user has limited access and isn\'t able to run DROP or ALTER database commands.',
'Can\'t DROP' => 'Your database user has limited access and isn\'t able to run DROP or ALTER database commands.'
);
$errorMessage = sprintf(n2_('If you see this message after the repair database process, please %1$scontact us%2$s with the log:'), '<a href="https://smartslider3.com/contact-us/support/" target="_blank">', '</a>');
foreach ($possibleErrors as $error => $cause) {
if (strpos($lastError, $error) !== false) {
$errorMessage = n2_($cause) . ' ' . n2_('Contact your server host and ask them to fix this for you!');
break;
}
}
$message = array(
n2_('Unexpected database error.'),
'',
'<a href="' . wp_nonce_url(add_query_arg(array('repairss3' => '1'), SmartSlider3Platform::getAdminUrl()), 'repairss3') . '" class="n2_button n2_button--big n2_button--blue">' . n2_('Try to repair database') . '</a>',
'',
$errorMessage,
'',
'<b>' . $lastError . '</b>',
$lastQuery
);
Notification::error(implode('<br>', $message), array(
'wide' => true
));
}
}
return $result;
}
public function getCharsetCollate() {
return $this->db->get_charset_collate();
}
}
\ No newline at end of file
<?php
namespace Nextend\Framework\Database\WordPress;
use Nextend\Framework\Database\AbstractPlatformConnector;
use Nextend\Framework\Database\AbstractPlatformConnectorTable;
use wpdb;
class WordPressConnectorTable extends AbstractPlatformConnectorTable {
/** @var wpdb */
protected static $db;
/**
* @param AbstractPlatformConnector $connector
* @param wpdb $db
*/
public static function init($connector, $db) {
self::$connector = $connector;
self::$db = $db;
}
public function findByPk($primaryKey) {
$query = self::$db->prepare("SELECT * FROM " . $this->tableName . " WHERE " . self::$connector->quoteName($this->primaryKeyColumn) . " = %s", $primaryKey);
return self::$connector->checkError(self::$db->get_row($query, ARRAY_A));
}
public function findByAttributes(array $attributes, $fields = false, $order = false) {
return self::$connector->checkError(self::$db->get_row($this->_findByAttributesSQL($attributes, $fields, $order), ARRAY_A));
}
public function findAll($order = false) {
return self::$connector->checkError(self::$db->get_results($this->_findByAttributesSQL(array(), false, $order), ARRAY_A));
}
public function findAllByAttributes(array $attributes, $fields = false, $order = false) {
return self::$connector->checkError(self::$db->get_results($this->_findByAttributesSQL($attributes, $fields, $order), ARRAY_A));
}
public function insert(array $attributes) {
return self::$connector->checkError(self::$db->insert($this->tableName, $attributes));
}
public function insertId() {
return self::$db->insert_id;
}
public function update(array $attributes, array $conditions) {
return self::$connector->checkError(self::$db->update($this->tableName, $attributes, $conditions));
}
public function updateByPk($primaryKey, array $attributes) {
$where = array();
$where[$this->primaryKeyColumn] = $primaryKey;
self::$connector->checkError(self::$db->update($this->tableName, $attributes, $where));
}
public function deleteByPk($primaryKey) {
$where = array();
$where[$this->primaryKeyColumn] = $primaryKey;
self::$connector->checkError(self::$db->delete($this->tableName, $where));
}
public function deleteByAttributes(array $conditions) {
self::$connector->checkError(self::$db->delete($this->tableName, $conditions));
}
private function _findByAttributesSQL(array $attributes, $fields = array(), $order = false) {
$args = array('');
$query = 'SELECT ';
if (!empty($fields)) {
$fields = array_map(array(
self::$connector,
'quoteName'
), $fields);
$query .= implode(', ', $fields);
} else {
$query .= '*';
}
$query .= ' FROM ' . $this->tableName;
$where = array();
foreach ($attributes as $key => $val) {
$where[] = self::$connector->quoteName($key) . ' = ' . (is_numeric($val) ? '%d' : '%s');
$args[] = $val;
}
if (count($where)) {
$query .= ' WHERE ' . implode(' AND ', $where);
}
if ($order) {
$query .= ' ORDER BY ' . $order;
}
if (count($args) > 1) {
$args[0] = $query;
return call_user_func_array(array(
self::$db,
'prepare'
), $args);
} else {
return $query;
}
}
}
\ No newline at end of file
<?php
/**
* fast-image-size base class
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize;
use Nextend\Framework\Pattern\SingletonTrait;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
class FastImageSize {
use SingletonTrait;
private static $cache = array();
/**
* @param string $image
* @param array $attributes
*/
public static function initAttributes($image, &$attributes) {
$size = self::getSize($image);
if ($size) {
$attributes['width'] = $size['width'];
$attributes['height'] = $size['height'];
}
}
public static function getWidth($image) {
$size = self::getSize($image);
if ($size) {
return $size['width'];
}
return 0;
}
public static function getSize($image) {
$imagePath = ResourceTranslator::toPath($image);
if (!isset(self::$cache[$imagePath])) {
if (empty($imagePath)) {
self::$cache[$imagePath] = false;
} else {
self::$cache[$imagePath] = self::getInstance()
->getImageSize($imagePath);
}
}
return self::$cache[$imagePath];
}
/** @var array Size info that is returned */
protected $size = array();
/** @var string Data retrieved from remote */
protected $data = '';
/** @var array List of supported image types and associated image types */
protected $supportedTypes = array(
'png' => array('png'),
'gif' => array('gif'),
'jpeg' => array(
'jpeg',
'jpg'
),
'webp' => array(
'webp',
),
'svg' => array(
'svg',
)
);
/** @var array Class map that links image extensions/mime types to class */
protected $classMap;
/** @var array An array containing the classes of supported image types */
protected $type;
/**
* Get image dimensions of supplied image
*
* @param string $file Path to image that should be checked
* @param string $type Mimetype of image
*
* @return array|bool Array with image dimensions if successful, false if not
*/
public function getImageSize($file, $type = '') {
// Reset values
$this->resetValues();
// Treat image type as unknown if extension or mime type is unknown
if (!preg_match('/\.([a-z0-9]+)$/i', $file, $match) && empty($type)) {
$this->getImagesizeUnknownType($file);
} else {
$extension = (empty($type) && isset($match[1])) ? $match[1] : preg_replace('/.+\/([a-z0-9-.]+)$/i', '$1', $type);
$this->getImageSizeByExtension($file, $extension);
}
return sizeof($this->size) > 1 ? $this->size : false;
}
/**
* Get dimensions of image if type is unknown
*
* @param string $filename Path to file
*/
protected function getImagesizeUnknownType($filename) {
// Grab the maximum amount of bytes we might need
$data = $this->getImage($filename, 0, Type\TypeJpeg::JPEG_MAX_HEADER_SIZE, false);
if ($data !== false) {
$this->loadAllTypes();
foreach ($this->type as $imageType) {
$imageType->getSize($filename);
if (sizeof($this->size) > 1) {
break;
}
}
}
}
/**
* Get image size by file extension
*
* @param string $file Path to image that should be checked
* @param string $extension Extension/type of image
*/
protected function getImageSizeByExtension($file, $extension) {
$extension = strtolower($extension);
$this->loadExtension($extension);
if (isset($this->classMap[$extension])) {
$this->classMap[$extension]->getSize($file);
}
}
/**
* Reset values to default
*/
protected function resetValues() {
$this->size = array();
$this->data = '';
}
/**
* Set mime type based on supplied image
*
* @param int $type Type of image
*/
public function setImageType($type) {
$this->size['type'] = $type;
}
/**
* Set size info
*
* @param array $size Array containing size info for image
*/
public function setSize($size) {
$this->size = $size;
}
/**
* Get image from specified path/source
*
* @param string $filename Path to image
* @param int $offset Offset at which reading of the image should start
* @param int $length Maximum length that should be read
* @param bool $forceLength True if the length needs to be the specified
* length, false if not. Default: true
*
* @return false|string Image data or false if result was empty
*/
public function getImage($filename, $offset, $length, $forceLength = true) {
if (empty($this->data)) {
$this->data = @file_get_contents($filename, null, null, $offset, $length);
}
// Force length to expected one. Return false if data length
// is smaller than expected length
if ($forceLength === true) {
return (strlen($this->data) < $length) ? false : substr($this->data, $offset, $length);
}
return empty($this->data) ? false : $this->data;
}
/**
* Get return data
*
* @return array|bool Size array if dimensions could be found, false if not
*/
protected function getReturnData() {
return sizeof($this->size) > 1 ? $this->size : false;
}
/**
* Load all supported types
*/
protected function loadAllTypes() {
foreach ($this->supportedTypes as $imageType => $extension) {
$this->loadType($imageType);
}
}
/**
* Load an image type by extension
*
* @param string $extension Extension of image
*/
protected function loadExtension($extension) {
if (isset($this->classMap[$extension])) {
return;
}
foreach ($this->supportedTypes as $imageType => $extensions) {
if (in_array($extension, $extensions, true)) {
$this->loadType($imageType);
}
}
}
/**
* Load an image type
*
* @param string $imageType Mimetype
*/
protected function loadType($imageType) {
if (isset($this->type[$imageType])) {
return;
}
$className = '\\' . __NAMESPACE__ . '\Type\Type' . ucfirst($imageType);
$this->type[$imageType] = new $className($this);
// Create class map
foreach ($this->supportedTypes[$imageType] as $ext) {
/** @var Type\TypeInterface */
$this->classMap[$ext] = $this->type[$imageType];
}
}
}
<?php
/**
* fast-image-size image type base
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize\Type;
use Nextend\Framework\FastImageSize\FastImageSize;
abstract class TypeBase implements TypeInterface {
/** @var FastImageSize */
protected $fastImageSize;
/**
* Base constructor for image types
*
* @param FastImageSize $fastImageSize
*/
public function __construct(FastImageSize $fastImageSize) {
$this->fastImageSize = $fastImageSize;
}
}
<?php
/**
* fast-image-size image type gif
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize\Type;
class TypeGif extends TypeBase {
/** @var string GIF87a header */
const GIF87A_HEADER = "\x47\x49\x46\x38\x37\x61";
/** @var string GIF89a header */
const GIF89A_HEADER = "\x47\x49\x46\x38\x39\x61";
/** @var int GIF header size */
const GIF_HEADER_SIZE = 6;
/**
* {@inheritdoc}
*/
public function getSize($filename) {
// Get data needed for reading image dimensions as outlined by GIF87a
// and GIF89a specifications
$data = $this->fastImageSize->getImage($filename, 0, self::GIF_HEADER_SIZE + self::SHORT_SIZE * 2);
$type = substr($data, 0, self::GIF_HEADER_SIZE);
if ($type !== self::GIF87A_HEADER && $type !== self::GIF89A_HEADER) {
return;
}
$size = unpack('vwidth/vheight', substr($data, self::GIF_HEADER_SIZE, self::SHORT_SIZE * 2));
$this->fastImageSize->setSize($size);
$this->fastImageSize->setImageType(IMAGETYPE_GIF);
}
}
<?php
/**
* fast-image-size image type interface
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize\Type;
interface TypeInterface {
/** @var int 4-byte long size */
const LONG_SIZE = 4;
/** @var int 2-byte short size */
const SHORT_SIZE = 2;
/**
* Get size of supplied image
*
* @param string $filename File name of image
*
* @return null
*/
public function getSize($filename);
}
<?php
/**
* fast-image-size image type jpeg
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize\Type;
class TypeJpeg extends TypeBase {
/** @var int JPEG max header size. Headers can be bigger, but we'll abort
* going through the header after this */
const JPEG_MAX_HEADER_SIZE = 786432; // = 768 kiB
/** @var string JPEG header */
const JPEG_HEADER = "\xFF\xD8";
/** @var string Start of frame marker */
const SOF_START_MARKER = "\xFF";
/** @var string End of image (EOI) marker */
const JPEG_EOI_MARKER = "\xD9";
/** @var array JPEG SOF markers */
protected $sofMarkers = array(
"\xC0",
"\xC1",
"\xC2",
"\xC3",
"\xC5",
"\xC6",
"\xC7",
"\xC9",
"\xCA",
"\xCB",
"\xCD",
"\xCE",
"\xCF"
);
/** @var string|bool JPEG data stream */
protected $data = '';
/** @var int Data length */
protected $dataLength = 0;
/**
* {@inheritdoc}
*/
public function getSize($filename) {
// Do not force the data length
$this->data = $this->fastImageSize->getImage($filename, 0, self::JPEG_MAX_HEADER_SIZE, false);
// Check if file is jpeg
if ($this->data === false || substr($this->data, 0, self::SHORT_SIZE) !== self::JPEG_HEADER) {
return;
}
// Look through file for SOF marker
$size = $this->getSizeInfo();
$this->fastImageSize->setSize($size);
$this->fastImageSize->setImageType(IMAGETYPE_JPEG);
}
/**
* Get size info from image data
*
* @return array An array with the image's size info or an empty array if
* size info couldn't be found
*/
protected function getSizeInfo() {
$size = array();
// since we check $i + 1 we need to stop one step earlier
$this->dataLength = strlen($this->data) - 1;
$sofStartRead = true;
// Look through file for SOF marker
for ($i = 2; $i < $this->dataLength; $i++) {
$marker = $this->getNextMarker($i, $sofStartRead);
if (in_array($marker, $this->sofMarkers)) {
// Extract size info from SOF marker
return $this->extractSizeInfo($i);
} else {
// Extract length only
$markerLength = $this->extractMarkerLength($i);
if ($markerLength < 2) {
return $size;
}
$i += $markerLength - 1;
continue;
}
}
return $size;
}
/**
* Extract marker length from data
*
* @param int $i Current index
*
* @return int Length of current marker
*/
protected function extractMarkerLength($i) {
// Extract length only
list(, $unpacked) = unpack("H*", substr($this->data, $i, self::LONG_SIZE));
// Get width and height from unpacked size info
$markerLength = hexdec(substr($unpacked, 0, 4));
return $markerLength;
}
/**
* Extract size info from data
*
* @param int $i Current index
*
* @return array Size info of current marker
*/
protected function extractSizeInfo($i) {
// Extract size info from SOF marker
list(, $unpacked) = unpack("H*", substr($this->data, $i - 1 + self::LONG_SIZE, self::LONG_SIZE));
// Get width and height from unpacked size info
$size = array(
'width' => hexdec(substr($unpacked, 4, 4)),
'height' => hexdec(substr($unpacked, 0, 4)),
);
return $size;
}
/**
* Get next JPEG marker in file
*
* @param int $i Current index
* @param bool $sofStartRead Flag whether SOF start padding was already read
*
* @return string Next JPEG marker in file
*/
protected function getNextMarker(&$i, &$sofStartRead) {
$this->skipStartPadding($i, $sofStartRead);
do {
if ($i >= $this->dataLength) {
return self::JPEG_EOI_MARKER;
}
$marker = $this->data[$i];
$i++;
} while ($marker == self::SOF_START_MARKER);
return $marker;
}
/**
* Skip over any possible padding until we reach a byte without SOF start
* marker. Extraneous bytes might need to require proper treating.
*
* @param int $i Current index
* @param bool $sofStartRead Flag whether SOF start padding was already read
*/
protected function skipStartPadding(&$i, &$sofStartRead) {
if (!$sofStartRead) {
while ($this->data[$i] !== self::SOF_START_MARKER) {
$i++;
}
}
}
}
<?php
/**
* fast-image-size image type png
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize\Type;
class TypePng extends TypeBase {
/** @var string PNG header */
const PNG_HEADER = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a";
/** @var int PNG IHDR offset */
const PNG_IHDR_OFFSET = 12;
/**
* {@inheritdoc}
*/
public function getSize($filename) {
// Retrieve image data including the header, the IHDR tag, and the
// following 2 chunks for the image width and height
$data = $this->fastImageSize->getImage($filename, 0, self::PNG_IHDR_OFFSET + 3 * self::LONG_SIZE);
// Check if header fits expected format specified by RFC 2083
if (substr($data, 0, self::PNG_IHDR_OFFSET - self::LONG_SIZE) !== self::PNG_HEADER || substr($data, self::PNG_IHDR_OFFSET, self::LONG_SIZE) !== 'IHDR') {
return;
}
$size = unpack('Nwidth/Nheight', substr($data, self::PNG_IHDR_OFFSET + self::LONG_SIZE, self::LONG_SIZE * 2));
$this->fastImageSize->setSize($size);
$this->fastImageSize->setImageType(IMAGETYPE_PNG);
}
}
<?php
namespace Nextend\Framework\FastImageSize\Type;
class TypeSvg extends TypeBase {
/**
* {@inheritdoc}
*/
public function getSize($filename) {
$data = $this->fastImageSize->getImage($filename, 0, 100);
preg_match('/width="([0-9]+)"/', $data, $matches);
if ($matches && $matches[1] > 0) {
$size = array();
$size['width'] = $matches[1];
preg_match('/height="([0-9]+)"/', $data, $matches);
if ($matches && $matches[1] > 0) {
$size['height'] = $matches[1];
$this->fastImageSize->setSize($size);
return;
}
}
preg_match('/viewBox=["\']([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)["\']/i', $data, $matches);
if ($matches) {
$this->fastImageSize->setSize(array(
'width' => $matches[3] - $matches[1],
'height' => $matches[4] - $matches[2],
));
}
}
}
<?php
/**
* fast-image-size image type webp
*
* @package fast-image-size
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nextend\Framework\FastImageSize\Type;
use Nextend\Framework\FastImageSize\FastImageSize;
class TypeWebp extends TypeBase {
/** @var string RIFF header */
const WEBP_RIFF_HEADER = "RIFF";
/** @var string Webp header */
const WEBP_HEADER = "WEBP";
/** @var string VP8 chunk header */
const VP8_HEADER = "VP8";
/** @var string Simple(lossy) webp format */
const WEBP_FORMAT_SIMPLE = ' ';
/** @var string Lossless webp format */
const WEBP_FORMAT_LOSSLESS = 'L';
/** @var string Extended webp format */
const WEBP_FORMAT_EXTENDED = 'X';
/** @var int WEBP header size needed for retrieving image size */
const WEBP_HEADER_SIZE = 30;
/** @var array Size info array */
protected $size;
/**
* Constructor for webp image type. Adds missing constant if necessary.
*
* @param FastImageSize $fastImageSize
*/
public function __construct(FastImageSize $fastImageSize) {
parent::__construct($fastImageSize);
if (!defined('IMAGETYPE_WEBP')) {
define('IMAGETYPE_WEBP', 18);
}
}
/**
* {@inheritdoc}
*/
public function getSize($filename) {
// Do not force length of header
$data = $this->fastImageSize->getImage($filename, 0, self::WEBP_HEADER_SIZE);
$this->size = array();
$webpFormat = substr($data, 15, 1);
if (!$this->hasWebpHeader($data) || !$this->isValidFormat($webpFormat)) {
return;
}
$data = substr($data, 16, 14);
$this->getWebpSize($data, $webpFormat);
$this->fastImageSize->setSize($this->size);
$this->fastImageSize->setImageType(IMAGETYPE_WEBP);
}
/**
* Check if $data has valid WebP header
*
* @param string $data Image data
*
* @return bool True if $data has valid WebP header, false if not
*/
protected function hasWebpHeader($data) {
$riffSignature = substr($data, 0, self::LONG_SIZE);
$webpSignature = substr($data, 8, self::LONG_SIZE);
$vp8Signature = substr($data, 12, self::SHORT_SIZE + 1);
return !empty($data) && $riffSignature === self::WEBP_RIFF_HEADER && $webpSignature === self::WEBP_HEADER && $vp8Signature === self::VP8_HEADER;
}
/**
* Check if $format is a valid WebP format
*
* @param string $format Format string
*
* @return bool True if format is valid WebP format, false if not
*/
protected function isValidFormat($format) {
return in_array($format, array(
self::WEBP_FORMAT_SIMPLE,
self::WEBP_FORMAT_LOSSLESS,
self::WEBP_FORMAT_EXTENDED
));
}
/**
* Get webp size info depending on format type and set size array values
*
* @param string $data Data string
* @param string $format Format string
*/
protected function getWebpSize($data, $format) {
switch ($format) {
case self::WEBP_FORMAT_SIMPLE:
$this->size = unpack('vwidth/vheight', substr($data, 10, 4));
break;
case self::WEBP_FORMAT_LOSSLESS:
// Lossless uses 14-bit values so we'll have to use bitwise shifting
$this->size = array(
'width' => ord($data[5]) + ((ord($data[6]) & 0x3F) << 8) + 1,
'height' => (ord($data[6]) >> 6) + (ord($data[7]) << 2) + ((ord($data[8]) & 0xF) << 10) + 1,
);
break;
case self::WEBP_FORMAT_EXTENDED:
// Extended uses 24-bit values cause 14-bit for lossless wasn't weird enough
$this->size = array(
'width' => ord($data[8]) + (ord($data[9]) << 8) + (ord($data[10]) << 16) + 1,
'height' => ord($data[11]) + (ord($data[12]) << 8) + (ord($data[13]) << 16) + 1,
);
break;
}
}
}
<?php
namespace Nextend\Framework\Filesystem;
use Nextend\Framework\Url\Url;
if (!defined('NEXTEND_RELATIVE_CACHE_WEB')) {
define('NEXTEND_RELATIVE_CACHE_WEB', '/cache/nextend/web');
define('NEXTEND_CUSTOM_CACHE', 0);
} else {
define('NEXTEND_CUSTOM_CACHE', 1);
}
if (!defined('NEXTEND_RELATIVE_CACHE_NOTWEB')) {
define('NEXTEND_RELATIVE_CACHE_NOTWEB', '/cache/nextend/notweb');
}
abstract class AbstractPlatformFilesystem {
public $paths = array();
/**
* @var string Absolute path which match to the baseuri. It must not end with /
* @example /asd/xyz/wordpress
*/
protected $_basepath;
protected $dirPermission = 0777;
protected $filePermission = 0666;
protected $translate = array();
public function init() {
}
public function getPaths() {
return $this->paths;
}
public function check($base, $folder) {
static $checked = array();
if (!isset($checked[$base . '/' . $folder])) {
$cacheFolder = $base . '/' . $folder;
if (!$this->existsFolder($cacheFolder)) {
if ($this->is_writable($base)) {
$this->createFolder($cacheFolder);
} else {
die('<div style="position:fixed;background:#fff;width:100%;height:100%;top:0;left:0;z-index:100000;">' . sprintf('<h2><b>%s</b> is not writable.</h2>', $base) . '</div>');
}
} else if (!$this->is_writable($cacheFolder)) {
die('<div style="position:fixed;background:#fff;width:100%;height:100%;top:0;left:0;z-index:100000;">' . sprintf('<h2><b>%s</b> is not writable.</h2>', $cacheFolder) . '</div>');
}
$checked[$base . '/' . $folder] = true;
}
}
public function measurePermission($testDir) {
while ('.' != $testDir && !is_dir($testDir)) {
$testDir = dirname($testDir);
}
if ($stat = @stat($testDir)) {
$this->dirPermission = $stat['mode'] & 0007777;
$this->filePermission = $this->dirPermission & 0000666;
}
}
/**
* @param $path
*
* @return mixed
*/
public function toLinux($path) {
return str_replace(DIRECTORY_SEPARATOR, '/', $path);
}
/**
* @return string
*/
public function getBasePath() {
return $this->_basepath;
}
/**
* @param $path
*/
public function setBasePath($path) {
$this->_basepath = $path;
}
public function getWebCachePath() {
return $this->getBasePath() . NEXTEND_RELATIVE_CACHE_WEB;
}
public function getNotWebCachePath() {
return $this->getBasePath() . NEXTEND_RELATIVE_CACHE_NOTWEB;
}
/**
* @param $path
*
* @return string
*/
public function pathToAbsoluteURL($path) {
return Url::pathToUri($path);
}
/**
* @param $path
*
* @return string
*/
public function pathToRelativePath($path) {
return preg_replace('/^' . preg_quote($this->_basepath, '/') . '/', '', str_replace('/', DIRECTORY_SEPARATOR, $path));
}
/**
* @param $path
*
* @return string
*/
public function pathToAbsolutePath($path) {
return $this->_basepath . str_replace('/', DIRECTORY_SEPARATOR, $path);
}
/**
* @param $url
*
* @return string
*/
public function absoluteURLToPath($url) {
$fullUri = Url::getFullUri();
if (substr($url, 0, strlen($fullUri)) == $fullUri) {
return str_replace($fullUri, $this->_basepath, $url);
}
return $url;
}
/**
* @param $file
*
* @return bool
*/
public function fileexists($file) {
return is_file($file);
}
/**
* @param $file
*
* @return bool
*/
public function safefileexists($file) {
return realpath($file) && is_file($file);
}
/**
*
* @param $dir
*
* @return array Folder names without trailing slash
*/
public function folders($dir) {
if (!is_dir($dir)) {
return array();
}
$folders = array();
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) $folders[] = $file;
}
return $folders;
}
/**
* @param $path
*
* @return bool
*/
public function is_writable($path) {
return is_writable($path);
}
/**
* @param $path
*
* @return bool
*/
public function createFolder($path) {
return mkdir($path, $this->dirPermission, true);
}
public function deleteFolder($dir) {
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (!$this->deleteFolder($dir . DIRECTORY_SEPARATOR . $file)) {
chmod($dir . DIRECTORY_SEPARATOR . $file, $this->dirPermission);
if (!$this->deleteFolder($dir . DIRECTORY_SEPARATOR . $file)) return false;
}
}
return rmdir($dir);
}
public function existsFolder($path) {
return is_dir($path);
}
public function files($path) {
$files = array();
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if ($file[0] != ".") {
$files[] = $file;
}
}
closedir($dh);
}
}
return $files;
}
/**
* @param $path
*
* @return bool
*/
public function existsFile($path) {
return file_exists($path);
}
/**
* @param $path
* @param $buffer
*
* @return int
*/
public function createFile($path, $buffer) {
return file_put_contents($path, $buffer);
}
/**
* @param $path
*
* @return string
*/
public function readFile($path) {
return file_get_contents($path);
}
/**
* convert dir alias to normal format
*
* @param $pathName
*
* @return mixed
*/
public function dirFormat($pathName) {
return str_replace(".", DIRECTORY_SEPARATOR, $pathName);
}
public function getImagesFolder() {
return '';
}
public function realpath($path) {
return rtrim(realpath($path), '/\\');
}
public function registerTranslate($from, $to) {
$this->translate[$from] = $to;
}
protected function trailingslashit($string) {
return $this->untrailingslashit($string) . '/';
}
protected function untrailingslashit($string) {
return rtrim($string, '/\\');
}
public function convertToRealDirectorySeparator($path) {
return str_replace(DIRECTORY_SEPARATOR == '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $path);
}
public function get_temp_dir() {
static $temp = '';
if (defined('SS_TEMP_DIR')) return $this->trailingslashit(SS_TEMP_DIR);
if ($temp) return $this->trailingslashit($temp);
if (function_exists('sys_get_temp_dir')) {
$temp = sys_get_temp_dir();
if (@is_dir($temp) && $this->is_writable($temp)) return $this->trailingslashit($temp);
}
$temp = ini_get('upload_tmp_dir');
if (@is_dir($temp) && $this->is_writable($temp)) return $this->trailingslashit($temp);
$temp = $this->getNotWebCachePath() . '/';
if (is_dir($temp) && $this->is_writable($temp)) return $temp;
return '/tmp/';
}
public function tempnam($filename = '', $dir = '') {
if (empty($dir)) {
$dir = $this->get_temp_dir();
}
if (empty($filename) || '.' == $filename || '/' == $filename || '\\' == $filename) {
$filename = time();
}
// Use the basename of the given file without the extension as the name for the temporary directory
$temp_filename = basename($filename);
$temp_filename = preg_replace('|\.[^.]*$|', '', $temp_filename);
// If the folder is falsey, use its parent directory name instead.
if (!$temp_filename) {
return $this->tempnam(dirname($filename), $dir);
}
// Suffix some random data to avoid filename conflicts
$temp_filename .= '-' . md5(uniqid(rand() . time()));
$temp_filename .= '.tmp';
$temp_filename = $dir . $temp_filename;
$fp = @fopen($temp_filename, 'x');
if (!$fp && is_writable($dir) && file_exists($temp_filename)) {
return $this->tempnam($filename, $dir);
}
if ($fp) {
fclose($fp);
}
return $temp_filename;
}
}
\ No newline at end of file
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.