File manager - Edit - /home/matthif/www/wp-content/languages/styles.tar
Back
gutenberg.php 0000666 00000004574 15226760533 0007266 0 ustar 00 <?php /** * Style generator based on settings. * * @package Neve\Core\Styles */ namespace Neve\Core\Styles; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; /** * Class Generator for Gutenberg editor. * * @package Neve\Core\Styles */ class Gutenberg extends Generator { use Css_Vars; /** * Generator constructor. */ public function __construct() { $this->context = Dynamic_Selector::CONTEXT_GUTENBERG; $this->setup_buttons(); $this->setup_typography(); $this->add_editor_color_palette_styles(); } /** * Setup typography subscribers. */ public function setup_typography() { $rules = $this->get_typography_rules(); $this->_subscribers[] = [ Dynamic_Selector::KEY_SELECTOR => ':root', Dynamic_Selector::KEY_RULES => $rules, Dynamic_Selector::KEY_CONTEXT => [ Dynamic_Selector::CONTEXT_GUTENBERG => true, ], ]; } /** * Setup button subscribers. */ public function setup_buttons() { $rules = $this->get_button_rules(); $this->_subscribers[] = [ Dynamic_Selector::KEY_SELECTOR => ':root', Dynamic_Selector::KEY_RULES => $rules, Dynamic_Selector::KEY_CONTEXT => [ Dynamic_Selector::CONTEXT_GUTENBERG => true, ], ]; } /** * Adds colors from the editor-color-palette theme support. */ private function add_editor_color_palette_styles() { $is_new_user = get_option( 'neve_new_user' ); $imported_starter_site = get_option( 'neve_imported_demo' ); if ( $is_new_user === 'yes' && $imported_starter_site !== 'yes' ) { return; } $this->_subscribers['.has-neve-button-color-color'] = [ Config::CSS_PROP_COLOR => [ Dynamic_Selector::META_KEY => Config::MODS_BUTTON_PRIMARY_STYLE . '.background', Dynamic_Selector::META_IMPORTANT => true, Dynamic_Selector::META_DEFAULT => 'var(--nv-primary-accent)', Dynamic_Selector::KEY_CONTEXT => [ Dynamic_Selector::CONTEXT_GUTENBERG => true, ], ], ]; $this->_subscribers['.has-neve-button-color-background-color'] = [ Config::CSS_PROP_BACKGROUND_COLOR => [ Dynamic_Selector::META_KEY => Config::MODS_BUTTON_PRIMARY_STYLE . '.background', Dynamic_Selector::META_IMPORTANT => true, Dynamic_Selector::META_DEFAULT => 'var(--nv-primary-accent)', Dynamic_Selector::KEY_CONTEXT => [ Dynamic_Selector::CONTEXT_GUTENBERG => true, ], ], ]; } } elFinderVolumeLocalFileSystem.class.php 0000666 00000136366 15226760533 0014315 0 ustar 00 <?php // Implement similar functionality in PHP 5.2 or 5.3 // http://php.net/manual/class.recursivecallbackfilteriterator.php#110974 if (!class_exists('RecursiveCallbackFilterIterator', false)) { class RecursiveCallbackFilterIterator extends RecursiveFilterIterator { private $callback; public function __construct(RecursiveIterator $iterator, $callback) { $this->callback = $callback; parent::__construct($iterator); } public function accept() { return call_user_func($this->callback, parent::current(), parent::key(), parent::getInnerIterator()); } public function getChildren() { return new self($this->getInnerIterator()->getChildren(), $this->callback); } } } /** * elFinder driver for local filesystem. * * @author Dmitry (dio) Levashov * @author Troex Nevelin **/ class elFinderVolumeLocalFileSystem extends elFinderVolumeDriver { /** * Driver id * Must be started from letter and contains [a-z0-9] * Used as part of volume id * * @var string **/ protected $driverId = 'l'; /** * Required to count total archive files size * * @var int **/ protected $archiveSize = 0; /** * Is checking stat owner * * @var boolean */ protected $statOwner = false; /** * Path to quarantine directory * * @var string */ private $quarantine; /** * Constructor * Extend options with required fields * * @author Dmitry (dio) Levashov */ public function __construct() { $this->options['alias'] = ''; // alias to replace root dir name $this->options['dirMode'] = 0755; // new dirs mode $this->options['fileMode'] = 0644; // new files mode $this->options['rootCssClass'] = 'elfinder-navbar-root-local'; $this->options['followSymLinks'] = true; $this->options['detectDirIcon'] = ''; // file name that is detected as a folder icon e.g. '.diricon.png' $this->options['keepTimestamp'] = array('copy', 'move'); // keep timestamp at inner filesystem allowed 'copy', 'move' and 'upload' $this->options['substituteImg'] = true; // support substitute image with dim command $this->options['statCorrector'] = null; // callable to correct stat data `function(&$stat, $path, $statOwner, $volumeDriveInstance){}` if (DIRECTORY_SEPARATOR === '/') { // Linux $this->options['acceptedName'] = '/^[^\.\/\x00][^\/\x00]*$/'; } else { // Windows $this->options['acceptedName'] = '/^[^\.\/\x00\\\:*?"<>|][^\/\x00\\\:*?"<>|]*$/'; } } /*********************************************************************/ /* INIT AND CONFIGURE */ /*********************************************************************/ /** * Prepare driver before mount volume. * Return true if volume is ready. * * @return bool **/ protected function init() { // Normalize directory separator for windows if (DIRECTORY_SEPARATOR !== '/') { foreach (array('path', 'tmbPath', 'tmpPath', 'quarantine') as $key) { if (!empty($this->options[$key])) { $this->options[$key] = str_replace('/', DIRECTORY_SEPARATOR, $this->options[$key]); } } // PHP >= 7.1 Supports UTF-8 path on Windows if (version_compare(PHP_VERSION, '7.1', '>=')) { $this->options['encoding'] = ''; $this->options['locale'] = ''; } } if (!$cwd = getcwd()) { return $this->setError('elFinder LocalVolumeDriver requires a result of getcwd().'); } // detect systemRoot if (!isset($this->options['systemRoot'])) { if ($cwd[0] === DIRECTORY_SEPARATOR || $this->root[0] === DIRECTORY_SEPARATOR) { $this->systemRoot = DIRECTORY_SEPARATOR; } else if (preg_match('/^([a-zA-Z]:' . preg_quote(DIRECTORY_SEPARATOR, '/') . ')/', $this->root, $m)) { $this->systemRoot = $m[1]; } else if (preg_match('/^([a-zA-Z]:' . preg_quote(DIRECTORY_SEPARATOR, '/') . ')/', $cwd, $m)) { $this->systemRoot = $m[1]; } } $this->root = $this->getFullPath($this->root, $cwd); if (!empty($this->options['startPath'])) { $this->options['startPath'] = $this->getFullPath($this->options['startPath'], $this->root); } if (is_null($this->options['syncChkAsTs'])) { $this->options['syncChkAsTs'] = true; } if (is_null($this->options['syncCheckFunc'])) { $this->options['syncCheckFunc'] = array($this, 'localFileSystemInotify'); } // check 'statCorrector' if (empty($this->options['statCorrector']) || !is_callable($this->options['statCorrector'])) { $this->options['statCorrector'] = null; } return true; } /** * Configure after successfull mount. * * @return void * @throws elFinderAbortException * @author Dmitry (dio) Levashov */ protected function configure() { $hiddens = array(); $root = $this->stat($this->root); // check thumbnails path if (!empty($this->options['tmbPath'])) { if (strpos($this->options['tmbPath'], DIRECTORY_SEPARATOR) === false) { $hiddens['tmb'] = $this->options['tmbPath']; $this->options['tmbPath'] = $this->_abspath($this->options['tmbPath']); } else { $this->options['tmbPath'] = $this->_normpath($this->options['tmbPath']); } } // check temp path if (!empty($this->options['tmpPath'])) { if (strpos($this->options['tmpPath'], DIRECTORY_SEPARATOR) === false) { $hiddens['temp'] = $this->options['tmpPath']; $this->options['tmpPath'] = $this->_abspath($this->options['tmpPath']); } else { $this->options['tmpPath'] = $this->_normpath($this->options['tmpPath']); } } // check quarantine path $_quarantine = ''; if (!empty($this->options['quarantine'])) { if (strpos($this->options['quarantine'], DIRECTORY_SEPARATOR) === false) { $_quarantine = $this->_abspath($this->options['quarantine']); $this->options['quarantine'] = ''; } else { $this->options['quarantine'] = $this->_normpath($this->options['quarantine']); } } else { $_quarantine = $this->_abspath('.quarantine'); } is_dir($_quarantine) && self::localRmdirRecursive($_quarantine); parent::configure(); // check tmbPath if (!$this->tmbPath && isset($hiddens['tmb'])) { unset($hiddens['tmb']); } // if no thumbnails url - try detect it if ($root['read'] && !$this->tmbURL && $this->URL) { if (strpos($this->tmbPath, $this->root) === 0) { $this->tmbURL = $this->URL . str_replace(DIRECTORY_SEPARATOR, '/', substr($this->tmbPath, strlen($this->root) + 1)); if (preg_match("|[^/?&=]$|", $this->tmbURL)) { $this->tmbURL .= '/'; } } } // set $this->tmp by options['tmpPath'] $this->tmp = ''; if (!empty($this->options['tmpPath'])) { if ((is_dir($this->options['tmpPath']) || mkdir($this->options['tmpPath'], $this->options['dirMode'], true)) && is_writable($this->options['tmpPath'])) { $this->tmp = $this->options['tmpPath']; } else { if (isset($hiddens['temp'])) { unset($hiddens['temp']); } } } if (!$this->tmp && ($tmp = elFinder::getStaticVar('commonTempPath'))) { $this->tmp = $tmp; } // check quarantine dir $this->quarantine = ''; if (!empty($this->options['quarantine'])) { if ((is_dir($this->options['quarantine']) || mkdir($this->options['quarantine'], $this->options['dirMode'], true)) && is_writable($this->options['quarantine'])) { $this->quarantine = $this->options['quarantine']; } else { if (isset($hiddens['quarantine'])) { unset($hiddens['quarantine']); } } } else if ($_path = elFinder::getCommonTempPath()) { $this->quarantine = $_path; } if (!$this->quarantine) { if (!$this->tmp) { $this->archivers['extract'] = array(); $this->disabled[] = 'extract'; } else { $this->quarantine = $this->tmp; } } if ($hiddens) { foreach ($hiddens as $hidden) { $this->attributes[] = array( 'pattern' => '~^' . preg_quote(DIRECTORY_SEPARATOR . $hidden, '~') . '$~', 'read' => false, 'write' => false, 'locked' => true, 'hidden' => true ); } } if (!empty($this->options['keepTimestamp'])) { $this->options['keepTimestamp'] = array_flip($this->options['keepTimestamp']); } $this->statOwner = (!empty($this->options['statOwner'])); // enable WinRemoveTailDots plugin on Windows server if (DIRECTORY_SEPARATOR !== '/') { if (!isset($this->options['plugin'])) { $this->options['plugin'] = array(); } $this->options['plugin']['WinRemoveTailDots'] = array('enable' => true); } } /** * Long pooling sync checker * This function require server command `inotifywait` * If `inotifywait` need full path, Please add `define('ELFINER_INOTIFYWAIT_PATH', '/PATH_TO/inotifywait');` into connector.php * * @param string $path * @param int $standby * @param number $compare * * @return number|bool * @throws elFinderAbortException */ public function localFileSystemInotify($path, $standby, $compare) { if (isset($this->sessionCache['localFileSystemInotify_disable'])) { return false; } $path = realpath($path); $mtime = filemtime($path); if (!$mtime) { return false; } if ($mtime != $compare) { return $mtime; } $inotifywait = defined('ELFINER_INOTIFYWAIT_PATH') ? ELFINER_INOTIFYWAIT_PATH : 'inotifywait'; $standby = max(1, intval($standby)); $cmd = $inotifywait . ' ' . escapeshellarg($path) . ' -t ' . $standby . ' -e moved_to,moved_from,move,close_write,delete,delete_self'; $this->procExec($cmd, $o, $r); if ($r === 0) { // changed clearstatcache(); if (file_exists($path)) { $mtime = filemtime($path); // error on busy? return $mtime ? $mtime : time(); } else { // target was removed return 0; } } else if ($r === 2) { // not changed (timeout) return $compare; } // error // cache to $_SESSION $this->sessionCache['localFileSystemInotify_disable'] = true; $this->session->set($this->id, $this->sessionCache); return false; } /*********************************************************************/ /* FS API */ /*********************************************************************/ /*********************** paths/urls *************************/ /** * Return parent directory path * * @param string $path file path * * @return string * @author Dmitry (dio) Levashov **/ protected function _dirname($path) { return dirname($path); } /** * Return file name * * @param string $path file path * * @return string * @author Dmitry (dio) Levashov **/ protected function _basename($path) { return basename($path); } /** * Join dir name and file name and retur full path * * @param string $dir * @param string $name * * @return string * @author Dmitry (dio) Levashov **/ protected function _joinPath($dir, $name) { $dir = rtrim($dir, DIRECTORY_SEPARATOR); $path = realpath($dir . DIRECTORY_SEPARATOR . $name); // realpath() returns FALSE if the file does not exist if ($path === false || strpos($path, $this->root) !== 0) { if (DIRECTORY_SEPARATOR !== '/') { $dir = str_replace('/', DIRECTORY_SEPARATOR, $dir); $name = str_replace('/', DIRECTORY_SEPARATOR, $name); } // Directory traversal measures if (strpos($dir, '..' . DIRECTORY_SEPARATOR) !== false || substr($dir, -2) == '..') { $dir = $this->root; } if (strpos($name, '..' . DIRECTORY_SEPARATOR) !== false) { $name = basename($name); } $path = $dir . DIRECTORY_SEPARATOR . $name; } return $path; } /** * Return normalized path, this works the same as os.path.normpath() in Python * * @param string $path path * * @return string * @author Troex Nevelin **/ protected function _normpath($path) { if (empty($path)) { return '.'; } $changeSep = (DIRECTORY_SEPARATOR !== '/'); if ($changeSep) { $drive = ''; if (preg_match('/^([a-zA-Z]:)(.*)/', $path, $m)) { $drive = $m[1]; $path = $m[2] ? $m[2] : '/'; } $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); } if (strpos($path, '/') === 0) { $initial_slashes = true; } else { $initial_slashes = false; } if (($initial_slashes) && (strpos($path, '//') === 0) && (strpos($path, '///') === false)) { $initial_slashes = 2; } $initial_slashes = (int)$initial_slashes; $comps = explode('/', $path); $new_comps = array(); foreach ($comps as $comp) { if (in_array($comp, array('', '.'))) { continue; } if (($comp != '..') || (!$initial_slashes && !$new_comps) || ($new_comps && (end($new_comps) == '..'))) { array_push($new_comps, $comp); } elseif ($new_comps) { array_pop($new_comps); } } $comps = $new_comps; $path = implode('/', $comps); if ($initial_slashes) { $path = str_repeat('/', $initial_slashes) . $path; } if ($changeSep) { $path = $drive . str_replace('/', DIRECTORY_SEPARATOR, $path); } return $path ? $path : '.'; } /** * Return file path related to root dir * * @param string $path file path * * @return string * @author Dmitry (dio) Levashov **/ protected function _relpath($path) { if ($path === $this->root) { return ''; } else { if (strpos($path, $this->root) === 0) { return ltrim(substr($path, strlen($this->root)), DIRECTORY_SEPARATOR); } else { // for link return $path; } } } /** * Convert path related to root dir into real path * * @param string $path file path * * @return string * @author Dmitry (dio) Levashov **/ protected function _abspath($path) { if ($path === DIRECTORY_SEPARATOR) { return $this->root; } else { $path = $this->_normpath($path); if (strpos($path, $this->systemRoot) === 0) { return $path; } else if (DIRECTORY_SEPARATOR !== '/' && preg_match('/^[a-zA-Z]:' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', $path)) { return $path; } else { return $this->_joinPath($this->root, $path); } } } /** * Return fake path started from root dir * * @param string $path file path * * @return string * @author Dmitry (dio) Levashov **/ protected function _path($path) { return $this->rootName . ($path == $this->root ? '' : $this->separator . $this->_relpath($path)); } /** * Return true if $path is children of $parent * * @param string $path path to check * @param string $parent parent path * * @return bool * @author Dmitry (dio) Levashov **/ protected function _inpath($path, $parent) { $cwd = getcwd(); $real_path = $this->getFullPath($path, $cwd); $real_parent = $this->getFullPath($parent, $cwd); if ($real_path && $real_parent) { return $real_path === $real_parent || strpos($real_path, rtrim($real_parent, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR) === 0; } return false; } /***************** file stat ********************/ /** * Return stat for given path. * Stat contains following fields: * - (int) size file size in b. required * - (int) ts file modification time in unix time. required * - (string) mime mimetype. required for folders, others - optionally * - (bool) read read permissions. required * - (bool) write write permissions. required * - (bool) locked is object locked. optionally * - (bool) hidden is object hidden. optionally * - (string) alias for symlinks - link target path relative to root path. optionally * - (string) target for symlinks - link target path. optionally * If file does not exists - returns empty array or false. * * @param string $path file path * * @return array|false * @author Dmitry (dio) Levashov **/ protected function _stat($path) { $stat = array(); if (!file_exists($path) && !is_link($path)) { return $stat; } //Verifies the given path is the root or is inside the root. Prevents directory traveral. if (!$this->_inpath($path, $this->root)) { return $stat; } $stat['isowner'] = false; $linkreadable = false; if ($path != $this->root && is_link($path)) { if (!$this->options['followSymLinks']) { return array(); } if (!($target = $this->readlink($path)) || $target == $path) { if (is_null($target)) { $stat = array(); return $stat; } else { $stat['mime'] = 'symlink-broken'; $target = readlink($path); $lstat = lstat($path); $ostat = $this->getOwnerStat($lstat['uid'], $lstat['gid']); $linkreadable = !empty($ostat['isowner']); } } $stat['alias'] = $this->_path($target); $stat['target'] = $target; } $readable = is_readable($path); if ($readable) { $size = sprintf('%u', filesize($path)); $stat['ts'] = filemtime($path); if ($this->statOwner) { $fstat = stat($path); $uid = $fstat['uid']; $gid = $fstat['gid']; $stat['perm'] = substr((string)decoct($fstat['mode']), -4); $stat = array_merge($stat, $this->getOwnerStat($uid, $gid)); } } if (($dir = is_dir($path)) && $this->options['detectDirIcon']) { $favicon = $path . DIRECTORY_SEPARATOR . $this->options['detectDirIcon']; if ($this->URL && file_exists($favicon)) { $stat['icon'] = $this->URL . str_replace(DIRECTORY_SEPARATOR, '/', substr($favicon, strlen($this->root) + 1)); } } if (!isset($stat['mime'])) { $stat['mime'] = $dir ? 'directory' : $this->mimetype($path); } //logical rights first $stat['read'] = ($linkreadable || $readable) ? null : false; $stat['write'] = is_writable($path) ? null : false; if (is_null($stat['read'])) { if ($dir) { $stat['size'] = 0; } else if (isset($size)) { $stat['size'] = $size; } } if ($this->options['statCorrector']) { call_user_func_array($this->options['statCorrector'], array(&$stat, $path, $this->statOwner, $this)); } return $stat; } /** * Get stat `owner`, `group` and `isowner` by `uid` and `gid` * Sub-fuction of _stat() and _scandir() * * @param integer $uid * @param integer $gid * * @return array stat */ protected function getOwnerStat($uid, $gid) { static $names = null; static $phpuid = null; if (is_null($names)) { $names = array('uid' => array(), 'gid' => array()); } if (is_null($phpuid)) { if (is_callable('posix_getuid')) { $phpuid = posix_getuid(); } else { $phpuid = 0; } } $stat = array(); if ($uid) { $stat['isowner'] = ($phpuid == $uid); if (isset($names['uid'][$uid])) { $stat['owner'] = $names['uid'][$uid]; } else if (is_callable('posix_getpwuid')) { $pwuid = posix_getpwuid($uid); $stat['owner'] = $names['uid'][$uid] = $pwuid['name']; } else { $stat['owner'] = $names['uid'][$uid] = $uid; } } if ($gid) { if (isset($names['gid'][$gid])) { $stat['group'] = $names['gid'][$gid]; } else if (is_callable('posix_getgrgid')) { $grgid = posix_getgrgid($gid); $stat['group'] = $names['gid'][$gid] = $grgid['name']; } else { $stat['group'] = $names['gid'][$gid] = $gid; } } return $stat; } /** * Return true if path is dir and has at least one childs directory * * @param string $path dir path * * @return bool * @author Dmitry (dio) Levashov **/ protected function _subdirs($path) { $dirs = false; if (is_dir($path) && is_readable($path)) { if (class_exists('FilesystemIterator', false)) { $dirItr = new ParentIterator( new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_SELF | (defined('RecursiveDirectoryIterator::FOLLOW_SYMLINKS') ? RecursiveDirectoryIterator::FOLLOW_SYMLINKS : 0) ) ); $dirItr->rewind(); if ($dirItr->hasChildren()) { $dirs = true; $name = $dirItr->getSubPathName(); while ($dirItr->valid()) { if (!$this->attr($path . DIRECTORY_SEPARATOR . $name, 'read', null, true)) { $dirs = false; $dirItr->next(); $name = $dirItr->getSubPathName(); continue; } $dirs = true; break; } } } else { $path = strtr($path, array('[' => '\\[', ']' => '\\]', '*' => '\\*', '?' => '\\?')); return (bool)glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR); } } return $dirs; } /** * Return object width and height * Usualy used for images, but can be realize for video etc... * * @param string $path file path * @param string $mime file mime type * * @return string * @author Dmitry (dio) Levashov **/ protected function _dimensions($path, $mime) { clearstatcache(); return strpos($mime, 'image') === 0 && is_readable($path) && filesize($path) && ($s = getimagesize($path)) !== false ? $s[0] . 'x' . $s[1] : false; } /******************** file/dir content *********************/ /** * Return symlink target file * * @param string $path link path * * @return string * @author Dmitry (dio) Levashov **/ protected function readlink($path) { if (!($target = readlink($path))) { return null; } if (strpos($target, $this->systemRoot) !== 0) { $target = $this->_joinPath(dirname($path), $target); } if (!file_exists($target)) { return false; } return $target; } /** * Return files list in directory. * * @param string $path dir path * * @return array * @throws elFinderAbortException * @author Dmitry (dio) Levashov */ protected function _scandir($path) { elFinder::checkAborted(); $files = array(); $cache = array(); $dirWritable = is_writable($path); $dirItr = array(); $followSymLinks = $this->options['followSymLinks']; try { $dirItr = new DirectoryIterator($path); } catch (UnexpectedValueException $e) { } foreach ($dirItr as $file) { try { if ($file->isDot()) { continue; } $files[] = $fpath = $file->getPathname(); $br = false; $stat = array(); $stat['isowner'] = false; $linkreadable = false; if ($file->isLink()) { if (!$followSymLinks) { continue; } if (!($target = $this->readlink($fpath)) || $target == $fpath) { if (is_null($target)) { $stat = array(); $br = true; } else { $_path = $fpath; $stat['mime'] = 'symlink-broken'; $target = readlink($_path); $lstat = lstat($_path); $ostat = $this->getOwnerStat($lstat['uid'], $lstat['gid']); $linkreadable = !empty($ostat['isowner']); $dir = false; $stat['alias'] = $this->_path($target); $stat['target'] = $target; } } else { $dir = is_dir($target); $stat['alias'] = $this->_path($target); $stat['target'] = $target; $stat['mime'] = $dir ? 'directory' : $this->mimetype($stat['alias']); } } else { if (($dir = $file->isDir()) && $this->options['detectDirIcon']) { $path = $file->getPathname(); $favicon = $path . DIRECTORY_SEPARATOR . $this->options['detectDirIcon']; if ($this->URL && file_exists($favicon)) { $stat['icon'] = $this->URL . str_replace(DIRECTORY_SEPARATOR, '/', substr($favicon, strlen($this->root) + 1)); } } $stat['mime'] = $dir ? 'directory' : $this->mimetype($fpath); } $size = sprintf('%u', $file->getSize()); $stat['ts'] = $file->getMTime(); if (!$br) { if ($this->statOwner && !$linkreadable) { $uid = $file->getOwner(); $gid = $file->getGroup(); $stat['perm'] = substr((string)decoct($file->getPerms()), -4); $stat = array_merge($stat, $this->getOwnerStat($uid, $gid)); } //logical rights first $stat['read'] = ($linkreadable || $file->isReadable()) ? null : false; $stat['write'] = $file->isWritable() ? null : false; $stat['locked'] = $dirWritable ? null : true; if (is_null($stat['read'])) { $stat['size'] = $dir ? 0 : $size; } if ($this->options['statCorrector']) { call_user_func_array($this->options['statCorrector'], array(&$stat, $fpath, $this->statOwner, $this)); } } $cache[] = array($fpath, $stat); } catch (RuntimeException $e) { continue; } } if ($cache) { $cache = $this->convEncOut($cache, false); foreach ($cache as $d) { $this->updateCache($d[0], $d[1]); } } return $files; } /** * Open file and return file pointer * * @param string $path file path * @param string $mode * * @return false|resource * @internal param bool $write open file for writing * @author Dmitry (dio) Levashov */ protected function _fopen($path, $mode = 'rb') { return fopen($path, $mode); } /** * Close opened file * * @param resource $fp file pointer * @param string $path * * @return bool * @author Dmitry (dio) Levashov */ protected function _fclose($fp, $path = '') { return (is_resource($fp) && fclose($fp)); } /******************** file/dir manipulations *************************/ /** * Create dir and return created dir path or false on failed * * @param string $path parent dir path * @param string $name new directory name * * @return string|bool * @author Dmitry (dio) Levashov **/ protected function _mkdir($path, $name) { $path = $this->_joinPath($path, $name); if (mkdir($path)) { chmod($path, $this->options['dirMode']); return $path; } return false; } /** * Create file and return it's path or false on failed * * @param string $path parent dir path * @param string $name new file name * * @return string|bool * @author Dmitry (dio) Levashov **/ protected function _mkfile($path, $name) { $path = $this->_joinPath($path, $name); if (($fp = fopen($path, 'w'))) { fclose($fp); chmod($path, $this->options['fileMode']); return $path; } return false; } /** * Create symlink * * @param string $source file to link to * @param string $targetDir folder to create link in * @param string $name symlink name * * @return bool * @author Dmitry (dio) Levashov **/ protected function _symlink($source, $targetDir, $name) { return $this->localFileSystemSymlink($source, $this->_joinPath($targetDir, $name)); } /** * Copy file into another file * * @param string $source source file path * @param string $targetDir target directory path * @param string $name new file name * * @return bool * @author Dmitry (dio) Levashov **/ protected function _copy($source, $targetDir, $name) { $mtime = filemtime($source); $target = $this->_joinPath($targetDir, $name); if ($ret = copy($source, $target)) { isset($this->options['keepTimestamp']['copy']) && $mtime && touch($target, $mtime); } return $ret; } /** * Move file into another parent dir. * Return new file path or false. * * @param string $source source file path * @param $targetDir * @param string $name file name * * @return bool|string * @internal param string $target target dir path * @author Dmitry (dio) Levashov */ protected function _move($source, $targetDir, $name) { $mtime = filemtime($source); $target = $this->_joinPath($targetDir, $name); if ($ret = rename($source, $target) ? $target : false) { isset($this->options['keepTimestamp']['move']) && $mtime && touch($target, $mtime); } return $ret; } /** * Remove file * * @param string $path file path * * @return bool * @author Dmitry (dio) Levashov **/ protected function _unlink($path) { return is_file($path) && unlink($path); } /** * Remove dir * * @param string $path dir path * * @return bool * @author Dmitry (dio) Levashov **/ protected function _rmdir($path) { return rmdir($path); } /** * Create new file and write into it from file pointer. * Return new file path or false on error. * * @param resource $fp file pointer * @param string $dir target dir path * @param string $name file name * @param array $stat file stat (required by some virtual fs) * * @return bool|string * @author Dmitry (dio) Levashov **/ protected function _save($fp, $dir, $name, $stat) { $path = $this->_joinPath($dir, $name); $meta = stream_get_meta_data($fp); $uri = isset($meta['uri']) ? $meta['uri'] : ''; if ($uri && !preg_match('#^[a-zA-Z0-9]+://#', $uri) && !is_link($uri)) { fclose($fp); $mtime = filemtime($uri); $isCmdPaste = ($this->ARGS['cmd'] === 'paste'); $isCmdCopy = ($isCmdPaste && empty($this->ARGS['cut'])); if (($isCmdCopy || !rename($uri, $path)) && !copy($uri, $path)) { return false; } // keep timestamp on upload if ($mtime && $this->ARGS['cmd'] === 'upload') { touch($path, isset($this->options['keepTimestamp']['upload']) ? $mtime : time()); } } else { if (file_put_contents($path, $fp, LOCK_EX) === false) { return false; } } chmod($path, $this->options['fileMode']); return $path; } /** * Get file contents * * @param string $path file path * * @return string|false * @author Dmitry (dio) Levashov **/ protected function _getContents($path) { return file_get_contents($path); } /** * Write a string to a file * * @param string $path file path * @param string $content new file content * * @return bool * @author Dmitry (dio) Levashov **/ protected function _filePutContents($path, $content) { return (file_put_contents($path, $content, LOCK_EX) !== false); } /** * Detect available archivers * * @return void * @throws elFinderAbortException */ protected function _checkArchivers() { $this->archivers = $this->getArchivers(); return; } /** * chmod availability * * @param string $path * @param string $mode * * @return bool */ protected function _chmod($path, $mode) { $modeOct = is_string($mode) ? octdec($mode) : octdec(sprintf("%04o", $mode)); return chmod($path, $modeOct); } /** * Recursive symlinks search * * @param string $path file/dir path * * @return bool * @throws Exception * @author Dmitry (dio) Levashov */ protected function _findSymlinks($path) { return self::localFindSymlinks($path); } /** * Extract files from archive * * @param string $path archive path * @param array $arc archiver command and arguments (same as in $this->archivers) * * @return array|string|boolean * @throws elFinderAbortException * @author Dmitry (dio) Levashov, * @author Alexey Sukhotin */ protected function _extract($path, $arc) { if ($this->quarantine) { $dir = $this->quarantine . DIRECTORY_SEPARATOR . md5(basename($path) . mt_rand()); $archive = (isset($arc['toSpec']) || $arc['cmd'] === 'phpfunction') ? '' : $dir . DIRECTORY_SEPARATOR . basename($path); if (!mkdir($dir)) { return false; } // insurance unexpected shutdown register_shutdown_function(array($this, 'rmdirRecursive'), realpath($dir)); chmod($dir, 0777); // copy in quarantine if (!is_readable($path) || ($archive && !copy($path, $archive))) { return false; } // extract in quarantine try { $this->unpackArchive($path, $arc, $archive ? true : $dir); } catch(Exception $e) { return $this->setError($e->getMessage()); } // get files list try { $ls = self::localScandir($dir); } catch (Exception $e) { return false; } // no files - extract error ? if (empty($ls)) { return false; } $this->archiveSize = 0; // find symlinks and check extracted items $checkRes = $this->checkExtractItems($dir); if ($checkRes['symlinks']) { self::localRmdirRecursive($dir); return $this->setError(array_merge($this->error, array(elFinder::ERROR_ARC_SYMLINKS))); } $this->archiveSize = $checkRes['totalSize']; if ($checkRes['rmNames']) { foreach ($checkRes['rmNames'] as $name) { $this->addError(elFinder::ERROR_SAVE, $name); } } // check max files size if ($this->options['maxArcFilesSize'] > 0 && $this->options['maxArcFilesSize'] < $this->archiveSize) { $this->delTree($dir); return $this->setError(elFinder::ERROR_ARC_MAXSIZE); } $extractTo = $this->extractToNewdir; // 'auto', ture or false // archive contains one item - extract in archive dir $name = ''; $src = $dir . DIRECTORY_SEPARATOR . $ls[0]; if (($extractTo === 'auto' || !$extractTo) && count($ls) === 1 && is_file($src)) { $name = $ls[0]; } else if ($extractTo === 'auto' || $extractTo) { // for several files - create new directory // create unique name for directory $src = $dir; $splits = elFinder::splitFileExtention(basename($path)); $name = $splits[0]; $test = dirname($path) . DIRECTORY_SEPARATOR . $name; if (file_exists($test) || is_link($test)) { $name = $this->uniqueName(dirname($path), $name, '-', false); } } if ($name !== '') { $result = dirname($path) . DIRECTORY_SEPARATOR . $name; if (!rename($src, $result)) { $this->delTree($dir); return false; } } else { $dstDir = dirname($path); $result = array(); foreach ($ls as $name) { $target = $dstDir . DIRECTORY_SEPARATOR . $name; if (self::localMoveRecursive($dir . DIRECTORY_SEPARATOR . $name, $target, true, $this->options['copyJoin'])) { $result[] = $target; } } if (!$result) { $this->delTree($dir); return false; } } is_dir($dir) && $this->delTree($dir); return (is_array($result) || file_exists($result)) ? $result : false; } //TODO: Add return statement here return false; } /** * Create archive and return its path * * @param string $dir target dir * @param array $files files names list * @param string $name archive name * @param array $arc archiver options * * @return string|bool * @throws elFinderAbortException * @author Dmitry (dio) Levashov, * @author Alexey Sukhotin */ protected function _archive($dir, $files, $name, $arc) { return $this->makeArchive($dir, $files, $name, $arc); } /******************** Over write functions *************************/ /** * File path of local server side work file path * * @param string $path * * @return string * @author Naoki Sawada */ protected function getWorkFile($path) { return $path; } /** * Delete dirctory trees * * @param string $localpath path need convert encoding to server encoding * * @return boolean * @throws elFinderAbortException * @author Naoki Sawada */ protected function delTree($localpath) { return $this->rmdirRecursive($localpath); } /** * Return fileinfo based on filename * For item ID based path file system * Please override if needed on each drivers * * @param string $path file cache * * @return array|boolean false */ protected function isNameExists($path) { $exists = file_exists($this->convEncIn($path)); // restore locale $this->convEncOut(); return $exists ? $this->stat($path) : false; } /******************** Over write (Optimized) functions *************************/ /** * Recursive files search * * @param string $path dir path * @param string $q search string * @param array $mimes * * @return array * @throws elFinderAbortException * @author Dmitry (dio) Levashov * @author Naoki Sawada */ protected function doSearch($path, $q, $mimes) { if (!empty($this->doSearchCurrentQuery['matchMethod']) || $this->encoding || !class_exists('FilesystemIterator', false)) { // has custom match method or non UTF-8, use elFinderVolumeDriver::doSearch() return parent::doSearch($path, $q, $mimes); } $result = array(); $timeout = $this->options['searchTimeout'] ? $this->searchStart + $this->options['searchTimeout'] : 0; if ($timeout && $timeout < time()) { $this->setError(elFinder::ERROR_SEARCH_TIMEOUT, $this->path($this->encode($path))); return $result; } elFinder::extendTimeLimit($this->options['searchTimeout'] + 30); $match = array(); try { $iterator = new RecursiveIteratorIterator( new RecursiveCallbackFilterIterator( new RecursiveDirectoryIterator($path, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::SKIP_DOTS | ((defined('RecursiveDirectoryIterator::FOLLOW_SYMLINKS') && $this->options['followSymLinks']) ? RecursiveDirectoryIterator::FOLLOW_SYMLINKS : 0) ), array($this, 'localFileSystemSearchIteratorFilter') ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD ); foreach ($iterator as $key => $node) { if ($timeout && ($this->error || $timeout < time())) { !$this->error && $this->setError(elFinder::ERROR_SEARCH_TIMEOUT, $this->path($this->encode($node->getPath))); break; } if ($node->isDir()) { if ($this->stripos($node->getFilename(), $q) !== false) { $match[] = $key; } } else { $match[] = $key; } } } catch (Exception $e) { } if ($match) { foreach ($match as $p) { if ($timeout && ($this->error || $timeout < time())) { !$this->error && $this->setError(elFinder::ERROR_SEARCH_TIMEOUT, $this->path($this->encode(dirname($p)))); break; } $stat = $this->stat($p); if (!$stat) { // invalid links continue; } if (!empty($stat['hidden']) || !$this->mimeAccepted($stat['mime'], $mimes)) { continue; } if ((!$mimes || $stat['mime'] !== 'directory')) { $stat['path'] = $this->path($stat['hash']); if ($this->URL && !isset($stat['url'])) { $_path = str_replace(DIRECTORY_SEPARATOR, '/', substr($p, strlen($this->root) + 1)); $stat['url'] = $this->URL . str_replace('%2F', '/', rawurlencode($_path)); } $result[] = $stat; } } } return $result; } /******************** Original local functions ************************ * * @param $file * @param $key * @param $iterator * * @return bool */ public function localFileSystemSearchIteratorFilter($file, $key, $iterator) { /* @var FilesystemIterator $file */ /* @var RecursiveDirectoryIterator $iterator */ $name = $file->getFilename(); if ($this->doSearchCurrentQuery['excludes']) { foreach ($this->doSearchCurrentQuery['excludes'] as $exclude) { if ($this->stripos($name, $exclude) !== false) { return false; } } } if ($iterator->hasChildren()) { if ($this->options['searchExDirReg'] && preg_match($this->options['searchExDirReg'], $key)) { return false; } return (bool)$this->attr($key, 'read', null, true); } return ($this->stripos($name, $this->doSearchCurrentQuery['q']) === false) ? false : true; } /** * Creates a symbolic link * * @param string $target The target * @param string $link The link * * @return boolean ( result of symlink() ) */ protected function localFileSystemSymlink($target, $link) { $res = false; if (function_exists('symlink') and is_callable('symlink')) { $errlev = error_reporting(); error_reporting($errlev ^ E_WARNING); if ($res = symlink(realpath($target), $link)) { $res = is_readable($link); } error_reporting($errlev); } return $res; } } // END class css_prop.php 0000666 00000033142 15226760533 0007125 0 ustar 00 <?php namespace Neve\Core\Styles; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; use Neve\Views\Font_Manager; class Css_Prop { /** * Helper method to build the value based on 100 diff. */ public static function minus_100( $css_prop, $value, $meta, $device ) { return sprintf( "%s: %s%s;", ( $css_prop ), ( 100 - $value ), isset( $meta[ Dynamic_Selector::META_SUFFIX ] ) ? $meta[ Dynamic_Selector::META_SUFFIX ] : 'px' ); } /** * Get suffix from controls that store data in the following format: * { desktop: value, tablet: value, mobile: value, deskotp-unit: px, tablet-unit: px, mobile-unit: px } * * @param array $meta Subscribers meta data. */ public static function get_unit_responsive( $meta, $device ) { $all_value = Mods::get( $meta['key'], isset( $meta[ Dynamic_Selector::META_DEFAULT ] ) ? $meta[ Dynamic_Selector::META_DEFAULT ] : null ); $suffix = 'px'; if ( isset( $all_value[ $device . '-unit' ] ) ) { $suffix = $all_value[ $device . '-unit' ]; } elseif ( isset( $all_value['unit'] ) ) { $suffix = $all_value['unit']; } return $suffix; } /** * Get suffix from controls that store data in the following format: * { desktop: value, tablet: value, mobile: value, suffix : { deskop: px, tablet: px, mobile: px} } * * @param array $meta Subscribers meta data. */ public static function get_suffix_responsive( $meta, $device ) { $default_value = isset( $meta[ Dynamic_Selector::META_DEFAULT ] ) ? $meta[ Dynamic_Selector::META_DEFAULT ] : null; $all_value = isset( $meta[ Dynamic_Selector::META_AS_JSON ] ) ? Mods::to_json( $meta['key'], $default_value ) : Mods::get( $meta['key'], $default_value ); // The neve_responsive_range_control component double JSON stringified, therefore try to parse it again. if( ! is_array( $all_value ) ) { $maybe_parse_json = json_decode( $all_value , true); if( is_array( $maybe_parse_json ) ) { $all_value = $maybe_parse_json; } } return isset( $all_value['suffix'][ $device ] ) ? $all_value['suffix'][ $device ] : ( isset( $all_value['suffix'] ) && is_string( $all_value['suffix'] ) ? $all_value['suffix'] : 'px' );; } /** * Transform rule meta into CSS rule string. * * @param string $css_prop CSS Prop. * @param string|array $value Dynamic value. * @param array $meta Rule meta. * @param string $device Current device. * * @return string */ public static function transform( $css_prop, $value, $meta, $device ) { //If we have a custom filter, let's call it. if ( isset( $meta['filter'] ) ) { if ( is_callable( $meta['filter'] ) ) { return call_user_func_array( $meta['filter'], [ $css_prop, $value, $meta, $device ] ); } if ( method_exists( __CLASS__, $meta['filter'] ) ) { return call_user_func_array( [ __CLASS__, $meta['filter'] ], [ $css_prop, $value, $meta, $device ] ); } return ''; } if ( isset( $meta['override'] ) ) { return sprintf( '%s:%s;', $css_prop, $meta['override'] ); } switch ( $css_prop ) { case Config::CSS_PROP_BACKGROUND_COLOR: case Config::CSS_PROP_COLOR: case Config::CSS_PROP_FILL_COLOR: case Config::CSS_PROP_BORDER_COLOR: $mode = ( false === strpos( $value, 'rgba' ) ) ? 'hex' : 'rgba'; $is_var = ( strpos( $value, 'var' ) !== false ); if ( $mode === 'hex' && ! $is_var ) { $value = strpos( $value, "#" ) === 0 ? $value : '#' . $value; } return sprintf( "%s: %s%s;", ( $css_prop ), neve_sanitize_colors( $value ), isset( $meta['important'] ) && $meta['important'] ? '!important' : '' ); case Config::CSS_PROP_MAX_WIDTH: case Config::CSS_PROP_WIDTH: case Config::CSS_PROP_FLEX_BASIS: case Config::CSS_PROP_MARGIN_LEFT: case Config::CSS_PROP_MARGIN_RIGHT: case Config::CSS_PROP_MARGIN_TOP: case Config::CSS_PROP_MARGIN_BOTTOM: case Config::CSS_PROP_PADDING_LEFT: case Config::CSS_PROP_PADDING_RIGHT: case Config::CSS_PROP_HEIGHT: case Config::CSS_PROP_MIN_HEIGHT: case Config::CSS_PROP_LEFT: case Config::CSS_PROP_RIGHT: $suffix = isset( $meta[ Dynamic_Selector::META_SUFFIX ] ) ? $meta[ Dynamic_Selector::META_SUFFIX ] : 'px'; if ( $suffix === 'responsive_suffix' ) { $suffix = self::get_suffix_responsive( $meta, $device ); } return sprintf( "%s: %s%s;", ( $css_prop ), ( $value ), $suffix ); case Config::CSS_PROP_BORDER_RADIUS: case Config::CSS_PROP_BORDER_WIDTH: case Config::CSS_PROP_PADDING: case Config::CSS_PROP_MARGIN: $suffix = isset( $meta[ Dynamic_Selector::META_SUFFIX ] ) ? $meta[ Dynamic_Selector::META_SUFFIX ] : 'px'; if ( ! is_array( $value ) ) { return sprintf( "%s:%s%s;", $css_prop, absint( $value ), $suffix ); } if ( ! isset( $meta['is_responsive'] ) || $meta['is_responsive'] === false ) { $suffix = isset( $value['unit'] ) ? $value['unit'] : 'px'; } if ( $suffix === 'responsive_unit' ) { $suffix = self::get_unit_responsive( $meta, $device ); } $non_empty_values = array_filter( $value, 'strlen' ); // @phpstan-ignore-line if ( count( $non_empty_values ) === 4 ) { return sprintf( "%s:%s%s %s%s %s%s %s%s;", $css_prop, (int) $value['top'], $suffix, (int) $value['right'], $suffix, (int) $value['bottom'], $suffix, (int) $value['left'], $suffix ); } $rule = ''; $patterns = [ Config::CSS_PROP_MARGIN => 'margin-%s', Config::CSS_PROP_PADDING => 'padding-%s', Config::CSS_PROP_BORDER_WIDTH => 'border-%s-width', Config::CSS_PROP_BORDER_RADIUS => [ 'top' => 'border-top-left-radius', 'right' => 'border-top-right-radius', 'bottom' => 'border-bottom-right-radius', 'left' => 'border-bottom-left-radius', ], ]; if ( isset( $non_empty_values['unit'] ) ) { unset ( $non_empty_values['unit'] ); } foreach ( $non_empty_values as $position => $position_value ) { $rule .= sprintf( "%s:%s%s;", sprintf( ( is_array( $patterns[ $css_prop ] ) ? $patterns[ $css_prop ][ $position ] : $patterns[ $css_prop ] ), $position ), (int) $position_value, $suffix ); } return $rule; //Line height uses an awkward format saved, and we can't define it as responsive because we would need to use the suffix part. case Config::CSS_PROP_LINE_HEIGHT: case Config::CSS_PROP_FONT_SIZE: $suffix = isset( $meta[ Dynamic_Selector::META_SUFFIX ] ) ? $meta[ Dynamic_Selector::META_SUFFIX ] : 'em'; // We consider the provided suffix as default, in case that we have a responsive setting with responsive suffix. if ( isset( $meta[ Dynamic_Selector::META_IS_RESPONSIVE ] ) && $meta[ Dynamic_Selector::META_IS_RESPONSIVE ] ) { $all_value = Mods::get( $meta['key'] ); $suffix = isset( $all_value['suffix'][ $device ] ) ? $all_value['suffix'][ $device ] : ( isset( $all_value['suffix'] ) ? $all_value['suffix'] : $suffix ); } return sprintf( ' %s: %s%s;', $css_prop, $value, $suffix ); //Letter spacing has a legacy value of non-responsive which we need to take into consideration. case Config::CSS_PROP_LETTER_SPACING: return sprintf( ' %s: %spx;', $css_prop, $value ); case Config::CSS_PROP_CUSTOM_BTN_TYPE: if ( $value !== 'outline' ) { return 'border:none;'; } return "border:1px solid;"; case Config::CSS_PROP_FONT_WEIGHT: if ( isset( $meta['font'] ) ) { $font = strpos( $meta['font'], 'mods_' ) === 0 ? Mods::get( str_replace( 'mods_', '', $meta['font'] ) ) : $meta['font']; Font_Manager::add_google_font( $font, strval( $value ) ); } return sprintf( ' %s: %s;', $css_prop, intval( $value ) ); case Config::CSS_PROP_FONT_FAMILY: if ( $value === 'default' ) { return ''; } Font_Manager::add_google_font( $value ); return sprintf( ' %s: %s, var(--nv-fallback-ff);', $css_prop, $value ); case Config::CSS_PROP_TEXT_TRANSFORM: case Config::CSS_PROP_BOX_SHADOW: case Config::CSS_PROP_MIX_BLEND_MODE: case Config::CSS_PROP_OPACITY: case Config::CSS_PROP_GRID_TEMPLATE_COLS: return sprintf( ' %s: %s;', $css_prop, $value ); default: $is_font_family_var = strpos( strtolower( $css_prop ), 'fontfamily' ) > - 1; if ( $is_font_family_var ) { Font_Manager::add_google_font( $value ); $value = self::format_font_family_value( $value ); } if ( isset( $meta['directional-prop'] ) ) { return self::transform_directional_prop( $meta, $device, $value, $css_prop, $meta['directional-prop'] ); } $suffix = self::get_suffix( $meta, $device, $value, $css_prop ); return sprintf( ' %s: %s%s;', $css_prop, $value, $suffix ); } } /** * Get suffix for generic settings. * * @param array $meta Meta array. * @param string $device Current device. * @param mixed $value Value. * * @return string * * @since 3.0.0 */ public static function get_suffix( $meta, $device, $value, $css_prop ) { $suffix = isset( $meta[ Dynamic_Selector::META_SUFFIX ] ) ? $meta[ Dynamic_Selector::META_SUFFIX ] : ''; // If not responsive, most controls use 'unit' key inside value. if ( ! isset( $meta['is_responsive'] ) || $meta['is_responsive'] === false ) { $suffix = isset( $value['unit'] ) ? $value['unit'] : $suffix; } // If responsive, try to find the suffix. if ( isset( $meta[ Dynamic_Selector::META_IS_RESPONSIVE ] ) && $meta[ Dynamic_Selector::META_IS_RESPONSIVE ] ) { $all_value = Mods::get( $meta['key'] ); $suffix = isset( $all_value['suffix'][ $device ] ) ? $all_value['suffix'][ $device ] : ( isset( $all_value['suffix'] ) ? $all_value['suffix'] : $suffix ); } if ( $suffix === 'responsive_unit' ) { $suffix = self::get_unit_responsive( $meta, $device ); } if ( $suffix === 'responsive_suffix' ) { $suffix = self::get_suffix_responsive( $meta, $device ); } // Enqueue any google fonts we might be missing. if ( isset ( $meta['font'] ) ) { $font = strpos( $meta['font'], 'mods_' ) === 0 ? Mods::get( str_replace( 'mods_', '', $meta['font'] ) ) : $meta['font']; Font_Manager::add_google_font( $font, strval( $value ) ); } return $suffix === '—' ? '' : $suffix; } /** * Transforms the directional properties. * * @param array $meta Meta array. * @param string $device Current device. * @param array|int $value Value. * @param string $css_prop Css Property. * @param string $type Type of directional property. * * @return string */ public static function transform_directional_prop( $meta, $device, $value, $css_prop, $type ) { $suffix = self::get_suffix( $meta, $device, $value, $css_prop ); $suffix = $suffix ? $suffix : 'px'; $template = ''; // Make sure that this is directional, even if an int value is provided. if ( is_int( $value ) ) { $directions = Config::$directional_keys; $value = array_fill_keys( $directions, $value ); } // If we still don't have an array. Make sure to drop this setting. if ( ! is_array( $value ) ) { return ''; } // Directional array without any other keys than the actual directions. $filtered = array_filter( $value, function ( $key ) { return in_array( $key, Config::$directional_keys, true ); }, ARRAY_FILTER_USE_KEY ); $number_of_directions = $type === Config::CSS_PROP_DIRECTIONAL_ONE_AXIS ? 4 : count( array_unique( $filtered ) ); if ( $number_of_directions === 1 ) { if ( neve_value_is_zero( $value['top'] ) ) { $suffix = ''; } if ( empty( $value['top'] ) && ! neve_value_is_zero( $value['top'] ) ) { return ''; } $template .= $value['top'] . $suffix; return $css_prop . ':' . $template . ';'; } if ( $number_of_directions === 2 && $value['top'] === $value['bottom'] && $value['right'] === $value['left'] ) { if ( isset( $value['is_outline_button_padding'] ) ) { return $css_prop . ':' . $value['top'] . ' ' . $value['right'] . ';'; } if ( neve_value_is_zero( $value['top'] ) && neve_value_is_zero( $value['right'] ) ) { return ''; } $top_suffix = neve_value_is_zero( $value['top'] ) ? '' : $suffix; $right_suffix = neve_value_is_zero( $value['right'] ) ? '' : $suffix; $template .= $value['top'] . $top_suffix . ' ' . $value['right'] . $right_suffix; return $css_prop . ':' . $template . ';'; } foreach ( Config::$directional_keys as $direction ) { if ( isset( $value['is_outline_button_padding'] ) ) { $template .= $value[$direction] . ' '; continue; } if ( ! isset( $value[ $direction ] ) || neve_value_is_zero( $value[ $direction ] ) ) { $template .= '0 '; continue; } $template .= $value[ $direction ] . $suffix . ' '; } if ( empty( $template ) ) { return ''; } $template = trim( $template ) . ';'; return $css_prop . ':' . $template . ';'; } /** * Format the font family value. * * @param string $value the font family value. */ public static function format_font_family_value( $value ) { // At some point we were setting the DB values with quotes and removed that. // Make sure we drop the slashes and quotes. $value = str_replace( [ '"', '\\' ], '', $value ); if ( strpos( $value, ',' ) !== false ) { $value = explode( ',', $value ); $value = array_map( 'Neve\Core\Styles\CSS_Prop::quote_font_family', $value ); return join( ',', $value ); } return self::quote_font_family( $value ); } /** * Strip side spaces wrap font family in quotes. * * @param string $family the font family. * * @return string */ private static function quote_font_family( $family ) { // Make sure we don't have whitespace. $family = trim( $family ); // Remove quotes. Because of previously faulty fix. $family = trim( $family, '"' ); if ( strpos( $family, ' ' ) === false ) { return $family; } return '"' . $family . '"'; } } css_vars.php 0000666 00000031503 15226760533 0007117 0 ustar 00 <?php /** * CSS Variables trait */ namespace Neve\Core\Styles; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; use Neve\Core\Traits\Theme_Mods; /** * Trait Css_Vars * * @since 3.0.0 */ trait Css_Vars { use Theme_Mods; /** * Get container rules. * * @return array[] */ public function get_container_rules() { return [ '--container' => [ Dynamic_Selector::META_KEY => Config::MODS_CONTAINER_WIDTH, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', Dynamic_Selector::META_DEFAULT => '{ "mobile": 748, "tablet": 992, "desktop": 1170 }', ], ]; } /** * Get button rules. * * @return array */ public function get_button_rules() { $mod_key_primary = Config::MODS_BUTTON_PRIMARY_STYLE; $default_primary = neve_get_button_appearance_default(); $mod_key_secondary = Config::MODS_BUTTON_SECONDARY_STYLE; $default_secondary = neve_get_button_appearance_default( 'secondary' ); $rules = [ '--primarybtnbg' => [ Dynamic_Selector::META_KEY => $mod_key_primary . '.background', ], '--secondarybtnbg' => [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.background', ], '--primarybtnhoverbg' => [ Dynamic_Selector::META_KEY => $mod_key_primary . '.backgroundHover', ], '--secondarybtnhoverbg' => [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.backgroundHover', ], '--primarybtncolor' => [ Dynamic_Selector::META_KEY => $mod_key_primary . '.text', ], '--secondarybtncolor' => [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.text', ], '--primarybtnhovercolor' => [ Dynamic_Selector::META_KEY => $mod_key_primary . '.textHover', ], '--secondarybtnhovercolor' => [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.textHover', ], '--primarybtnborderradius' => [ Dynamic_Selector::META_KEY => $mod_key_primary . '.borderRadius', Dynamic_Selector::META_SUFFIX => 'px', 'directional-prop' => Config::CSS_PROP_BORDER_RADIUS, ], '--secondarybtnborderradius' => [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.borderRadius', Dynamic_Selector::META_SUFFIX => 'px', 'directional-prop' => Config::CSS_PROP_BORDER_RADIUS, ], ]; $primary_values = get_theme_mod( $mod_key_primary, $default_primary ); $secondary_values = get_theme_mod( $mod_key_secondary, $default_secondary ); // Button Shadow Primary if ( isset( $primary_values['useShadow'] ) && ! empty( $primary_values['useShadow'] ) ) { $rules['--primarybtnshadow'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.shadowColor', Dynamic_Selector::META_DEFAULT => 'none', Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) use ($primary_values) { $blur = intval($primary_values['shadowProperties']['blur']); $width = intval($primary_values['shadowProperties']['width']); $height = intval($primary_values['shadowProperties']['height']); return sprintf( '%s:%s;', $css_prop, sprintf('%spx %spx %spx %s;', $width, $height, $blur, $value ) ); } ]; } // Button Shadow Primary Hover if ( isset( $primary_values['useShadowHover'] ) && ! empty( $primary_values['useShadowHover'] ) ) { $rules['--primarybtnhovershadow'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.shadowColorHover', Dynamic_Selector::META_DEFAULT => 'none', Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) use ($primary_values) { $blur = intval($primary_values['shadowPropertiesHover']['blur']); $width = intval($primary_values['shadowPropertiesHover']['width']); $height = intval($primary_values['shadowPropertiesHover']['height']); return sprintf( '%s:%s;', $css_prop, sprintf('%spx %spx %spx %s;', $width, $height, $blur, $value ) ); } ]; } // Button Shadow Secondary if ( isset( $secondary_values['useShadow'] ) && ! empty( $secondary_values['useShadow'] ) ) { $rules['--secondarybtnshadow'] = [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.shadowColor', Dynamic_Selector::META_DEFAULT => 'none', Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) use ($secondary_values) { $blur = intval($secondary_values['shadowProperties']['blur']); $width = intval($secondary_values['shadowProperties']['width']); $height = intval($secondary_values['shadowProperties']['height']); return sprintf( '%s:%s;', $css_prop, sprintf('%spx %spx %spx %s;', $width, $height, $blur, $value ) ); } ]; } // Button Shadow Secondary Hover if ( isset( $secondary_values['useShadowHover'] ) && ! empty( $secondary_values['useShadowHover'] ) ) { $rules['--secondarybtnhovershadow'] = [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.shadowColorHover', Dynamic_Selector::META_DEFAULT => 'none', Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) use ($secondary_values) { $blur = intval($secondary_values['shadowPropertiesHover']['blur']); $width = intval($secondary_values['shadowPropertiesHover']['width']); $height = intval($secondary_values['shadowPropertiesHover']['height']); return sprintf( '%s:%s;', $css_prop, sprintf('%spx %spx %spx %s;', $width, $height, $blur, $value ) ); } ]; } // Border Width if ( isset( $primary_values['type'] ) && $primary_values['type'] === 'outline' ) { $rules['--primarybtnborderwidth'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.borderWidth', Dynamic_Selector::META_SUFFIX => 'px', 'directional-prop' => Config::CSS_PROP_BORDER_WIDTH, ]; } if ( isset( $secondary_values['type'] ) && $secondary_values['type'] === 'outline' ) { $rules['--secondarybtnborderwidth'] = [ Dynamic_Selector::META_KEY => $mod_key_secondary . '.borderWidth', Dynamic_Selector::META_SUFFIX => 'px', 'directional-prop' => Config::CSS_PROP_BORDER_WIDTH, ]; } $mod_key_primary = Config::MODS_BUTTON_PRIMARY_PADDING; $default_primary = Mods::get_alternative_mod_default( Config::MODS_BUTTON_PRIMARY_PADDING ); $rules['--btnpadding'] = [ Dynamic_Selector::META_KEY => $mod_key_primary, Dynamic_Selector::META_DEFAULT => $default_primary, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_unit', Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { $mod_key_primary = Config::MODS_BUTTON_PRIMARY_STYLE; $default_primary = neve_get_button_appearance_default(); $mod_key_secondary = Config::MODS_BUTTON_SECONDARY_STYLE; $default_secondary = neve_get_button_appearance_default( 'secondary' ); $values = [ 'primary' => get_theme_mod( $mod_key_primary, $default_primary ), 'secondary' => get_theme_mod( $mod_key_secondary, $default_secondary ), ]; $paddings = [ 'primary' => $value, 'secondary' => $value, ]; foreach ( $values as $btn_type => $appearance_values ) { if ( ! isset( $appearance_values['type'] ) || $appearance_values['type'] !== 'outline' ) { continue; } $border_width = $appearance_values['borderWidth']; foreach ( $paddings[ $btn_type ] as $direction => $padding_value ) { if ( ! isset( $border_width[ $direction ] ) || absint( $border_width[ $direction ] ) === 0 ) { continue; } if( ! is_numeric( $padding_value ) ){ continue; } $suffix_css_prop = $btn_type === 'primary' ? '--primarybtnpadding' : '--secondarybtnpadding'; $suffix = Css_Prop::get_suffix( $meta, $device, $value, $suffix_css_prop ); $paddings[ $btn_type ][ 'is_outline_button_padding' ] = true; $paddings[ $btn_type ][ $direction ] = 'calc(' . $padding_value . $suffix . ' - ' . $border_width[ $direction ] . 'px)'; } } $final_value_default = Css_Prop::transform_directional_prop( $meta, $device, $value, '--btnpadding', Config::CSS_PROP_PADDING ); $final_value_primary = Css_Prop::transform_directional_prop( $meta, $device, $paddings['primary'], '--primarybtnpadding', Config::CSS_PROP_PADDING ); $final_value_secondary = Css_Prop::transform_directional_prop( $meta, $device, $paddings['secondary'], '--secondarybtnpadding', Config::CSS_PROP_PADDING ); return $final_value_default . $final_value_primary . $final_value_secondary; }, 'directional-prop' => Config::CSS_PROP_PADDING, ]; $mod_key_primary = Config::MODS_BUTTON_TYPEFACE; $rules['--btnfs'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.fontSize', Dynamic_Selector::META_IS_RESPONSIVE => true, ]; $rules['--btnlineheight'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.lineHeight', Dynamic_Selector::META_IS_RESPONSIVE => true, ]; $rules['--btnletterspacing'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.letterSpacing', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ]; $rules['--btntexttransform'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.textTransform', Dynamic_Selector::META_IS_RESPONSIVE => false, ]; $rules['--btnfontweight'] = [ Dynamic_Selector::META_KEY => $mod_key_primary . '.fontWeight', ]; return $rules; } /** * Get the common typography rules * * @retun array */ public function get_typography_rules() { $default = Mods::get_alternative_mod_default( Config::MODS_TYPEFACE_GENERAL ); $mod_key = Config::MODS_TYPEFACE_GENERAL; $rules = [ '--bodyfontfamily' => [ Dynamic_Selector::META_KEY => Config::MODS_FONT_GENERAL, Dynamic_Selector::META_DEFAULT => Mods::get_alternative_mod_default( Config::MODS_FONT_GENERAL ), ], '--bodyfontsize' => [ Dynamic_Selector::META_KEY => $mod_key . '.fontSize', Dynamic_Selector::META_DEFAULT => $default['fontSize'], Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ], '--bodylineheight' => [ Dynamic_Selector::META_KEY => $mod_key . '.lineHeight', Dynamic_Selector::META_DEFAULT => $default['lineHeight'], Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => '', ], '--bodyletterspacing' => [ Dynamic_Selector::META_KEY => $mod_key . '.letterSpacing', Dynamic_Selector::META_DEFAULT => $default['letterSpacing'], Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ], '--bodyfontweight' => [ Dynamic_Selector::META_KEY => $mod_key . '.fontWeight', Dynamic_Selector::META_DEFAULT => $default['fontWeight'], 'font' => 'mods_' . Config::MODS_FONT_HEADINGS, ], '--bodytexttransform' => [ Dynamic_Selector::META_KEY => $mod_key . '.textTransform', ], '--headingsfontfamily' => [ Dynamic_Selector::META_KEY => Config::MODS_FONT_HEADINGS, ], ]; foreach ( neve_get_headings_selectors() as $id => $heading_selector ) { $composed_key = sprintf( 'neve_%s_typeface_general', $id ); $mod_key = $composed_key; $default = Mods::get_alternative_mod_default( $composed_key ); $rules[ '--' . $id . 'fontfamily' ] = [ Dynamic_Selector::META_KEY => $this->get_mod_key_heading_fontfamily( $id ) ]; $rules[ '--' . $id . 'fontsize' ] = [ Dynamic_Selector::META_KEY => $mod_key . '.fontSize', Dynamic_Selector::META_DEFAULT => $default['fontSize'], Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ]; $rules[ '--' . $id . 'fontweight' ] = [ Dynamic_Selector::META_KEY => $mod_key . '.fontWeight', Dynamic_Selector::META_DEFAULT => $default['fontWeight'], 'font' => 'mods_' . Config::MODS_FONT_HEADINGS, ]; $rules[ '--' . $id . 'lineheight' ] = [ Dynamic_Selector::META_KEY => $mod_key . '.lineHeight', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => $default['lineHeight'], Dynamic_Selector::META_SUFFIX => '', ]; $rules[ '--' . $id . 'letterspacing' ] = [ Dynamic_Selector::META_KEY => $mod_key . '.letterSpacing', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => $default['letterSpacing'], Dynamic_Selector::META_SUFFIX => 'px', ]; $rules[ '--' . $id . 'texttransform' ] = [ Dynamic_Selector::META_KEY => $mod_key . '.textTransform', Dynamic_Selector::META_DEFAULT => $default['textTransform'], ]; } return $rules; } } generator.php 0000666 00000003671 15226760533 0007267 0 ustar 00 <?php /** * Style generator based on settings. * * @package Neve\Core\Styles */ namespace Neve\Core\Styles; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; /** * Class Generator * * @package Neve\Core\Styles */ class Generator { /** * Subscriber list used for CSS generation. * * @var array Subscriber list. */ protected $_subscribers = []; const SUBSCRIBER_TYPE = 'type'; const SUBSCRIBER_MAP = 'map'; const SUBSCRIBER_KEY = 'key'; const SUBSCRIBER_DEFAULTS = 'defaults'; /** * Current context. * * @var string|null */ protected $context = null; /** * Generate the dynamic CSS. * * @param bool $echo Should we write it or return it. * * @return string|void Css output. */ public function generate( $echo = false ) { $desktop_css = ''; $tablet_css = ''; $all_css = ''; if ( $this->context === null ) { $this->context = Dynamic_Selector::CONTEXT_FRONTEND; } /** * Neve try to build the CSS as mobile first. * Based on this fact, the general CSS is considered the mobile one. */ $dynamic_selectors = new Dynamic_Selector( $this->_subscribers, $this->context ); $all_css .= $dynamic_selectors->for_mobile(); $tablet_css .= $dynamic_selectors->for_tablet(); $desktop_css .= $dynamic_selectors->for_desktop(); if ( ! empty( $tablet_css ) ) { $all_css .= sprintf( '@media(min-width: 576px){ %s }', $tablet_css ); } if ( ! empty( $desktop_css ) ) { $all_css .= sprintf( '@media(min-width: 960px){ %s }', $desktop_css ); } if ( ! $echo ) { return $all_css; } echo $all_css; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Set new subscribers. * * @param array $subscribers New generator list. */ public function set( $subscribers ) { $this->_subscribers = $subscribers; } /** * Return current subscribers. * * @return array */ public function get() { return $this->_subscribers; } } frontend.php 0000666 00000107431 15226760533 0007117 0 ustar 00 <?php /** * Style generator based on settings. * * @package Neve\Core\Styles */ namespace Neve\Core\Styles; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; use Neve\Customizer\Defaults\Layout; use Neve\Customizer\Defaults\Single_Post; /** * Class Generator for Frontend. * * @package Neve\Core\Styles */ class Frontend extends Generator { use Css_Vars; use Single_Post; use Layout; /** * Box shadow map values * * @var string[] */ private $box_shadow_map = [ 1 => '0 1px 3px -2px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.1)', 2 => '0 3px 6px -5px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.1)', 3 => '0 10px 20px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.1)', 4 => '0 14px 28px rgba(0, 0, 0, 0.12), 0 10px 10px rgba(0, 0, 0, 0.12)', 5 => '0 16px 38px -12px rgba(0,0,0,0.56), 0 4px 25px 0 rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.2)', ]; /** * Generator constructor. */ public function __construct() { $this->_subscribers = []; $this->setup_container(); $this->setup_blog_layout(); $this->setup_legacy_gutenberg_palette(); $this->setup_layout_subscribers(); $this->setup_buttons(); $this->setup_typography(); $this->setup_blog_meta(); $this->setup_blog_typography(); $this->setup_blog_colors(); $this->setup_form_fields_style(); $this->setup_header_style(); $this->setup_single_post_style(); $this->setup_content_vspacing(); } /** * Setup the container styles. * * @return void */ private function setup_container() { $this->_subscribers[] = [ Dynamic_Selector::KEY_SELECTOR => ':root', Dynamic_Selector::KEY_RULES => $this->get_container_rules(), ]; } /** * Setup legacy gutenberg palette for old users. */ private function setup_legacy_gutenberg_palette() { $is_new_user = get_option( 'neve_new_user' ); $imported_starter_site = get_option( 'neve_imported_demo' ); if ( $is_new_user === 'yes' && $imported_starter_site !== 'yes' ) { return; } $this->_subscribers['.has-neve-button-color-color'] = [ Config::CSS_PROP_COLOR => [ Dynamic_Selector::META_KEY => Config::MODS_BUTTON_PRIMARY_STYLE . '.background', Dynamic_Selector::META_IMPORTANT => true, Dynamic_Selector::META_DEFAULT => '#0366d6', ], ]; $this->_subscribers['.has-neve-button-color-background-color'] = [ Config::CSS_PROP_BACKGROUND_COLOR => [ Dynamic_Selector::META_KEY => Config::MODS_BUTTON_PRIMARY_STYLE . '.background', Dynamic_Selector::META_IMPORTANT => true, Dynamic_Selector::META_DEFAULT => '#0366d6', ], ]; } /** * Add css for blog colors. */ public function setup_blog_colors() { $layout = get_theme_mod( 'neve_blog_archive_layout', 'grid' ); if ( $layout === 'covers' ) { $this->_subscribers['.neve-main'] = [ '--color' => 'neve_blog_covers_text_color', ]; } $thumbnail_box_shadow_meta_name = apply_filters( 'neve_thumbnail_box_shadow_meta_filter', 'neve_post_thumbnail_box_shadow' ); $this->_subscribers['.neve-main']['--boxshadow'] = [ Dynamic_Selector::META_KEY => $thumbnail_box_shadow_meta_name, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { if ( absint( $value ) === 0 ) { return ''; } if ( ! array_key_exists( absint( $value ), $this->box_shadow_map ) ) { return ''; } return sprintf( '%s:%s;', $css_prop, $this->box_shadow_map[ $value ] ); }, ]; } /** * Add css for blog typography. */ public function setup_blog_typography() { $archive_typography = [ Config::CSS_SELECTOR_ARCHIVE_POST_TITLE => [ 'mod' => Config::MODS_TYPEFACE_ARCHIVE_POST_TITLE, 'font' => Config::MODS_FONT_HEADINGS, ], Config::CSS_SELECTOR_ARCHIVE_POST_EXCERPT => [ 'mod' => Config::MODS_TYPEFACE_ARCHIVE_POST_EXCERPT, 'font' => Config::MODS_FONT_GENERAL, ], Config::CSS_SELECTOR_ARCHIVE_POST_META => [ 'mod' => Config::MODS_TYPEFACE_ARCHIVE_POST_META, 'font' => Config::MODS_FONT_GENERAL, ], Config::CSS_SELECTOR_SINGLE_POST_TITLE => [ 'mod' => Config::MODS_TYPEFACE_SINGLE_POST_TITLE, 'font' => Config::MODS_FONT_HEADINGS, ], Config::CSS_SELECTOR_SINGLE_POST_META => [ 'mod' => Config::MODS_TYPEFACE_SINGLE_POST_META, 'font' => Config::MODS_FONT_GENERAL, ], Config::CSS_SELECTOR_SINGLE_POST_COMMENT_TITLE => [ 'mod' => Config::MODS_TYPEFACE_SINGLE_POST_COMMENT_TITLE, 'font' => Config::MODS_FONT_HEADINGS, ], ]; foreach ( $archive_typography as $selector => $args ) { $this->_subscribers[ $selector ] = [ '--fontsize' => [ Dynamic_Selector::META_KEY => $args['mod'] . '.fontSize', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ], '--lineheight' => [ Dynamic_Selector::META_KEY => $args['mod'] . '.lineHeight', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => '', ], '--letterspacing' => [ Dynamic_Selector::META_KEY => $args['mod'] . '.letterSpacing', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ], '--fontweight' => [ Dynamic_Selector::META_KEY => $args['mod'] . '.fontWeight', 'font' => 'mods_' . $args['font'], ], '--texttransform' => $args['mod'] . '.textTransform', ]; } } /** * Add css for blog layout. * * Removed grid in new skin CSS so this should handle the grid. * * @return bool|void * @since 3.0.0 */ public function setup_blog_layout() { $this->_subscribers[':root'] = [ '--postwidth' => [ Dynamic_Selector::META_KEY => 'neve_grid_layout', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => $this->grid_columns_default(), Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { $blog_layout = get_theme_mod( 'neve_blog_archive_layout', 'grid' ); if ( ! in_array( $blog_layout, [ 'grid', 'covers' ], true ) ) { return sprintf( '%s:%s;', $css_prop, '100%' ); } if ( $value < 1 ) { $value = 1; } return sprintf( '%s:%s;', $css_prop, 100 / $value . '%' ); }, ], ]; } /** * Setup typography subscribers. */ public function setup_typography() { $rules = $this->get_typography_rules(); $this->_subscribers[] = [ Dynamic_Selector::KEY_SELECTOR => ':root', Dynamic_Selector::KEY_RULES => $rules, ]; } /** * Setup button subscribers. */ public function setup_buttons() { $rules = $this->get_button_rules(); $this->_subscribers[] = [ Dynamic_Selector::KEY_SELECTOR => ':root', Dynamic_Selector::KEY_RULES => $rules, ]; } /** * Setup settings subscribers for layout. * * TODO: Exclude sidebar CSS when there is not sidebar option selected. * TODO: Better exclude classes when Woo is not present, i.e shop-sidebar class is added even when Woo is not used. */ public function setup_layout_subscribers() { $is_advanced_on = Mods::get( Config::MODS_ADVANCED_LAYOUT_OPTIONS, true ); if ( ! $is_advanced_on ) { $this->_subscribers['#content .container .col, #content .container-fluid .col'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SITEWIDE_CONTENT_WIDTH, Dynamic_Selector::META_SUFFIX => '%', Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, ], ]; $this->_subscribers['.alignfull > [class*="__inner-container"], .alignwide > [class*="__inner-container"]'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SITEWIDE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => 70, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { $width = Mods::to_json( Config::MODS_CONTAINER_WIDTH ); if ( $device === Dynamic_Selector::DESKTOP ) { return sprintf( 'max-width:%spx', round( ( $value / 100 ) * $width[ $device ] - Config::CONTENT_DEFAULT_PADDING ) ); } if ( $device === Dynamic_Selector::MOBILE ) { return sprintf( 'max-width:%spx;margin:auto', ( $width[ $device ] - Config::CONTENT_DEFAULT_PADDING ) ); } return ''; }, ], ]; $this->_subscribers['.container-fluid .alignfull > [class*="__inner-container"], .container-fluid .alignwide > [class*="__inner-container"]'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SITEWIDE_CONTENT_WIDTH, Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { return sprintf( 'max-width:calc(%s%% + %spx)', $value, Config::CONTENT_DEFAULT_PADDING / 2 ); }, ], ]; $this->_subscribers['.nv-sidebar-wrap, .nv-sidebar-wrap.shop-sidebar'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SITEWIDE_CONTENT_WIDTH, Dynamic_Selector::META_FILTER => 'minus_100', Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_SUFFIX => '%', ], ]; return; } // Others content width. $this->_subscribers['body:not(.single):not(.archive):not(.blog):not(.search):not(.error404) .neve-main > .container .col, body.post-type-archive-course .neve-main > .container .col, body.post-type-archive-llms_membership .neve-main > .container .col'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_OTHERS_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_OTHERS_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_SUFFIX => '%', ], ]; $this->_subscribers['body:not(.single):not(.archive):not(.blog):not(.search):not(.error404) .nv-sidebar-wrap, body.post-type-archive-course .nv-sidebar-wrap, body.post-type-archive-llms_membership .nv-sidebar-wrap'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_OTHERS_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_OTHERS_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => 'minus_100', Dynamic_Selector::META_SUFFIX => '%', ], ]; // Archive content width. $this->_subscribers['.neve-main > .archive-container .nv-index-posts.col'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_ARCHIVE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_ARCHIVE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_SUFFIX => '%', ], ]; $this->_subscribers['.neve-main > .archive-container .nv-sidebar-wrap'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_ARCHIVE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_ARCHIVE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => 'minus_100', Dynamic_Selector::META_SUFFIX => '%', ], ]; // Single content width. list( $context, $allowed_context ) = $this->get_cpt_context( [ 'post' ] ); $sidebar_content_width_meta = $this->get_sidebar_content_width_meta( $context, $allowed_context ); $sidebar_layout_width_default = $this->sidebar_layout_width_default( $sidebar_content_width_meta ); $this->_subscribers['.neve-main > .single-post-container .nv-single-post-wrap.col'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => $sidebar_content_width_meta, Dynamic_Selector::META_DEFAULT => $sidebar_layout_width_default, Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_SUFFIX => '%', ], ]; $this->_subscribers['.single-post-container .alignfull > [class*="__inner-container"], .single-post-container .alignwide > [class*="__inner-container"]'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => $sidebar_content_width_meta, Dynamic_Selector::META_DEFAULT => $sidebar_layout_width_default, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { $width = Mods::to_json( Config::MODS_CONTAINER_WIDTH ); $value = $device !== Dynamic_Selector::DESKTOP ? ( $width[ $device ] - Config::CONTENT_DEFAULT_PADDING ) : round( ( $value / 100 ) * $width[ $device ] - Config::CONTENT_DEFAULT_PADDING ); return sprintf( 'max-width:%spx', $value ); }, ], ]; $this->_subscribers['.container-fluid.single-post-container .alignfull > [class*="__inner-container"], .container-fluid.single-post-container .alignwide > [class*="__inner-container"]'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => $sidebar_content_width_meta, Dynamic_Selector::META_DEFAULT => $sidebar_layout_width_default, Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { return sprintf( 'max-width:calc(%s%% + %spx)', $value, Config::CONTENT_DEFAULT_PADDING / 2 ); }, ], ]; $this->_subscribers['.neve-main > .single-post-container .nv-sidebar-wrap'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => $sidebar_content_width_meta, Dynamic_Selector::META_DEFAULT => $sidebar_layout_width_default, Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => 'minus_100', Dynamic_Selector::META_SUFFIX => '%', ], ]; // TODO provide context handler for better checks. if ( ! class_exists( 'WooCommerce', false ) ) { return; } $this->_subscribers['.archive.woocommerce .neve-main > .shop-container .nv-shop.col'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SHOP_ARCHIVE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_SHOP_ARCHIVE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_SUFFIX => '%', ], ]; $this->_subscribers['.archive.woocommerce .neve-main > .shop-container .nv-sidebar-wrap'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SHOP_ARCHIVE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_SHOP_ARCHIVE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => 'minus_100', Dynamic_Selector::META_SUFFIX => '%', ], ]; $this->_subscribers['.single-product .neve-main > .shop-container .nv-shop.col'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SHOP_SINGLE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_SHOP_SINGLE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_SUFFIX => '%', ], ]; $this->_subscribers['.single-product .alignfull > [class*="__inner-container"], .single-product .alignwide > [class*="__inner-container"]'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SHOP_SINGLE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_SHOP_SINGLE_CONTENT_WIDTH ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { $width = Mods::to_json( Config::MODS_CONTAINER_WIDTH ); $value = $device !== Dynamic_Selector::DESKTOP ? ( $width[ $device ] - Config::CONTENT_DEFAULT_PADDING ) : round( ( $value / 100 ) * $width[ $device ] - Config::CONTENT_DEFAULT_PADDING ); return sprintf( 'max-width:%spx', $value ); }, ], ]; $this->_subscribers['.single-product .container-fluid .alignfull > [class*="__inner-container"], .single-product .alignwide > [class*="__inner-container"]'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SHOP_SINGLE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_SHOP_SINGLE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) { return sprintf( 'max-width:calc(%s%% + %spx)', $value, Config::CONTENT_DEFAULT_PADDING / 2 ); }, ], ]; $this->_subscribers['.single-product .neve-main > .shop-container .nv-sidebar-wrap'] = [ Config::CSS_PROP_MAX_WIDTH => [ Dynamic_Selector::META_KEY => Config::MODS_SHOP_SINGLE_CONTENT_WIDTH, Dynamic_Selector::META_DEFAULT => $this->sidebar_layout_width_default( Config::MODS_SHOP_SINGLE_CONTENT_WIDTH ), Dynamic_Selector::META_DEVICE_ONLY => Dynamic_Selector::DESKTOP, Dynamic_Selector::META_FILTER => 'minus_100', Dynamic_Selector::META_SUFFIX => '%', ], ]; } /** * Adds form field styles */ private function setup_form_fields_style() { $border_width_default = array_fill_keys( Config::$directional_keys, '2' ); $border_radius_default = array_fill_keys( Config::$directional_keys, '3' ); $this->_subscribers[] = [ Dynamic_Selector::KEY_SELECTOR => ':root', Dynamic_Selector::KEY_RULES => [ '--formfieldborderwidth' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_BORDER_WIDTH, Dynamic_Selector::META_SUFFIX => 'px', Dynamic_Selector::META_DEFAULT => $border_width_default, 'directional-prop' => Config::CSS_PROP_BORDER_WIDTH, ], '--formfieldborderradius' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_BORDER_RADIUS, Dynamic_Selector::META_SUFFIX => 'px', Dynamic_Selector::META_DEFAULT => $border_radius_default, 'directional-prop' => Config::CSS_PROP_BORDER_RADIUS, ], '--formfieldbgcolor' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_BACKGROUND_COLOR, Dynamic_Selector::META_DEFAULT => 'var(--nv-site-bg)', ], '--formfieldbordercolor' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_BORDER_COLOR, Dynamic_Selector::META_DEFAULT => '#dddddd', ], '--formfieldcolor' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_COLOR, Dynamic_Selector::META_DEFAULT => 'var(--nv-text-color)', ], '--formfieldpadding' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_PADDING, Dynamic_Selector::META_DEFAULT => Mods::get_alternative_mod_default( Config::MODS_FORM_FIELDS_PADDING ), Dynamic_Selector::META_SUFFIX => 'px', Dynamic_Selector::META_IS_RESPONSIVE => false, 'directional-prop' => Config::CSS_PROP_PADDING, ], '--formfieldtexttransform' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_TYPEFACE . '.textTransform', Dynamic_Selector::META_IS_RESPONSIVE => false, ], '--formfieldfontsize' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_TYPEFACE . '.fontSize', Dynamic_Selector::META_SUFFIX => 'px', Dynamic_Selector::META_IS_RESPONSIVE => true, ], '--formfieldlineheight' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_TYPEFACE . '.lineHeight', Dynamic_Selector::META_SUFFIX => '', Dynamic_Selector::META_IS_RESPONSIVE => true, ], '--formfieldletterspacing' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_TYPEFACE . '.letterSpacing', Dynamic_Selector::META_SUFFIX => 'px', Dynamic_Selector::META_IS_RESPONSIVE => true, ], '--formfieldfontweight' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_TYPEFACE . '.fontWeight', ], // Form Labels '--formlabelfontsize' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_LABELS_TYPEFACE . '.fontSize', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'px', ], '--formlabellineheight' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_LABELS_TYPEFACE . '.lineHeight', Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => '', ], '--formlabelletterspacing' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_LABELS_TYPEFACE . '.letterSpacing', Dynamic_Selector::META_IS_RESPONSIVE => true, ], '--formlabelfontweight' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_LABELS_TYPEFACE . '.fontWeight', ], '--formlabeltexttransform' => [ Dynamic_Selector::META_KEY => Config::MODS_FORM_FIELDS_LABELS_TYPEFACE . '.textTransform', ], ], ]; // Form button style. Override if needed. $form_buttons_type = get_theme_mod( 'neve_form_button_type', 'primary' ); if ( $form_buttons_type === 'primary' ) { return; } $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON ]['background-color'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnbg, transparent)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON ]['color'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtncolor)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON ]['padding'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnpadding, 7px 12px)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON ]['border-radius'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnborderradius, 3px)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON_HOVER ]['background-color'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnhoverbg, transparent)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON_HOVER ]['color'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnhovercolor)', ]; $mod_key_secondary = Config::MODS_BUTTON_SECONDARY_STYLE; $default_secondary = Mods::get_alternative_mod_default( Config::MODS_BUTTON_SECONDARY_STYLE ); $secondary_values = get_theme_mod( $mod_key_secondary, $default_secondary ); if ( ! isset( $secondary_values['type'] ) || $secondary_values['type'] !== 'outline' ) { return; } $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON ]['border-width'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnborderwidth, 3px)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON ]['border-color'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnhovercolor)', ]; $this->_subscribers[ Config::CSS_SELECTOR_FORM_BUTTON_HOVER ]['border-color'] = [ 'key' => 'neve_form_button_type', 'override' => 'var(--secondarybtnhovercolor)', ]; } /** * Add form buttons selectors to the Buttons selector. * * @param string $selector the CSS selector received from the filter. * * @return string */ public function add_form_buttons( $selector ) { return ( $selector . ', form input[type="submit"], form button[type="submit"]' ); } /** * Add form buttons hover selectors to the Buttons selector. * * @param string $selector the CSS selector received from the filter. * * @return string */ public function add_form_buttons_hover( $selector ) { return ( $selector . ', form input[type="submit"]:hover, form button[type="submit"]:hover' ); } /** * Add css for blog meta. */ public function setup_blog_meta() { list( $context, $allowed_context ) = $this->get_cpt_context(); $archive_avatar_size_meta_key = Config::MODS_ARCHIVE_POST_META_AUTHOR_AVATAR_SIZE; $single_avatar_size_meta_key = Config::MODS_SINGLE_POST_META_AUTHOR_AVATAR_SIZE; if ( in_array( $context, $allowed_context, true ) && is_singular( $context ) || is_post_type_archive( $context ) ) { $archive_avatar_size_meta_key = 'neve_' . $context . '_archive_author_avatar_size'; $single_avatar_size_meta_key = 'neve_single_' . $context . '_avatar_size'; } $rules = [ '--avatarsize' => [ Dynamic_Selector::META_KEY => $archive_avatar_size_meta_key, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_suffix', Dynamic_Selector::META_DEFAULT => '{ "mobile": 20, "tablet": 20, "desktop": 20 }', ], ]; $rules_single = [ '--avatarsize' => [ Dynamic_Selector::META_KEY => $single_avatar_size_meta_key, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_suffix', Dynamic_Selector::META_DEFAULT => Mods::get( 'neve_author_avatar_size', '{ "mobile": 20, "tablet": 20, "desktop": 20 }' ), ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-meta-list', 'rules' => $rules, ]; $this->_subscribers[] = [ 'selectors' => '.single .nv-meta-list', 'rules' => $rules_single, ]; } /** * Add css for single post. */ private function setup_single_post_style() { $boxed_comments_rules = [ '--padding' => [ Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_PADDING, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => $this->padding_default(), 'directional-prop' => Config::CSS_PROP_PADDING, ], '--bgcolor' => [ Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_BACKGROUND_COLOR, ], '--color' => [ Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_TEXT_COLOR, ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-is-boxed.nv-comments-wrap', 'rules' => $boxed_comments_rules, ]; $boxed_comment_form_rules = [ '--padding' => [ Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_FORM_PADDING, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_unit', Dynamic_Selector::META_DEFAULT => $this->padding_default(), 'directional-prop' => Config::CSS_PROP_PADDING, ], '--bgcolor' => [ Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_FORM_BACKGROUND_COLOR, ], '--color' => [ Dynamic_Selector::META_KEY => Config::MODS_POST_COMMENTS_FORM_TEXT_COLOR, ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-is-boxed.comment-respond', 'rules' => $boxed_comment_form_rules, ]; $spacing_rules = [ '--spacing' => [ Dynamic_Selector::META_KEY => Config::MODS_SINGLE_POST_ELEMENTS_SPACING, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_suffix', ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-single-post-wrap', 'rules' => $spacing_rules, ]; } /** * Check that all mods passed can be used for the provided context. * We use this to check if we can register subscribers for the provided mods. * * @since 3.1.0 * * @param string[] $mods A list of mods. * @param string $context A context for the mods. * @param array $allowed_context A list of allowed contexts to be passed on. * * @return int */ private function can_use_mods( $mods, $context, $allowed_context ) { return array_reduce( $mods, function ( $carry, $item ) use ( $context, $allowed_context ) { if ( empty( $this->get_cover_meta( $context, $item, $allowed_context ) ) ) { return 0; } return $carry; }, 1 ); } /** * Add css for post/page header. */ private function setup_header_style() { list( $context, $allowed_context ) = $this->get_cpt_context(); $justify_map = [ 'left' => 'flex-start', 'center' => 'center', 'right' => 'flex-end', ]; $can_use_cover_rules = $this->can_use_mods( [ Config::MODS_COVER_HEIGHT, Config::MODS_COVER_PADDING, Config::MODS_COVER_TITLE_ALIGNMENT, Config::MODS_COVER_TITLE_POSITION, ], $context, $allowed_context ); if ( $can_use_cover_rules ) { $cover_rules = [ '--height' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_HEIGHT, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_AS_JSON => true, Dynamic_Selector::META_SUFFIX => 'responsive_suffix', Dynamic_Selector::META_DEFAULT => '{ "mobile": "250", "tablet": "320", "desktop": "400" }', ], '--padding' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_PADDING, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => $this->padding_default( 'cover' ), Dynamic_Selector::META_SUFFIX => 'responsive_unit', 'directional-prop' => Config::CSS_PROP_PADDING, ], '--justify' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_TITLE_ALIGNMENT, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => self::post_title_alignment(), Dynamic_Selector::META_FILTER => function ( $css_prop, $value, $meta, $device ) use ( $justify_map ) { return sprintf( '%s: %s;', $css_prop, $justify_map[ $value ] ); }, ], '--textalign' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_TITLE_ALIGNMENT, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => self::post_title_alignment(), ], '--valign' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_TITLE_POSITION, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => [ 'mobile' => 'center', 'tablet' => 'center', 'desktop' => 'center', ], ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-post-cover', 'rules' => $cover_rules, ]; } $can_use_title_rules = $this->can_use_mods( [ Config::MODS_COVER_TEXT_COLOR, Config::MODS_COVER_TITLE_ALIGNMENT ], $context, $allowed_context ); if ( $can_use_title_rules ) { $title_rules = [ '--color' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_TEXT_COLOR, $allowed_context ), ], '--textalign' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_TITLE_ALIGNMENT, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => self::post_title_alignment(), ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-post-cover .nv-title-meta-wrap, .nv-page-title-wrap, .entry-header', 'rules' => $title_rules, ]; } $can_use_boxed_title_rules = $this->can_use_mods( [ Config::MODS_COVER_BOXED_TITLE_PADDING, Config::MODS_COVER_BOXED_TITLE_BACKGROUND ], $context, $allowed_context ); if ( $can_use_boxed_title_rules ) { $boxed_title_rules = [ '--padding' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_BOXED_TITLE_PADDING, $allowed_context ), Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_DEFAULT => $this->padding_default( 'cover' ), Dynamic_Selector::META_SUFFIX => 'responsive_unit', 'directional-prop' => Config::CSS_PROP_PADDING, ], '--bgcolor' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_BOXED_TITLE_BACKGROUND, $allowed_context ), Dynamic_Selector::META_DEFAULT => 'var(--nv-dark-bg)', ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-is-boxed.nv-title-meta-wrap', 'rules' => $boxed_title_rules, ]; } $can_use_overlay_rules = $this->can_use_mods( [ Config::MODS_COVER_BACKGROUND_COLOR, Config::MODS_COVER_OVERLAY_OPACITY, Config::MODS_COVER_BLEND_MODE ], $context, $allowed_context ); if ( $can_use_overlay_rules ) { $overlay_rules = [ '--bgcolor' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_BACKGROUND_COLOR, $allowed_context ), ], '--opacity' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_OVERLAY_OPACITY, $allowed_context ), Dynamic_Selector::META_DEFAULT => 50, ], '--blendmode' => [ Dynamic_Selector::META_KEY => $this->get_cover_meta( $context, Config::MODS_COVER_BLEND_MODE, $allowed_context ), Dynamic_Selector::META_DEFAULT => 'normal', ], ]; $this->_subscribers[] = [ 'selectors' => '.nv-overlay', 'rules' => $overlay_rules, ]; } } /** * Add content vertical spacing rules. */ private function setup_content_vspacing() { $rules = [ '--c-vspace' => [ Dynamic_Selector::META_KEY => Config::MODS_CONTENT_VSPACING, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_unit', Dynamic_Selector::META_DEFAULT => $this->content_vspacing_default(), Dynamic_Selector::META_DIRECTIONAL_PROP => Config::CSS_PROP_DIRECTIONAL_ONE_AXIS, ], ]; $this->_subscribers[] = [ 'selectors' => '.single:not(.single-product), .page', 'rules' => $rules, ]; $post_inherits_vspace = Mods::get( Config::MODS_SINGLE_POST_VSPACING_INHERIT, 'inherit' ) === 'inherit'; if ( ! $post_inherits_vspace ) { $default = Mods::get( Config::MODS_CONTENT_VSPACING, $this->content_vspacing_default() ); $post_rules = [ '--c-vspace' => [ Dynamic_Selector::META_KEY => Config::MODS_SINGLE_POST_CONTENT_VSPACING, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_unit', Dynamic_Selector::META_DEFAULT => $default, Dynamic_Selector::META_DIRECTIONAL_PROP => Config::CSS_PROP_DIRECTIONAL_ONE_AXIS, ], ]; $this->_subscribers[] = [ 'selectors' => '.single:not(.single-product) .neve-main', 'rules' => $post_rules, ]; } list( $context ) = $this->get_cpt_context(); $post_inherits_vspace = Mods::get( 'neve_' . $context . '_' . Config::MODS_POST_TYPE_VSPACING_INHERIT, 'inherit' ) === 'inherit'; if ( ! $post_inherits_vspace ) { $rules = [ '--c-vspace' => [ Dynamic_Selector::META_KEY => 'neve_' . $context . '_' . Config::MODS_POST_TYPE_VSPACING, Dynamic_Selector::META_IS_RESPONSIVE => true, Dynamic_Selector::META_SUFFIX => 'responsive_unit', Dynamic_Selector::META_DEFAULT => $this->content_vspacing_default(), 'directional-prop' => Config::CSS_PROP_DIRECTIONAL_ONE_AXIS, ], ]; $selectors = $context === 'page' ? '.' . $context : '.single-' . $context; $this->_subscribers[] = [ 'selectors' => $selectors . ' .neve-main', 'rules' => $rules, ]; } } } dynamic_selector.php 0000666 00000014114 15226760533 0010617 0 ustar 00 <?php /** * Dynamic selector. * * @package Neve\Core\Styles */ namespace Neve\Core\Styles; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; /** * Class Dynamic_Selector * * @package Neve\Core\Styles */ class Dynamic_Selector { const MOBILE = 'mobile'; const TABLET = 'tablet'; const DESKTOP = 'desktop'; const META_IS_RESPONSIVE = 'is_responsive'; const META_SUFFIX = 'suffix'; const META_KEY = 'key'; const META_IMPORTANT = 'important'; const META_DEFAULT = 'default'; const META_DIRECTIONAL_PROP = 'directional-prop'; const META_DEVICE_ONLY = 'device_only'; const META_FILTER = 'filter'; const META_AS_JSON = 'as_json'; const KEY_SELECTOR = 'selectors'; const KEY_RULES = 'rules'; const KEY_CONTEXT = 'context'; const CONTEXT_FRONTEND = 'frontend'; const CONTEXT_GUTENBERG = 'gutenberg'; /** * Holds CSS selector mapping. * * @var array Selector mapping. */ private $mapping = []; /** * Current device. * * @var string Current device. */ protected $device = null; /** * Used to flag the shorthand tag to css selector transformations. * * @var bool Flag shorthand transformation. */ private $is_transformed = false; /** * Holds current context. * * @var string Current context. */ private $current_context = null; /** * Dynamic_Selector constructor. * * @param array $mapping CSS selector mapping. */ public function __construct( $mapping, $context = null ) { $this->current_context = $context; $this->mapping = $mapping; } /** * Mark the subscriber for Mobile. * * @return $this */ public function for_mobile() { $this->device = self::MOBILE; return $this; } /** * Mark the subscriber for tablet. * * @return $this */ public function for_tablet() { $this->device = self::TABLET; return $this; } /** * Mark the subscriber for desktop. * * @return $this */ public function for_desktop() { $this->device = self::DESKTOP; return $this; } /** * Get current context. * * @return string Context. */ public function get_context() { return ! empty( $this->current_context ) ? $this->current_context : self::CONTEXT_FRONTEND; } /** * Transform selectors tags into CSS selectors. * * @return array Transformed mapping. */ public function transform_selectors() { if ( $this->is_transformed ) { return $this->mapping; } $map = []; foreach ( $this->mapping as $key_map => $value_map ) { $selector = ! isset( $value_map[ self::KEY_SELECTOR ] ) ? $key_map : $value_map[ self::KEY_SELECTOR ]; $props = ! isset( $value_map[ self::KEY_RULES ] ) ? $value_map : $value_map[ self::KEY_RULES ]; $context = isset( $value_map[ self::KEY_CONTEXT ] ) ? $value_map[ self::KEY_CONTEXT ] : [ self::CONTEXT_FRONTEND => true ]; $expanded_selectors = $selector; if ( ! isset( $context[ $this->get_context() ] ) ) { continue; } if ( isset( Config::$css_selectors_map[ $expanded_selectors ] ) ) { $expanded_selectors = Config::$css_selectors_map[ $expanded_selectors ]; } $expanded_selectors = apply_filters( 'neve_selectors_' . $selector, $expanded_selectors, $context, $this ); if ( empty( $expanded_selectors ) ) { continue; } if ( $this->get_context() === self::CONTEXT_GUTENBERG ) { $expanded_selectors = explode( ',', $expanded_selectors ); $expanded_selectors = array_map( function ( $value ) { return $value === ':root' ? $value : '.editor-styles-wrapper ' . $value; }, $expanded_selectors ); $expanded_selectors = implode( ',', $expanded_selectors ); } $map[ $expanded_selectors ] = isset( $map[ $expanded_selectors ] ) ? array_merge( $map[ $expanded_selectors ], $props ) : $props; } $this->is_transformed = true; $this->mapping = $map; return $this->mapping; } /** * Get dynamic value. * * @param array|string $meta Prop meta. * * @return bool|mixed */ public function get_value( $meta ) { // By default the non-responsive settings are shown only on mobile media query. By using the META_DEVICE_ONLY prop we can move this to different devices. if ( ( ! isset( $meta[ self::META_IS_RESPONSIVE ] ) || ! $meta[ self::META_IS_RESPONSIVE ] ) && $this->get_device() !== ( isset( $meta[ self::META_DEVICE_ONLY ] ) ? $meta[ self::META_DEVICE_ONLY ] : self::MOBILE ) ) { return false; } $key = is_array( $meta ) ? $meta[ self::META_KEY ] : $meta; $default = isset( $meta[ self::META_DEFAULT ] ) ? $meta[ self::META_DEFAULT ] : false; $value = Mods::get( $key, $default ); if ( $value === false || $value === null || $value === '' ) { return $default; } if ( isset( $meta[ self::META_IS_RESPONSIVE ] ) && $meta[ self::META_IS_RESPONSIVE ] ) { // If the value is defined as responsive and we don't have a responsive mapped value, // we use that value for all devices. if ( is_string( $value ) ) { $decoded_value = json_decode( $value, true ); $value = $decoded_value !== null ? $decoded_value : $value; } return isset( $value[ $this->get_device() ] ) ? $value[ $this->get_device() ] : ( ( is_string( $value ) || is_numeric( $value ) ) ? $value : false ); } return $value; } /** * Get current device. * * @return string Current device. */ public function get_device() { return ! empty( $this->device ) ? $this->device : self::MOBILE; } /** * Return CSS rules. * * @return string CSS style. */ public function __toString() { $rules = ''; $selectors = $this->transform_selectors(); foreach ( $selectors as $selector => $props ) { $rules_selector = ''; foreach ( $props as $css_prop => $meta ) { $value = $this->get_value( $meta ); if ( $value === false || $value === null || $value === '' ) { continue; } $rules_selector .= Css_Prop::transform( $css_prop, $value, $meta, $this->get_device() ); } $rules_selector = trim( $rules_selector ); if ( empty( $rules_selector ) ) { continue; } $rules .= sprintf( "\n%s{ \n%s \n}\n", $selector, $rules_selector ); } return $rules; } }
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings