Initial commit: plantilla base PHP para webs Acai CMS
This commit is contained in:
58
lib/FileJoiner.php
Executable file
58
lib/FileJoiner.php
Executable file
@@ -0,0 +1,58 @@
|
||||
<?
|
||||
class FileJoiner {
|
||||
private $_files;
|
||||
private $_fileContent;
|
||||
private $_type;
|
||||
private $_target;
|
||||
|
||||
public function __construct($files, $type, $target) {
|
||||
$this->_files = $files;
|
||||
$this->_type = $type;
|
||||
$this->_target = $target;
|
||||
}
|
||||
|
||||
private function _joinFiles() {
|
||||
$this->_fileContent = "";
|
||||
foreach ($this->_files as $file):
|
||||
$file = $file;
|
||||
if (file_exists($file)) {
|
||||
$this->_fileContent .= file_get_contents($file)."\n";
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
||||
public function getFile() {
|
||||
$target = $this->_target;
|
||||
if (file_exists($target)) {
|
||||
$targetTime = filemtime($target);
|
||||
// Recorremos la lista de archivos a ver si hay alguno más nuevo que el generado
|
||||
foreach ($this->_files as $file):
|
||||
$file = $file;
|
||||
if (file_exists($file)) {
|
||||
if (filemtime($file) > $targetTime) {
|
||||
$hayNuevos = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
endforeach;
|
||||
if (!@$hayNuevos) return file_get_contents($target);
|
||||
}
|
||||
// Generamos un nuevo archivo
|
||||
$this->_joinFiles();
|
||||
file_put_contents($target, $this->_fileContent);
|
||||
|
||||
return file_get_contents($target);
|
||||
}
|
||||
|
||||
public function getContentType() {
|
||||
$ct = "Content-Type: ";
|
||||
switch ($this->_type) {
|
||||
case "js":
|
||||
return $ct."application/javascript";
|
||||
case "css":
|
||||
return $ct."text/css";
|
||||
default: return $ct."text/plaintext";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
7
lib/IPNGenerica.php
Executable file
7
lib/IPNGenerica.php
Executable file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
if (isset($_REQUEST["ipn"]) || isset($_REQUEST["forma_de_pago"]) || isset($_REQUEST['cancel']) || (isset($_REQUEST['data']) && isset($_REQUEST['data']["object"]) ) ){
|
||||
require_once(__DIR__."/../cms/lib/plugins/builder_saas/builder_functions.php");
|
||||
hook("/hooks/1607710458061/");
|
||||
hook("/hooks/ipn/");
|
||||
}
|
||||
?>
|
||||
76
lib/Module.php
Executable file
76
lib/Module.php
Executable file
@@ -0,0 +1,76 @@
|
||||
<?
|
||||
class Module {
|
||||
public static $css = array();
|
||||
public static $cssHash = array();
|
||||
public static $js = array();
|
||||
public static $jsHash = array();
|
||||
public static $loaded = array();
|
||||
public static $path = './'.PLANTILLA.'/modulos/';
|
||||
|
||||
public static function load($folder, $params) {
|
||||
$folderAbs = Module::$path.$folder;
|
||||
if (!isset(Module::$loaded[$folder])) {
|
||||
$files = scandir($folderAbs);
|
||||
|
||||
// Los dos primeros elementos son ../ y ./
|
||||
array_splice($files, 0, 2);
|
||||
|
||||
foreach ($files as $file):
|
||||
$ext = pathinfo($folderAbs.'/'.$file, PATHINFO_EXTENSION);
|
||||
switch ($ext) {
|
||||
case 'css':
|
||||
$md5File = md5_file($folderAbs.'/'.$file);
|
||||
|
||||
if (!in_array($md5File,Module::$cssHash)) {
|
||||
Module::$css[] = '/modulos/'.$folder.'/'.$file;
|
||||
Module::$cssHash[] = $md5File;
|
||||
}
|
||||
break;
|
||||
case 'js':
|
||||
$md5File = md5_file($folderAbs.'/'.$file);
|
||||
if (!in_array($md5File,Module::$jsHash)) {
|
||||
Module::$js[] = '/modulos/'.$folder.'/'.$file;
|
||||
Module::$jsHash[] = $md5File;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
endforeach;
|
||||
Module::$loaded[$folder] = true;
|
||||
}
|
||||
|
||||
extract($params);
|
||||
ob_start();
|
||||
require($folderAbs.'/index.tpl');
|
||||
$resultado = ob_get_clean();
|
||||
return $resultado;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Devuelve una string con todos los link que ha sacado de los módulos
|
||||
*/
|
||||
public static function links() {
|
||||
Module::$css = array_unique(Module::$css);
|
||||
$links=''; if (defined('USE_MIN_TAILWIND') && USE_MIN_TAILWIND) return '';
|
||||
foreach (Module::$css as $c):
|
||||
$links .= '<link rel="stylesheet" href="'.h($c).'">';
|
||||
endforeach;
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devuelve una string con todos los scripts que ha sacado de los módulos
|
||||
*/
|
||||
public static function scripts() {
|
||||
Module::$js = array_unique(Module::$js);
|
||||
$scripts=''; if (defined('USE_MIN_JS_TAILWIND') && USE_MIN_JS_TAILWIND) return '';
|
||||
foreach (Module::$js as $s):
|
||||
$scripts .= '<script src="'.h($s).'"></script>';
|
||||
endforeach;
|
||||
return $scripts;
|
||||
}
|
||||
}
|
||||
?>
|
||||
49
lib/PHPMailerAutoload.php
Executable file
49
lib/PHPMailerAutoload.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer SPL autoloader.
|
||||
* PHP Version 5
|
||||
* @package PHPMailer
|
||||
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
* @author Brent R. Matzelle (original founder)
|
||||
* @copyright 2012 - 2014 Marcus Bointon
|
||||
* @copyright 2010 - 2012 Jim Jagielski
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPMailer SPL autoloader.
|
||||
* @param string $classname The name of the class to load
|
||||
*/
|
||||
function PHPMailerAutoload($classname)
|
||||
{
|
||||
//Can't use __DIR__ as it's only in PHP 5.3+
|
||||
$filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
|
||||
if (is_readable($filename)) {
|
||||
require $filename;
|
||||
}
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
|
||||
//SPL autoloading was introduced in PHP 5.1.2
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
||||
spl_autoload_register('PHPMailerAutoload', true, true);
|
||||
} else {
|
||||
spl_autoload_register('PHPMailerAutoload');
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Fall back to traditional autoload for old PHP versions
|
||||
* @param string $classname The name of the class to load
|
||||
*/
|
||||
function __autoload($classname)
|
||||
{
|
||||
PHPMailerAutoload($classname);
|
||||
}
|
||||
}
|
||||
23
lib/Resource.class.php
Executable file
23
lib/Resource.class.php
Executable file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
class Resource {
|
||||
static function link($path, $async = false, $hash = true) {
|
||||
$existMinimalCSSFile = array_filter(Module::$css,function($rec){ return strpos($rec,"cache") !== false; });
|
||||
if ($existMinimalCSSFile) $existMinimalCSSFile = array_values($existMinimalCSSFile);
|
||||
if (strpos($path,"cache") !== false && $existMinimalCSSFile) return;
|
||||
if (strpos($path,"tailwind") !== false && defined("USE_MIN_TAILWIND") && USE_MIN_TAILWIND) $path = str_replace("tailwind","cocotail",$path);
|
||||
if (strpos($path,"tailwind") !== false && $existMinimalCSSFile) $path = $existMinimalCSSFile[0];
|
||||
if (strpos($path,"tailwind") == false && !$existMinimalCSSFile && @$_REQUEST["generateMinCss"]) return;
|
||||
$absolute = strpos($path, 'http') === 0 || strpos($path, '//') === 0;
|
||||
if ($absolute) $hash = false;
|
||||
|
||||
if ($hash) $path = h($path);
|
||||
if ($async) {
|
||||
echo '<link rel="preload" as="style" href="'.$path.'" onload="this.onload=null;this.rel=\'stylesheet\'">
|
||||
<noscript><link rel="stylesheet" href="'.$path.'"></noscript>
|
||||
';
|
||||
}
|
||||
else {
|
||||
echo '<link rel="stylesheet" href="'.$path.'">';
|
||||
}
|
||||
}
|
||||
}
|
||||
3541
lib/class.phpmailer.php
Executable file
3541
lib/class.phpmailer.php
Executable file
File diff suppressed because it is too large
Load Diff
397
lib/class.pop3.php
Executable file
397
lib/class.pop3.php
Executable file
@@ -0,0 +1,397 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer POP-Before-SMTP Authentication Class.
|
||||
* PHP Version 5
|
||||
* @package PHPMailer
|
||||
* @link https://github.com/PHPMailer/PHPMailer/
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
* @author Brent R. Matzelle (original founder)
|
||||
* @copyright 2012 - 2014 Marcus Bointon
|
||||
* @copyright 2010 - 2012 Jim Jagielski
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPMailer POP-Before-SMTP Authentication Class.
|
||||
* Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication.
|
||||
* Does not support APOP.
|
||||
* @package PHPMailer
|
||||
* @author Richard Davey (original author) <rich@corephp.co.uk>
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
*/
|
||||
class POP3
|
||||
{
|
||||
/**
|
||||
* The POP3 PHPMailer Version number.
|
||||
* @type string
|
||||
* @access public
|
||||
*/
|
||||
public $Version = '5.2.9';
|
||||
|
||||
/**
|
||||
* Default POP3 port number.
|
||||
* @type integer
|
||||
* @access public
|
||||
*/
|
||||
public $POP3_PORT = 110;
|
||||
|
||||
/**
|
||||
* Default timeout in seconds.
|
||||
* @type integer
|
||||
* @access public
|
||||
*/
|
||||
public $POP3_TIMEOUT = 30;
|
||||
|
||||
/**
|
||||
* POP3 Carriage Return + Line Feed.
|
||||
* @type string
|
||||
* @access public
|
||||
* @deprecated Use the constant instead
|
||||
*/
|
||||
public $CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Debug display level.
|
||||
* Options: 0 = no, 1+ = yes
|
||||
* @type integer
|
||||
* @access public
|
||||
*/
|
||||
public $do_debug = 0;
|
||||
|
||||
/**
|
||||
* POP3 mail server hostname.
|
||||
* @type string
|
||||
* @access public
|
||||
*/
|
||||
public $host;
|
||||
|
||||
/**
|
||||
* POP3 port number.
|
||||
* @type integer
|
||||
* @access public
|
||||
*/
|
||||
public $port;
|
||||
|
||||
/**
|
||||
* POP3 Timeout Value in seconds.
|
||||
* @type integer
|
||||
* @access public
|
||||
*/
|
||||
public $tval;
|
||||
|
||||
/**
|
||||
* POP3 username
|
||||
* @type string
|
||||
* @access public
|
||||
*/
|
||||
public $username;
|
||||
|
||||
/**
|
||||
* POP3 password.
|
||||
* @type string
|
||||
* @access public
|
||||
*/
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* Resource handle for the POP3 connection socket.
|
||||
* @type resource
|
||||
* @access private
|
||||
*/
|
||||
private $pop_conn;
|
||||
|
||||
/**
|
||||
* Are we connected?
|
||||
* @type boolean
|
||||
* @access private
|
||||
*/
|
||||
private $connected = false;
|
||||
|
||||
/**
|
||||
* Error container.
|
||||
* @type array
|
||||
* @access private
|
||||
*/
|
||||
private $errors = array();
|
||||
|
||||
/**
|
||||
* Line break constant
|
||||
*/
|
||||
const CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Simple static wrapper for all-in-one POP before SMTP
|
||||
* @param $host
|
||||
* @param boolean $port
|
||||
* @param boolean $tval
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param integer $debug_level
|
||||
* @return boolean
|
||||
*/
|
||||
public static function popBeforeSmtp(
|
||||
$host,
|
||||
$port = false,
|
||||
$tval = false,
|
||||
$username = '',
|
||||
$password = '',
|
||||
$debug_level = 0
|
||||
) {
|
||||
$pop = new POP3;
|
||||
return $pop->authorise($host, $port, $tval, $username, $password, $debug_level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate with a POP3 server.
|
||||
* A connect, login, disconnect sequence
|
||||
* appropriate for POP-before SMTP authorisation.
|
||||
* @access public
|
||||
* @param string $host The hostname to connect to
|
||||
* @param integer|boolean $port The port number to connect to
|
||||
* @param integer|boolean $timeout The timeout value
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param integer $debug_level
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
|
||||
{
|
||||
$this->host = $host;
|
||||
// If no port value provided, use default
|
||||
if (false === $port) {
|
||||
$this->port = $this->POP3_PORT;
|
||||
} else {
|
||||
$this->port = (integer)$port;
|
||||
}
|
||||
// If no timeout value provided, use default
|
||||
if (false === $timeout) {
|
||||
$this->tval = $this->POP3_TIMEOUT;
|
||||
} else {
|
||||
$this->tval = (integer)$timeout;
|
||||
}
|
||||
$this->do_debug = $debug_level;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
// Reset the error log
|
||||
$this->errors = array();
|
||||
// connect
|
||||
$result = $this->connect($this->host, $this->port, $this->tval);
|
||||
if ($result) {
|
||||
$login_result = $this->login($this->username, $this->password);
|
||||
if ($login_result) {
|
||||
$this->disconnect();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// We need to disconnect regardless of whether the login succeeded
|
||||
$this->disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a POP3 server.
|
||||
* @access public
|
||||
* @param string $host
|
||||
* @param integer|boolean $port
|
||||
* @param integer $tval
|
||||
* @return boolean
|
||||
*/
|
||||
public function connect($host, $port = false, $tval = 30)
|
||||
{
|
||||
// Are we already connected?
|
||||
if ($this->connected) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//On Windows this will raise a PHP Warning error if the hostname doesn't exist.
|
||||
//Rather than suppress it with @fsockopen, capture it cleanly instead
|
||||
set_error_handler(array($this, 'catchWarning'));
|
||||
|
||||
if (false === $port) {
|
||||
$port = $this->POP3_PORT;
|
||||
}
|
||||
|
||||
// connect to the POP3 server
|
||||
$this->pop_conn = fsockopen(
|
||||
$host, // POP3 Host
|
||||
$port, // Port #
|
||||
$errno, // Error Number
|
||||
$errstr, // Error Message
|
||||
$tval
|
||||
); // Timeout (seconds)
|
||||
// Restore the error handler
|
||||
restore_error_handler();
|
||||
|
||||
// Did we connect?
|
||||
if (false === $this->pop_conn) {
|
||||
// It would appear not...
|
||||
$this->setError(array(
|
||||
'error' => "Failed to connect to server $host on port $port",
|
||||
'errno' => $errno,
|
||||
'errstr' => $errstr
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Increase the stream time-out
|
||||
stream_set_timeout($this->pop_conn, $tval, 0);
|
||||
|
||||
// Get the POP3 server response
|
||||
$pop3_response = $this->getResponse();
|
||||
// Check for the +OK
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
// The connection is established and the POP3 server is talking
|
||||
$this->connected = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in to the POP3 server.
|
||||
* Does not support APOP (RFC 2828, 4949).
|
||||
* @access public
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return boolean
|
||||
*/
|
||||
public function login($username = '', $password = '')
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->setError('Not connected to POP3 server');
|
||||
}
|
||||
if (empty($username)) {
|
||||
$username = $this->username;
|
||||
}
|
||||
if (empty($password)) {
|
||||
$password = $this->password;
|
||||
}
|
||||
|
||||
// Send the Username
|
||||
$this->sendString("USER $username" . self::CRLF);
|
||||
$pop3_response = $this->getResponse();
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
// Send the Password
|
||||
$this->sendString("PASS $password" . self::CRLF);
|
||||
$pop3_response = $this->getResponse();
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the POP3 server.
|
||||
* @access public
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
$this->sendString('QUIT');
|
||||
//The QUIT command may cause the daemon to exit, which will kill our connection
|
||||
//So ignore errors here
|
||||
try {
|
||||
@fclose($this->pop_conn);
|
||||
} catch (Exception $e) {
|
||||
//Do nothing
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a response from the POP3 server.
|
||||
* $size is the maximum number of bytes to retrieve
|
||||
* @param integer $size
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
private function getResponse($size = 128)
|
||||
{
|
||||
$response = fgets($this->pop_conn, $size);
|
||||
if ($this->do_debug >= 1) {
|
||||
echo "Server -> Client: $response";
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send raw data to the POP3 server.
|
||||
* @param string $string
|
||||
* @return integer
|
||||
* @access private
|
||||
*/
|
||||
private function sendString($string)
|
||||
{
|
||||
if ($this->pop_conn) {
|
||||
if ($this->do_debug >= 2) { //Show client messages when debug >= 2
|
||||
echo "Client -> Server: $string";
|
||||
}
|
||||
return fwrite($this->pop_conn, $string, strlen($string));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the POP3 server response.
|
||||
* Looks for for +OK or -ERR.
|
||||
* @param string $string
|
||||
* @return boolean
|
||||
* @access private
|
||||
*/
|
||||
private function checkResponse($string)
|
||||
{
|
||||
if (substr($string, 0, 3) !== '+OK') {
|
||||
$this->setError(array(
|
||||
'error' => "Server reported an error: $string",
|
||||
'errno' => 0,
|
||||
'errstr' => ''
|
||||
));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error to the internal error store.
|
||||
* Also display debug output if it's enabled.
|
||||
* @param $error
|
||||
*/
|
||||
private function setError($error)
|
||||
{
|
||||
$this->errors[] = $error;
|
||||
if ($this->do_debug >= 1) {
|
||||
echo '<pre>';
|
||||
foreach ($this->errors as $error) {
|
||||
print_r($error);
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POP3 connection error handler.
|
||||
* @param integer $errno
|
||||
* @param string $errstr
|
||||
* @param string $errfile
|
||||
* @param integer $errline
|
||||
* @access private
|
||||
*/
|
||||
private function catchWarning($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
$this->setError(array(
|
||||
'error' => "Connecting to the POP3 server raised a PHP warning: ",
|
||||
'errno' => $errno,
|
||||
'errstr' => $errstr,
|
||||
'errfile' => $errfile,
|
||||
'errline' => $errline
|
||||
));
|
||||
}
|
||||
}
|
||||
1152
lib/class.smtp.php
Executable file
1152
lib/class.smtp.php
Executable file
File diff suppressed because it is too large
Load Diff
307
lib/minifier.php
Executable file
307
lib/minifier.php
Executable file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
// Based on <https://github.com/mecha-cms/extend.minify>
|
||||
|
||||
define('MINIFY_STRING', '"(?:[^"\\\]|\\\.)*"|\'(?:[^\'\\\]|\\\.)*\'');
|
||||
define('MINIFY_COMMENT_CSS', '/\*[\s\S]*?\*/');
|
||||
define('MINIFY_COMMENT_HTML', '<!\-{2}[\s\S]*?\-{2}>');
|
||||
define('MINIFY_COMMENT_JS', '//[^\n]*');
|
||||
define('MINIFY_PATTERN_JS', '/[^\n]+?/[gimuy]*');
|
||||
define('MINIFY_HTML', '<[!/]?[a-zA-Z\d:.-]+[\s\S]*?>');
|
||||
define('MINIFY_HTML_ENT', '&(?:[a-zA-Z\d]+|\#\d+|\#x[a-fA-F\d]+);');
|
||||
define('MINIFY_HTML_KEEP', '<pre(?:\s[^<>]*?)?>[\s\S]*?</pre>|<code(?:\s[^<>]*?)?>[\s\S]*?</code>|<script(?:\s[^<>]*?)?>[\s\S]*?</script>|<style(?:\s[^<>]*?)?>[\s\S]*?</style>|<textarea(?:\s[^<>]*?)?>[\s\S]*?</textarea>');
|
||||
|
||||
// get URL
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443 ? 'https' : 'http') . '://';
|
||||
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : "");
|
||||
$url = $protocol . $host;
|
||||
|
||||
// escape character
|
||||
define('X', "\x1A");
|
||||
|
||||
// normalize line–break(s)
|
||||
function n($s) {
|
||||
return str_replace(["\r\n", "\r"], "\n", $s);
|
||||
}
|
||||
|
||||
// trim once
|
||||
function tr($a, $b) {
|
||||
if ($a && strpos($a, $b) === 0 && substr($a, -strlen($b)) === $b) {
|
||||
return substr(substr($a, strlen($b)), 0, -strlen($b));
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
function fn_minify($pattern, $input) {
|
||||
return preg_split('#(' . implode('|', $pattern) . ')#', $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
||||
}
|
||||
|
||||
function fn_minify_css($input, $comment = 2, $quote = 2) {
|
||||
if (!is_string($input) || !$input = n(trim($input))) return $input;
|
||||
$output = $prev = "";
|
||||
foreach (fn_minify([MINIFY_COMMENT_CSS, MINIFY_STRING], $input) as $part) {
|
||||
if (trim($part) === "") continue;
|
||||
if ($comment !== 1 && strpos($part, '/*') === 0 && substr($part, -2) === '*/') {
|
||||
if (
|
||||
$comment === 2 && (
|
||||
// Detect special comment(s) from the third character. It should be a `!` or `*` → `/*! keep */` or `/** keep */`
|
||||
strpos('*!', $part[2]) !== false ||
|
||||
// Detect license comment(s) from the content. It should contains character(s) like `@license`
|
||||
stripos($part, '@licence') !== false || // noun
|
||||
stripos($part, '@license') !== false || // verb
|
||||
stripos($part, '@preserve') !== false
|
||||
)
|
||||
) {
|
||||
$output .= $part;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ($part[0] === '"' && substr($part, -1) === '"' || $part[0] === "'" && substr($part, -1) === "'") {
|
||||
// Remove quote(s) where possible …
|
||||
$q = $part[0];
|
||||
if (
|
||||
$quote !== 1 && (
|
||||
// <https://www.w3.org/TR/CSS2/syndata.html#uri>
|
||||
substr($prev, -4) === 'url(' && preg_match('#\burl\($#', $prev) ||
|
||||
// <https://www.w3.org/TR/CSS2/syndata.html#characters>
|
||||
substr($prev, -1) === '=' && preg_match('#^' . $q . '[a-zA-Z_][\w-]*?' . $q . '$#', $part)
|
||||
)
|
||||
) {
|
||||
$part = tr($part, $q); // trim quote(s)
|
||||
}
|
||||
$output .= $part;
|
||||
} else {
|
||||
$output .= fn_minify_css_union($part);
|
||||
}
|
||||
$prev = $part;
|
||||
}
|
||||
return trim($output);
|
||||
}
|
||||
|
||||
function fn_minify_css_union($input) {
|
||||
if (stripos($input, 'calc(') !== false) {
|
||||
// Keep important white–space(s) in `calc()`
|
||||
$input = preg_replace_callback('#\b(calc\()\s*(.*?)\s*\)#i', function($m) {
|
||||
return $m[1] . preg_replace('#\s+#', X, $m[2]) . ')';
|
||||
}, $input);
|
||||
}
|
||||
$input = preg_replace([
|
||||
// Fix case for `#foo<space>[bar="baz"]`, `#foo<space>*` and `#foo<space>:first-child` [^1]
|
||||
'#(?<=[\w])\s+(\*|\[|:[\w-]+)#',
|
||||
// Fix case for `[bar="baz"]<space>.foo`, `*<space>.foo`, `:nth-child(2)<space>.foo` and `@media<space>(foo: bar)<space>and<space>(baz: qux)` [^2]
|
||||
'#([*\]\)])\s+(?=[\w\#.])#', '#\b\s+\(#', '#\)\s+\b#',
|
||||
// Minify HEX color code … [^3]
|
||||
'#\#([a-f\d])\1([a-f\d])\2([a-f\d])\3\b#i',
|
||||
// Remove white–space(s) around punctuation(s) [^4]
|
||||
'#\s*([~!@*\(\)+=\{\}\[\]:;,>\/])\s*#',
|
||||
// Replace zero unit(s) with `0` [^5]
|
||||
'#\b(?:0\.)?0([a-z]+\b)#i',
|
||||
// Replace `0.6` with `.6` [^6]
|
||||
'#\b0+\.(\d+)#',
|
||||
// Replace `:0 0`, `:0 0 0` and `:0 0 0 0` with `:0` [^7]
|
||||
'#:(0\s+){0,3}0(?=[!,;\)\}]|$)#',
|
||||
// Replace `background(?:-position)?:(0|none)` with `background$1:0 0` [^8]
|
||||
'#\b(background(?:-position)?):(?:0|none)([;,\}])#i',
|
||||
// Replace `(border(?:-radius)?|outline):none` with `$1:0` [^9]
|
||||
'#\b(border(?:-radius)?|outline):none\b#i',
|
||||
// Remove empty selector(s) [^10]
|
||||
'#(^|[\{\}])(?:[^\{\}]+)\{\}#',
|
||||
// Remove the last semi–colon and replace multiple semi–colon(s) with a semi–colon [^11]
|
||||
'#;+([;\}])#',
|
||||
// Replace multiple white–space(s) with a space [^12]
|
||||
'#\s+#'
|
||||
], [
|
||||
// [^1]
|
||||
X . '$1',
|
||||
// [^2]
|
||||
'$1' . X, X . '(', ')' . X,
|
||||
// [^3]
|
||||
'#$1$2$3',
|
||||
// [^4]
|
||||
'$1',
|
||||
// [^5]
|
||||
'0',
|
||||
// [^6]
|
||||
'.$1',
|
||||
// [^7]
|
||||
':0',
|
||||
// [^8]
|
||||
'$1:0 0$2',
|
||||
// [^9]
|
||||
'$1:0',
|
||||
// [^10]
|
||||
'$1',
|
||||
// [^11]
|
||||
'$1',
|
||||
// [^12]
|
||||
' '
|
||||
], $input);
|
||||
return trim(str_replace(X, ' ', $input));
|
||||
}
|
||||
|
||||
function fn_minify_html($input, $comment = 2, $quote = 1) {
|
||||
if (!is_string($input) || !$input = n(trim($input))) return $input;
|
||||
$output = $prev = "";
|
||||
foreach (fn_minify([MINIFY_COMMENT_HTML, MINIFY_HTML_KEEP, MINIFY_HTML, MINIFY_HTML_ENT], $input) as $part) {
|
||||
if ($part === "\n") continue;
|
||||
if ($part !== ' ' && trim($part) === "" || $comment !== 1 && strpos($part, '<!--') === 0) {
|
||||
// Detect IE conditional comment(s) by its closing tag …
|
||||
if ($comment === 2 && substr($part, -12) === '<![endif]-->') {
|
||||
$output .= $part;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ($part[0] === '<' && substr($part, -1) === '>') {
|
||||
$output .= fn_minify_html_union($part, $quote);
|
||||
} else if ($part[0] === '&' && substr($part, -1) === ';' && $part !== '<' && $part !== '>' && $part !== '&') {
|
||||
$output .= html_entity_decode($part); // Evaluate HTML entit(y|ies)
|
||||
} else {
|
||||
$output .= preg_replace('#\s+#', ' ', $part);
|
||||
}
|
||||
$prev = $part;
|
||||
}
|
||||
$output = str_replace(' </', '</', $output);
|
||||
// Force space with ` ` and line–break with `
`
|
||||
return str_ireplace([' ', ' ', '
', '
'], [' ', ' ', "\n", "\n"], trim($output));
|
||||
}
|
||||
|
||||
function fn_minify_html_union($input, $quote) {
|
||||
if (
|
||||
strpos($input, ' ') === false &&
|
||||
strpos($input, "\n") === false &&
|
||||
strpos($input, "\t") === false
|
||||
) return $input;
|
||||
global $url;
|
||||
return preg_replace_callback('#<\s*([^\/\s]+)\s*(?:>|(\s[^<>]+?)\s*>)#', function($m) use($quote, $url) {
|
||||
if (isset($m[2])) {
|
||||
// Minify inline CSS(s)
|
||||
if (stripos($m[2], ' style=') !== false) {
|
||||
$m[2] = preg_replace_callback('#( style=)([\'"]?)(.*?)\2#i', function($m) {
|
||||
return $m[1] . $m[2] . fn_minify_css($m[3]) . $m[2];
|
||||
}, $m[2]);
|
||||
}
|
||||
// Minify URL(s)
|
||||
if (strpos($m[2], '://') !== false) {
|
||||
// $m[2] = str_replace([
|
||||
// $url . '/',
|
||||
// $url . '?',
|
||||
// $url . '&',
|
||||
// $url . '#',
|
||||
// $url . '"',
|
||||
// $url . "'"
|
||||
// ], [
|
||||
// '/',
|
||||
// '?',
|
||||
// '&',
|
||||
// '#',
|
||||
// '/"',
|
||||
// "/'"
|
||||
// ], $m[2]);
|
||||
}
|
||||
$a = 'a(sync|uto(focus|play))|c(hecked|ontrols)|d(efer|isabled)|hidden|ismap|loop|multiple|open|re(adonly|quired)|s((cop|elect)ed|pellcheck)';
|
||||
$a = '<' . $m[1] . preg_replace([
|
||||
// From `a="a"`, `a='a'`, `a="true"`, `a='true'`, `a=""` and `a=''` to `a` [^1]
|
||||
'#\s(' . $a . ')(?:=([\'"]?)(?:true|\1)?\2)#i',
|
||||
// Remove extra white–space(s) between HTML attribute(s) [^2]
|
||||
'#\s*([^\s=]+?)(=(?:\S+|([\'"]?).*?\3)|$)#',
|
||||
// From `<img />` to `<img/>` [^3]
|
||||
'#\s+\/$#'
|
||||
], [
|
||||
// [^1]
|
||||
' $1',
|
||||
// [^2]
|
||||
' $1$2',
|
||||
// [^3]
|
||||
'/'
|
||||
], str_replace("\n", ' ', $m[2])) . '>';
|
||||
return $quote !== 1 ? fn_minify_html_union_attr($a) : $a;
|
||||
}
|
||||
return '<' . $m[1] . '>';
|
||||
}, $input);
|
||||
}
|
||||
|
||||
function fn_minify_html_union_attr($input) {
|
||||
if (strpos($input, '=') === false) return $input;
|
||||
return preg_replace_callback('#=(' . MINIFY_STRING . ')#', function($m) {
|
||||
$q = $m[1][0];
|
||||
if (strpos($m[1], ' ') === false && preg_match('#^' . $q . '[a-zA-Z_][\w-]*?' . $q . '$#', $m[1])) {
|
||||
return '=' . tr($m[1], $q);
|
||||
}
|
||||
return $m[0];
|
||||
}, $input);
|
||||
}
|
||||
|
||||
function fn_minify_js($input, $comment = 2, $quote = 2) {
|
||||
if (!is_string($input) || !$input = n(trim($input))) return $input;
|
||||
$output = $prev = "";
|
||||
foreach (fn_minify([MINIFY_COMMENT_CSS, MINIFY_STRING, MINIFY_COMMENT_JS, MINIFY_PATTERN_JS], $input) as $part) {
|
||||
if (trim($part) === "") continue;
|
||||
if ($comment !== 1 && (
|
||||
strpos($part, '//') === 0 || // Remove inline comment(s)
|
||||
strpos($part, '/*') === 0 && substr($part, -2) === '*/'
|
||||
)) {
|
||||
if (
|
||||
$comment === 2 && (
|
||||
// Detect special comment(s) from the third character. It should be a `!` or `*` → `/*! keep */` or `/** keep */`
|
||||
strpos('*!', $part[2]) !== false ||
|
||||
// Detect license comment(s) from the content. It should contains character(s) like `@license`
|
||||
stripos($part, '@licence') !== false || // noun
|
||||
stripos($part, '@license') !== false || // verb
|
||||
stripos($part, '@preserve') !== false
|
||||
)
|
||||
) {
|
||||
$output .= $part;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ($part[0] === '/' && (substr($part, -1) === '/' || preg_match('#\/[gimuy]*$#', $part))) {
|
||||
} else if ($part[0] === '"' && substr($part, -1) === '"' || $part[0] === "'" && substr($part, -1) === "'") {
|
||||
// TODO: Remove quote(s) where possible …
|
||||
$output .= $part;
|
||||
} else {
|
||||
$output .= fn_minify_js_union($part);
|
||||
}
|
||||
$prev = $part;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function fn_minify_js_union($input) {
|
||||
return preg_replace([
|
||||
// Remove white–space(s) around punctuation(s) [^1]
|
||||
'#\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#',
|
||||
// Remove the last semi–colon and comma [^2]
|
||||
'#[;,]([\]\}])#',
|
||||
// Replace `true` with `!0` and `false` with `!1` [^3]
|
||||
'#\btrue\b#', '#\bfalse\b#', '#\b(return\s?)\s*\b#',
|
||||
// Replace `new Array(x)` with `[x]` … [^4]
|
||||
'#\b(?:new\s+)?Array\((.*?)\)#', '#\b(?:new\s+)?Object\((.*?)\)#'
|
||||
], [
|
||||
// [^1]
|
||||
'$1',
|
||||
// [^2]
|
||||
'$1',
|
||||
// [^3]
|
||||
'!0', '!1', '$1',
|
||||
// [^4]
|
||||
'[$1]', '{$1}'
|
||||
], $input);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Backward Compatibility
|
||||
* ----------------------
|
||||
*/
|
||||
|
||||
function minify_css(...$lot) {
|
||||
return fn_minify_css(...$lot);
|
||||
}
|
||||
|
||||
function minify_html(...$lot) {
|
||||
return fn_minify_html(...$lot);
|
||||
}
|
||||
|
||||
function minify_js(...$lot) {
|
||||
return fn_minify_js(...$lot);
|
||||
}
|
||||
42
lib/recursos.php
Executable file
42
lib/recursos.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?
|
||||
require_once "variables.php";
|
||||
require_once "FileJoiner.php";
|
||||
|
||||
$fileType = "css";
|
||||
switch (@$_REQUEST["fileType"]) {
|
||||
case "css":
|
||||
$files = array(
|
||||
"..".RUTA_PLANTILLA."/css/bootstrap.min.css",
|
||||
"..".RUTA_PLANTILLA."/css/bxslider.min.css",
|
||||
"..".RUTA_PLANTILLA."/css/swipebox.min.css",
|
||||
"..".RUTA_PLANTILLA."/css/animate.css",
|
||||
"..".RUTA_PLANTILLA."/css/rrssb.css",
|
||||
"..".RUTA_PLANTILLA."/css/cesta.css",
|
||||
"..".RUTA_PLANTILLA."/style-base.css",
|
||||
"..".RUTA_PLANTILLA."/style.css"
|
||||
);
|
||||
$fileName = "..".RUTA_PLANTILLA."/css/main.css";
|
||||
break;
|
||||
case "js":
|
||||
$fileType = "js";
|
||||
$files = array(
|
||||
"..".RUTA_PLANTILLA."/js/bootstrap.min.js",
|
||||
"..".RUTA_PLANTILLA."/js/bxslider.min.js",
|
||||
"..".RUTA_PLANTILLA."/js/jquery.swipebox.min.js",
|
||||
"..".RUTA_PLANTILLA."/js/wow.min.js",
|
||||
"..".RUTA_PLANTILLA."/js/rrssb.min.js",
|
||||
"..".RUTA_PLANTILLA."/js/fetch.js",
|
||||
"..".RUTA_PLANTILLA."/js/lazy-loader.js",
|
||||
"..".RUTA_PLANTILLA."/js/liveSearchModal.js",
|
||||
"..".RUTA_PLANTILLA."/js/cesta_class.js",
|
||||
"..".RUTA_PLANTILLA."/js/mis-scripts.js"
|
||||
);
|
||||
|
||||
$fileName = "..".RUTA_PLANTILLA."/js/main.js";
|
||||
break;
|
||||
default: die("");
|
||||
}
|
||||
$fj = new FileJoiner($files, $fileType, @$fileName);
|
||||
header($fj->getContentType());
|
||||
die($fj->getFile());
|
||||
?>
|
||||
Reference in New Issue
Block a user