-
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Alert {
|
||||
|
||||
// Status, 0 = OK, 1 = Fail
|
||||
public static function set($value, $status=ALERT_STATUS_OK, $key='alert')
|
||||
{
|
||||
Session::set('defined', true);
|
||||
Session::set('alertStatus', $status);
|
||||
Session::set($key, $value);
|
||||
}
|
||||
|
||||
public static function get($key='alert')
|
||||
{
|
||||
Session::set('defined', false);
|
||||
return Session::get($key);
|
||||
}
|
||||
|
||||
public static function status()
|
||||
{
|
||||
return Session::get('alertStatus');
|
||||
}
|
||||
|
||||
public static function p($key='alert')
|
||||
{
|
||||
echo self::get($key);
|
||||
}
|
||||
|
||||
public static function defined()
|
||||
{
|
||||
return Session::get('defined');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Cookie {
|
||||
|
||||
public static function get($key)
|
||||
{
|
||||
if (isset($_COOKIE[$key])) {
|
||||
return $_COOKIE[$key];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function set($key, $value, $daysToExpire=30, $options=array())
|
||||
{
|
||||
$expire = time() + 60 * 60 * 24 * $daysToExpire;
|
||||
$secure = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
|
||||
|
||||
$defaults = array(
|
||||
'expires' => $expire,
|
||||
'path' => '/',
|
||||
'domain' => '',
|
||||
'secure' => $secure,
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax'
|
||||
);
|
||||
|
||||
setcookie($key, $value, array_merge($defaults, $options));
|
||||
}
|
||||
|
||||
public static function remove($key)
|
||||
{
|
||||
unset($_COOKIE[$key]);
|
||||
self::set($key, '', -1);
|
||||
}
|
||||
|
||||
public static function isEmpty($key)
|
||||
{
|
||||
return empty($_COOKIE[$key]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Date {
|
||||
|
||||
// Returns string with the date translated
|
||||
// Example: $date = 'Mon, 27th March' > 'Lun, 27th Marzo'
|
||||
public static function translate($date)
|
||||
{
|
||||
global $L;
|
||||
|
||||
// If English default language don't translate
|
||||
if ($L->currentLanguage()=='en') {
|
||||
return $date;
|
||||
}
|
||||
|
||||
// Get the array of dates from the language file
|
||||
$dates = $L->getDates();
|
||||
foreach ($dates as $english=>$anotherLang) {
|
||||
$date = preg_replace('/\b'.$english.'\b/u', $anotherLang, $date);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
// Return current Unix timestamp, GMT+0
|
||||
public static function unixTime()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
// Return the local time/date according to locale settings.
|
||||
public static function current($format)
|
||||
{
|
||||
$Date = new DateTime();
|
||||
$output = $Date->format($format);
|
||||
|
||||
return self::translate($output);
|
||||
}
|
||||
|
||||
// Returns the current time shifted by offset
|
||||
// $offest could be +1 day, +1 month
|
||||
public static function currentOffset($format, $offset)
|
||||
{
|
||||
$Date = new DateTime();
|
||||
$Date->modify($offset);
|
||||
$output = $Date->format($format);
|
||||
|
||||
return self::translate($output);
|
||||
}
|
||||
|
||||
public static function offset($date, $format, $offset)
|
||||
{
|
||||
$Date = new DateTime($date);
|
||||
$Date->modify($offset);
|
||||
$output = $Date->format($format);
|
||||
|
||||
return self::translate($output);
|
||||
}
|
||||
|
||||
// Format a local time/date according to locale settings.
|
||||
public static function format($date, $currentFormat, $outputFormat)
|
||||
{
|
||||
// Returns a new DateTime instance or FALSE on failure.
|
||||
$Date = DateTime::createFromFormat($currentFormat, $date);
|
||||
|
||||
if ($Date!==false) {
|
||||
$output = $Date->format($outputFormat);
|
||||
return self::translate($output);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function convertToUTC($date, $currentFormat, $outputFormat)
|
||||
{
|
||||
$Date = DateTime::createFromFormat($currentFormat, $date);
|
||||
$Date->setTimezone(new DateTimeZone('UTC'));
|
||||
$output = $Date->format($outputFormat);
|
||||
|
||||
return self::translate($output);
|
||||
}
|
||||
|
||||
public static function timeago($time)
|
||||
{
|
||||
$time = time() - $time;
|
||||
|
||||
$tokens = array (
|
||||
31536000 => 'year',
|
||||
2592000 => 'month',
|
||||
604800 => 'week',
|
||||
86400 => 'day',
|
||||
3600 => 'hour',
|
||||
60 => 'minute',
|
||||
1 => 'second'
|
||||
);
|
||||
|
||||
foreach ($tokens as $unit => $text) {
|
||||
if ($time < $unit) continue;
|
||||
$numberOfUnits = floor($time / $unit);
|
||||
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
|
||||
}
|
||||
}
|
||||
|
||||
// DEBUG: Check this function, need to be more fast
|
||||
// Return array('Africa/Abidjan'=>'Africa/Abidjan (GMT+0)', ..., 'Pacific/Wallis'=>'Pacific/Wallis (GMT+12)');
|
||||
// PHP supported list. http://php.net/manual/en/timezones.php
|
||||
public static function timezoneList()
|
||||
{
|
||||
$tmp = array();
|
||||
|
||||
$timezone_identifiers_list = timezone_identifiers_list();
|
||||
|
||||
foreach($timezone_identifiers_list as $timezone_identifier)
|
||||
{
|
||||
$date_time_zone = new DateTimeZone($timezone_identifier);
|
||||
$date_time = new DateTime('now', $date_time_zone);
|
||||
|
||||
$hours = floor($date_time_zone->getOffset($date_time) / 3600);
|
||||
$mins = floor(($date_time_zone->getOffset($date_time) - ($hours*3600)) / 60);
|
||||
|
||||
$hours = 'GMT' . ($hours < 0 ? $hours : '+'.$hours);
|
||||
$mins = ($mins > 0 ? $mins : '0'.$mins);
|
||||
|
||||
$text = str_replace("_"," ",$timezone_identifier);
|
||||
|
||||
$tmp[$timezone_identifier] = $text.' ('.$hours.':'.$mins.')';
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class DOM {
|
||||
|
||||
public static function getFirstImage($content)
|
||||
{
|
||||
// Disable warning
|
||||
libxml_use_internal_errors(true);
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$content);
|
||||
$finder = new DomXPath($dom);
|
||||
|
||||
$images = $finder->query("//img");
|
||||
|
||||
if($images->length>0) {
|
||||
// First image from the list
|
||||
$image = $images->item(0);
|
||||
// Get value from attribute src
|
||||
$imgSrc = $image->getAttribute('src');
|
||||
// Returns the image src
|
||||
return $imgSrc;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Email {
|
||||
|
||||
// Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
|
||||
public static function send($args)
|
||||
{
|
||||
// Current time in unixtimestamp
|
||||
$now = time();
|
||||
|
||||
// Domain
|
||||
$domainParse = parse_url(DOMAIN);
|
||||
|
||||
$headers = array();
|
||||
$headers[] = 'MIME-Version: 1.0';
|
||||
$headers[] = 'Content-type: text/html; charset=utf-8';
|
||||
$headers[] = 'Content-Transfer-Encoding: 8bit';
|
||||
|
||||
$headers[] = 'From: =?UTF-8?B?'.base64_encode($args['fromName']).'?= <'.$args['from'].'>';
|
||||
$headers[] = 'Reply-To: '.$args['from'];
|
||||
$headers[] = 'Return-Path: '.$args['from'];
|
||||
$headers[] = 'message-id: <'.$now.'webmaster@'.$domainParse['host'].'>';
|
||||
$headers[] = 'X-Mailer: PHP/'.phpversion();
|
||||
|
||||
$subject = '=?UTF-8?B?'.base64_encode($args['subject']).'?=';
|
||||
|
||||
$message = '<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>BLUDIT</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
'.$args['message'].'
|
||||
</div>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
return mail($args['to'], $subject, $message, implode(PHP_EOL, $headers));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Filesystem
|
||||
{
|
||||
|
||||
// Returns an array with the absolutes directories.
|
||||
public static function listDirectories($path, $regex = '*', $sortByDate = false)
|
||||
{
|
||||
$directories = glob($path . $regex, GLOB_ONLYDIR);
|
||||
|
||||
if (empty($directories)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ($sortByDate) {
|
||||
usort(
|
||||
$directories,
|
||||
function ($a, $b) {
|
||||
return filemtime($b) - filemtime($a);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return $directories;
|
||||
}
|
||||
|
||||
// Returns an array with the list of files with the absolute path
|
||||
// $sortByDate = TRUE, the first file is the newer file
|
||||
// $chunk = amount of chunks, FALSE if you don't want to chunk
|
||||
public static function listFiles($path, $regex = '*', $extension = '*', $sortByDate = false, $chunk = false)
|
||||
{
|
||||
$files = glob($path . $regex . '.' . $extension);
|
||||
|
||||
if (empty($files)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ($sortByDate) {
|
||||
usort(
|
||||
$files,
|
||||
function ($a, $b) {
|
||||
return filemtime($b) - filemtime($a);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Split the list of files into chunks
|
||||
// http://php.net/manual/en/function.array-chunk.php
|
||||
if ($chunk) {
|
||||
return array_chunk($files, $chunk);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
public static function mkdir($pathname, $recursive = false)
|
||||
{
|
||||
Log::set('mkdir ' . $pathname . ' recursive = ' . $recursive, LOG_TYPE_INFO);
|
||||
return mkdir($pathname, DIR_PERMISSIONS, $recursive);
|
||||
}
|
||||
|
||||
public static function rmdir($pathname)
|
||||
{
|
||||
Log::set('rmdir = ' . $pathname, LOG_TYPE_INFO);
|
||||
return rmdir($pathname);
|
||||
}
|
||||
|
||||
public static function mv($oldname, $newname)
|
||||
{
|
||||
Log::set('mv ' . $oldname . ' ' . $newname, LOG_TYPE_INFO);
|
||||
// Try renaming first (faster, works on same filesystem)
|
||||
if (@rename($oldname, $newname)) {
|
||||
return true;
|
||||
}
|
||||
// Fallback to copy+delete for cross-partition moves
|
||||
if (copy($oldname, $newname)) {
|
||||
if (unlink($oldname)) {
|
||||
return true;
|
||||
}
|
||||
// Copy succeeded but delete failed - remove the copy to avoid duplicates
|
||||
@unlink($newname);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function rmfile($filename)
|
||||
{
|
||||
Log::set('rmfile = ' . $filename, LOG_TYPE_INFO);
|
||||
return unlink($filename);
|
||||
}
|
||||
|
||||
public static function fileExists($filename)
|
||||
{
|
||||
return file_exists($filename);
|
||||
}
|
||||
|
||||
public static function directoryExists($path)
|
||||
{
|
||||
return file_exists($path);
|
||||
}
|
||||
|
||||
// Copy recursive a directory to another
|
||||
// If the destination directory not exists is created
|
||||
// $source = /home/diego/example or /home/diego/example/
|
||||
// $destination = /home/diego/newplace or /home/diego/newplace/
|
||||
public static function copyRecursive($source, $destination, $skipDirectory = false)
|
||||
{
|
||||
$source = rtrim($source, DS);
|
||||
$destination = rtrim($destination, DS);
|
||||
|
||||
// Check $source directory if exists
|
||||
if (!self::directoryExists($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check $destionation directory if exists
|
||||
if (!self::directoryExists($destination)) {
|
||||
// Create the $destination directory
|
||||
if (!mkdir($destination, DIR_PERMISSIONS, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
) as $item) {
|
||||
|
||||
$currentDirectory = dirname($item->getPathName());
|
||||
if ($skipDirectory !== $currentDirectory) {
|
||||
if ($item->isDir()) {
|
||||
@mkdir($destination . DS . $iterator->getSubPathName());
|
||||
} else {
|
||||
copy($item, $destination . DS . $iterator->getSubPathName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Delete a file or directory recursive
|
||||
// The directory is deleted
|
||||
public static function deleteRecursive($source, $deleteDirectory = true)
|
||||
{
|
||||
Log::set('deleteRecursive = ' . $source, LOG_TYPE_INFO);
|
||||
|
||||
if (!self::directoryExists($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
) as $item) {
|
||||
if ($item->isFile() || $item->isLink()) {
|
||||
unlink($item);
|
||||
} else {
|
||||
rmdir($item);
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleteDirectory) {
|
||||
return rmdir($source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Compress a file or directory
|
||||
// $source = /home/diego/example
|
||||
// $destionation = /tmp/example.zip
|
||||
public static function zip($source, $destination)
|
||||
{
|
||||
if (!extension_loaded('zip')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_dir($source) === true) {
|
||||
$iterator = new RecursiveDirectoryIterator($source);
|
||||
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file = realpath($file);
|
||||
if (is_dir($file)) {
|
||||
$zip->addEmptyDir(ltrim(str_replace($source, '', $file), "/\\"));
|
||||
} elseif (is_file($file)) {
|
||||
$zip->addFromString(ltrim(str_replace($source, '', $file), "/\\"), file_get_contents($file));
|
||||
}
|
||||
}
|
||||
} elseif (is_file($source)) {
|
||||
$zip->addFromString(basename($source), file_get_contents($source));
|
||||
}
|
||||
|
||||
return $zip->close();
|
||||
}
|
||||
|
||||
// Uncompress a zip file
|
||||
// $source = /home/diego/example.zip
|
||||
// $destionation = /home/diego/content
|
||||
public static function unzip($source, $destination)
|
||||
{
|
||||
if (!extension_loaded('zip')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if (!$zip->open($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$zip->extractTo($destination);
|
||||
return $zip->close();
|
||||
}
|
||||
|
||||
/*
|
||||
| Returns the next filename if the filename already exist otherwise returns the original filename
|
||||
|
|
||||
| @path string Path
|
||||
| @filename string Filename
|
||||
|
|
||||
| @return string
|
||||
*/
|
||||
public static function nextFilename($filename, $path = PATH_UPLOADS)
|
||||
{
|
||||
// Clean filename and get extension
|
||||
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
$fileExtension = Text::lowercase($fileExtension);
|
||||
$filename = pathinfo($filename, PATHINFO_FILENAME);
|
||||
$filename = Text::removeSpaces($filename);
|
||||
$filename = Text::removeQuotes($filename);
|
||||
|
||||
// Search for the next filename
|
||||
$tmpName = $filename . '.' . $fileExtension;
|
||||
if (Sanitize::pathFile($path . $tmpName)) {
|
||||
$number = 0;
|
||||
$tmpName = $filename . '_' . $number . '.' . $fileExtension;
|
||||
while (Sanitize::pathFile($path . $tmpName)) {
|
||||
$number = $number + 1;
|
||||
$tmpName = $filename . '_' . $number . '.' . $fileExtension;
|
||||
}
|
||||
}
|
||||
return $tmpName;
|
||||
}
|
||||
|
||||
/*
|
||||
| Returns the filename
|
||||
| Example:
|
||||
| @file /home/diego/dog.jpg
|
||||
| @return dog.jpg
|
||||
|
|
||||
| @file string Full path of the file
|
||||
|
|
||||
| @return string
|
||||
*/
|
||||
public static function filename($file)
|
||||
{
|
||||
return basename($file);
|
||||
}
|
||||
|
||||
/*
|
||||
| Returns the file extension
|
||||
| Example:
|
||||
| @file /home/diego/dog.jpg
|
||||
| @return jpg
|
||||
|
|
||||
| @file string Full path of the file
|
||||
|
|
||||
| @return string
|
||||
*/
|
||||
public static function extension($file)
|
||||
{
|
||||
return pathinfo($file, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Size of file or directory in bytes
|
||||
* @param [string] $fileOrDirectory
|
||||
* @return [int|bool] [bytes or false on error]
|
||||
*/
|
||||
public static function getSize($fileOrDirectory)
|
||||
{
|
||||
// Files
|
||||
if (is_file($fileOrDirectory)) {
|
||||
return filesize($fileOrDirectory);
|
||||
}
|
||||
// Directories
|
||||
if (file_exists($fileOrDirectory)) {
|
||||
$size = 0;
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fileOrDirectory, FilesystemIterator::SKIP_DOTS)) as $file) {
|
||||
try {
|
||||
$size += $file->getSize();
|
||||
} catch (Exception $e) {
|
||||
// SplFileInfo::getSize RuntimeException will be thrown on broken symlinks/errors
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function bytesToHumanFileSize($bytes, $decimals = 2)
|
||||
{
|
||||
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||
$factor = floor((strlen($bytes) - 1) / 3);
|
||||
return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
|
||||
}
|
||||
|
||||
/*
|
||||
| Returns the mime type of the file
|
||||
| Example:
|
||||
| @file /home/diego/dog.jpg
|
||||
| @return image/jpeg
|
||||
|
|
||||
| @file [string] Full path of the file
|
||||
|
|
||||
| @return [string|bool] Mime type as string or FALSE if not possible to get the mime type
|
||||
*/
|
||||
public static function mimeType($file)
|
||||
{
|
||||
if (function_exists('mime_content_type')) {
|
||||
return mime_content_type($file);
|
||||
}
|
||||
|
||||
if (function_exists('finfo_file')) {
|
||||
$fileinfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$mimeType = finfo_file($fileinfo, $file);
|
||||
finfo_close($fileinfo);
|
||||
return $mimeType;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function symlink($from, $to)
|
||||
{
|
||||
if (function_exists('symlink')) {
|
||||
Log::set('symlink from = ' . $from . ' to = ' . $to, LOG_TYPE_INFO);
|
||||
return symlink($from, $to);
|
||||
} else {
|
||||
return copy($from, $to);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Image {
|
||||
|
||||
private $image;
|
||||
private $width;
|
||||
private $height;
|
||||
private $imageResized;
|
||||
|
||||
public function setImage($fileName, $newWidth, $newHeight, $option="auto")
|
||||
{
|
||||
// *** Open up the file
|
||||
$this->image = $this->openImage($fileName);
|
||||
|
||||
// *** Check if image was opened successfully
|
||||
if ($this->image === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// *** Get width and height
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
|
||||
$this->resizeImage($newWidth, $newHeight, $option);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function saveImage($savePath, $imageQuality="100", $forceJPG=false, $forcePNG=false)
|
||||
{
|
||||
$extension = strtolower(pathinfo($savePath, PATHINFO_EXTENSION));
|
||||
|
||||
// Remove the extension
|
||||
$filename = substr($savePath, 0,strrpos($savePath,'.'));
|
||||
|
||||
if ($forcePNG) {
|
||||
$extension = 'png';
|
||||
} elseif ($forceJPG) {
|
||||
$extension = 'jpg';
|
||||
}
|
||||
|
||||
$path_complete = $filename.'.'.$extension;
|
||||
|
||||
switch ($extension) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
// Checking for JPG support
|
||||
if (imagetypes() & IMG_JPG) {
|
||||
imagejpeg($this->imageResized, $path_complete, $imageQuality);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'gif':
|
||||
// Checking for GIF support
|
||||
if (imagetypes() & IMG_GIF) {
|
||||
imagegif($this->imageResized, $path_complete);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
// *** Scale quality from 0-100 to 0-9
|
||||
$scaleQuality = round(($imageQuality/100) * 9);
|
||||
|
||||
// *** Invert quality setting as 0 is best, not 9
|
||||
$invertScaleQuality = 9 - $scaleQuality;
|
||||
|
||||
// Checking for PNG support
|
||||
if (imagetypes() & IMG_PNG) {
|
||||
imagepng($this->imageResized, $path_complete, $invertScaleQuality);
|
||||
}
|
||||
break;
|
||||
case 'webp':
|
||||
// Checking for WEBP support
|
||||
if (imagetypes() & IMG_WEBP) {
|
||||
imagewebp($this->imageResized, $path_complete, $imageQuality);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Fail extension detection
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function openImage($file)
|
||||
{
|
||||
// *** Get extension
|
||||
$extension = strtolower(strrchr($file, '.'));
|
||||
|
||||
// GD may be compiled without support for some formats (often WebP, and
|
||||
// sometimes JPEG on minimal builds). Guard each decoder with both a
|
||||
// runtime capability check and a function_exists() check to avoid a
|
||||
// fatal "call to undefined function" on stripped builds.
|
||||
$types = imagetypes();
|
||||
switch($extension)
|
||||
{
|
||||
case '.jpg':
|
||||
case '.jpeg':
|
||||
if (!($types & IMG_JPG) || !function_exists('imagecreatefromjpeg')) {
|
||||
return false;
|
||||
}
|
||||
$img = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case '.gif':
|
||||
if (!($types & IMG_GIF) || !function_exists('imagecreatefromgif')) {
|
||||
return false;
|
||||
}
|
||||
$img = imagecreatefromgif($file);
|
||||
break;
|
||||
case '.png':
|
||||
if (!($types & IMG_PNG) || !function_exists('imagecreatefrompng')) {
|
||||
return false;
|
||||
}
|
||||
$img = imagecreatefrompng($file);
|
||||
break;
|
||||
case '.webp':
|
||||
if (!($types & IMG_WEBP) || !function_exists('imagecreatefromwebp')) {
|
||||
return false;
|
||||
}
|
||||
$img = imagecreatefromwebp($file);
|
||||
break;
|
||||
default:
|
||||
$img = false;
|
||||
break;
|
||||
}
|
||||
return $img;
|
||||
}
|
||||
|
||||
private function resizeImage($newWidth, $newHeight, $option)
|
||||
{
|
||||
// *** Get optimal width and height - based on $option
|
||||
$optionArray = $this->getDimensions($newWidth, $newHeight, $option);
|
||||
|
||||
$optimalWidth = (int) $optionArray['optimalWidth'];
|
||||
$optimalHeight = (int) $optionArray['optimalHeight'];
|
||||
|
||||
|
||||
// *** Resample - create image canvas of x, y size
|
||||
$this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
|
||||
imagealphablending($this->imageResized, false);
|
||||
imagesavealpha($this->imageResized, true);
|
||||
imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
|
||||
|
||||
|
||||
// *** if option is 'crop', then crop too
|
||||
if ($option == 'crop') {
|
||||
$this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private function getDimensions($newWidth, $newHeight, $option)
|
||||
{
|
||||
|
||||
if( ($this->width < $newWidth) and ($this->height < $newHeight) )
|
||||
{
|
||||
return array('optimalWidth' => $this->width, 'optimalHeight' => $this->height);
|
||||
}
|
||||
|
||||
switch ($option)
|
||||
{
|
||||
case 'exact':
|
||||
$optimalWidth = $newWidth;
|
||||
$optimalHeight= $newHeight;
|
||||
break;
|
||||
case 'portrait':
|
||||
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
|
||||
$optimalHeight= $newHeight;
|
||||
break;
|
||||
case 'landscape':
|
||||
$optimalWidth = $newWidth;
|
||||
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
|
||||
break;
|
||||
case 'auto':
|
||||
$optionArray = $this->getSizeByAuto($newWidth, $newHeight);
|
||||
$optimalWidth = $optionArray['optimalWidth'];
|
||||
$optimalHeight = $optionArray['optimalHeight'];
|
||||
break;
|
||||
case 'crop':
|
||||
$optionArray = $this->getOptimalCrop($newWidth, $newHeight);
|
||||
$optimalWidth = $optionArray['optimalWidth'];
|
||||
$optimalHeight = $optionArray['optimalHeight'];
|
||||
break;
|
||||
default:
|
||||
$optionArray = $this->getSizeByAuto($newWidth, $newHeight);
|
||||
$optimalWidth = $optionArray['optimalWidth'];
|
||||
$optimalHeight = $optionArray['optimalHeight'];
|
||||
break;
|
||||
}
|
||||
|
||||
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
|
||||
}
|
||||
|
||||
private function getSizeByFixedHeight($newHeight)
|
||||
{
|
||||
$ratio = $this->width / $this->height;
|
||||
$newWidth = $newHeight * $ratio;
|
||||
return $newWidth;
|
||||
}
|
||||
|
||||
private function getSizeByFixedWidth($newWidth)
|
||||
{
|
||||
$ratio = $this->height / $this->width;
|
||||
$newHeight = $newWidth * $ratio;
|
||||
return $newHeight;
|
||||
}
|
||||
|
||||
private function getSizeByAuto($newWidth, $newHeight)
|
||||
{
|
||||
if ($this->height < $this->width)
|
||||
// *** Image to be resized is wider (landscape)
|
||||
{
|
||||
$optimalWidth = $newWidth;
|
||||
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
|
||||
}
|
||||
elseif ($this->height > $this->width)
|
||||
// *** Image to be resized is taller (portrait)
|
||||
{
|
||||
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
|
||||
$optimalHeight= $newHeight;
|
||||
}
|
||||
else
|
||||
// *** Image to be resizerd is a square
|
||||
{
|
||||
if ($newHeight < $newWidth) {
|
||||
$optimalWidth = $newWidth;
|
||||
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
|
||||
} else if ($newHeight > $newWidth) {
|
||||
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
|
||||
$optimalHeight= $newHeight;
|
||||
} else {
|
||||
// *** Sqaure being resized to a square
|
||||
$optimalWidth = $newWidth;
|
||||
$optimalHeight= $newHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
|
||||
}
|
||||
|
||||
private function getOptimalCrop($newWidth, $newHeight)
|
||||
{
|
||||
|
||||
$heightRatio = $this->height / $newHeight;
|
||||
$widthRatio = $this->width / $newWidth;
|
||||
|
||||
if ($heightRatio < $widthRatio) {
|
||||
$optimalRatio = $heightRatio;
|
||||
} else {
|
||||
$optimalRatio = $widthRatio;
|
||||
}
|
||||
|
||||
$optimalHeight = $this->height / $optimalRatio;
|
||||
$optimalWidth = $this->width / $optimalRatio;
|
||||
|
||||
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
|
||||
}
|
||||
|
||||
private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
|
||||
{
|
||||
// *** Find center - this will be used for the crop
|
||||
$cropStartX = (int) (( $optimalWidth / 2) - ( $newWidth /2 ));
|
||||
$cropStartY = (int) (( $optimalHeight/ 2) - ( $newHeight/2 ));
|
||||
|
||||
$crop = $this->imageResized;
|
||||
|
||||
// *** Now crop from center to exact requested size
|
||||
$this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
|
||||
imagealphablending($this->imageResized, false);
|
||||
imagesavealpha($this->imageResized, true);
|
||||
imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Log {
|
||||
|
||||
public static function set($text, $type=LOG_TYPE_INFO)
|
||||
{
|
||||
if (!DEBUG_MODE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$messageType = 0;
|
||||
if (is_array($text) ) {
|
||||
error_log('------------------------', $messageType);
|
||||
error_log('Array', $messageType);
|
||||
error_log('------------------------', $messageType);
|
||||
foreach ($text as $key=>$value) {
|
||||
error_log($key.'=>'.$value, $messageType);
|
||||
}
|
||||
error_log('------------------------', $messageType);
|
||||
}
|
||||
error_log($type.' ['.BLUDIT_VERSION.'] ['.$_SERVER['REQUEST_URI'].'] '.$text, $messageType);
|
||||
|
||||
if (DEBUG_TYPE=='TRACE') {
|
||||
error_log(print_r(debug_backtrace(), true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Paginator {
|
||||
|
||||
public static $pager = array(
|
||||
'itemsPerPage'=>0,
|
||||
'numberOfPages'=>1,
|
||||
'numberOfItems'=>0,
|
||||
'firstPage'=>1,
|
||||
'nextPage'=>1,
|
||||
'prevPage'=>1,
|
||||
'currentPage'=>1,
|
||||
'showPrev'=>false,
|
||||
'showNext'=>false,
|
||||
'showNextPrev'=>false
|
||||
);
|
||||
|
||||
public static function set($key, $value)
|
||||
{
|
||||
self::$pager[$key] = $value;
|
||||
}
|
||||
|
||||
public static function get($key)
|
||||
{
|
||||
return self::$pager[$key];
|
||||
}
|
||||
|
||||
public static function numberOfPages()
|
||||
{
|
||||
return self::get('numberOfPages');
|
||||
}
|
||||
|
||||
public static function currentPage()
|
||||
{
|
||||
return self::get('currentPage');
|
||||
}
|
||||
|
||||
public static function nextPage()
|
||||
{
|
||||
return self::get('nextPage');
|
||||
}
|
||||
|
||||
public static function prevPage()
|
||||
{
|
||||
return self::get('prevPage');
|
||||
}
|
||||
|
||||
public static function showNext()
|
||||
{
|
||||
return self::get('showNext');
|
||||
}
|
||||
|
||||
public static function showPrev()
|
||||
{
|
||||
return self::get('showPrev');
|
||||
}
|
||||
|
||||
public static function firstPage()
|
||||
{
|
||||
return self::get('firstPage');
|
||||
}
|
||||
|
||||
// Returns the absolute URL for the first page
|
||||
public static function firstPageUrl()
|
||||
{
|
||||
return self::numberUrl( self::firstPage() );
|
||||
}
|
||||
|
||||
// Returns the absolute URL for the last page
|
||||
public static function lastPageUrl()
|
||||
{
|
||||
return self::numberUrl( self::numberOfPages() );
|
||||
}
|
||||
|
||||
// Returns the absolute URL for the next page
|
||||
public static function nextPageUrl()
|
||||
{
|
||||
return self::numberUrl( self::nextPage() );
|
||||
}
|
||||
|
||||
// Returns the absolute URL for the previous page
|
||||
public static function previousPageUrl()
|
||||
{
|
||||
return self::numberUrl( self::prevPage() );
|
||||
}
|
||||
|
||||
// Return the absoulte URL with the page number
|
||||
public static function numberUrl($pageNumber)
|
||||
{
|
||||
global $url;
|
||||
|
||||
$domain = trim(DOMAIN_BASE,'/');
|
||||
$filter = trim($url->activeFilter(), '/');
|
||||
|
||||
if(empty($filter)) {
|
||||
$uri = $domain.'/'.$url->slug();
|
||||
}
|
||||
else {
|
||||
$uri = $domain.'/'.$filter.'/'.$url->slug();
|
||||
}
|
||||
|
||||
return $uri.'?page='.$pageNumber;
|
||||
}
|
||||
|
||||
public static function html($textPrevPage=false, $textNextPage=false, $showPageNumber=false)
|
||||
{
|
||||
global $L;
|
||||
|
||||
$html = '<div id="paginator">';
|
||||
$html .= '<ul>';
|
||||
|
||||
if(self::get('showNext'))
|
||||
{
|
||||
if($textPrevPage===false) {
|
||||
$textPrevPage = '« '.$L->g('Previous page');
|
||||
}
|
||||
|
||||
$html .= '<li class="left">';
|
||||
$html .= '<a href="'.self::nextPageUrl().'">'.$textPrevPage.'</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
if($showPageNumber) {
|
||||
$html .= '<li class="list">'.(self::get('currentPage')+1).' / '.(self::get('numberOfPages')+1).'</li>';
|
||||
}
|
||||
|
||||
if(self::get('showPrev'))
|
||||
{
|
||||
if($textNextPage===false) {
|
||||
$textNextPage = $L->g('Next page').' »';
|
||||
}
|
||||
|
||||
$html .= '<li class="right">';
|
||||
$html .= '<a href="'.self::previousPageUrl().'">'.$textNextPage.'</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bootstrap Pagination
|
||||
*/
|
||||
public static function bootstrap_html($textPrevPage=false, $textNextPage=false, $showPageNumber=false){
|
||||
|
||||
global $language;
|
||||
|
||||
$total_pages = self::numberOfPages();
|
||||
$howMany = 2;
|
||||
$currentPage = self::currentPage();
|
||||
$first_page = self::firstPage();
|
||||
$last_page = self::lastPageUrl();
|
||||
$show_next = (self::showNext()) ? "" : "disabled";
|
||||
$show_previois = (self::showPrev()) ? "" : "disabled";
|
||||
|
||||
$html = '<nav aria-label="Page navigation">';
|
||||
$html .= '<ul class="pagination">';
|
||||
if ($currentPage > 3 || $currentPage === $total_pages){
|
||||
$html .= '<li class="page-item">';
|
||||
$html .= '<a class="page-link" href="'.self::firstPageUrl().'" aria-label="First"><span aria-hidden="true">«</span> '.$language->get('First').'</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
if ($currentPage > 1){
|
||||
$html .= '<li class="page-item'.$show_previois.'">';
|
||||
$html .= '<a class="page-link" href="'.self::previousPageUrl().'" aria-label="Previous"><span aria-hidden="true">«</span> '.$language->get('Previous').'</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
if ($currentPage > $howMany + 1){
|
||||
$html .= '<li class="page-item disabled"><span>...</span></li>';
|
||||
}
|
||||
for ($pageIndex = $currentPage - $howMany; $pageIndex <= $currentPage + $howMany; $pageIndex++){
|
||||
|
||||
$active = ($pageIndex==self::currentPage()) ? "active" : false;
|
||||
|
||||
if ($pageIndex >= 1 && $pageIndex <= $total_pages){
|
||||
$html .= '<li class ="'.$active.'"><a href="'.self::numberUrl($pageIndex).'">'.$pageIndex.'</a></li>';
|
||||
}
|
||||
}
|
||||
if ($currentPage < $total_pages){
|
||||
$html .= '<li class="page-item disabled"><span>...</span></li>';
|
||||
}
|
||||
if ($currentPage < $total_pages){
|
||||
$html .= '<li class="page-item'.$show_next.'">';
|
||||
$html .= '<a class="page-link" href="'.self::nextPageUrl().'" aria-label="Next">'.$language->get('Next').' <span aria-hidden="true">»</span></a>';
|
||||
$html .= '</li>';
|
||||
$html .= '<li><a href="'.$last_page.'">'.$language->get('Last').'</a></li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
$html .= '</nav>';
|
||||
|
||||
return $html;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Redirect {
|
||||
|
||||
public static function url($url, $httpCode=301)
|
||||
{
|
||||
if (!headers_sent()) {
|
||||
header("Location: ".$url, TRUE, $httpCode);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
exit('<meta http-equiv="refresh" content="0; url='.$url.'"/>');
|
||||
}
|
||||
|
||||
public static function page($page)
|
||||
{
|
||||
self::url(HTML_PATH_ADMIN_ROOT.$page);
|
||||
}
|
||||
|
||||
public static function home()
|
||||
{
|
||||
self::url(HTML_PATH_ROOT);
|
||||
}
|
||||
|
||||
public static function admin()
|
||||
{
|
||||
self::url(HTML_PATH_ADMIN_ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Sanitize {
|
||||
|
||||
public static function removeTags($text) {
|
||||
return strip_tags($text);
|
||||
}
|
||||
|
||||
// Convert special characters to HTML entities
|
||||
public static function html($text)
|
||||
{
|
||||
$flags = ENT_COMPAT;
|
||||
|
||||
if (defined('ENT_HTML5')) {
|
||||
$flags = ENT_COMPAT|ENT_HTML5;
|
||||
}
|
||||
|
||||
return htmlspecialchars($text, $flags, CHARSET);
|
||||
}
|
||||
|
||||
// Convert special HTML entities back to characters
|
||||
public static function htmlDecode($text)
|
||||
{
|
||||
$flags = ENT_COMPAT;
|
||||
|
||||
if(defined('ENT_HTML5')) {
|
||||
$flags = ENT_COMPAT|ENT_HTML5;
|
||||
}
|
||||
|
||||
return htmlspecialchars_decode($text, $flags);
|
||||
}
|
||||
|
||||
public static function pathFile($path, $file=false)
|
||||
{
|
||||
if ($file!==false){
|
||||
$fullPath = $path.$file;
|
||||
} else {
|
||||
$fullPath = $path;
|
||||
}
|
||||
|
||||
// Fix for Windows on paths. eg: $path = c:\diego/page/subpage convert to c:\diego\page\subpages
|
||||
$fullPath = str_replace('/', DS, $fullPath);
|
||||
|
||||
if (CHECK_SYMBOLIC_LINKS) {
|
||||
$real = realpath($fullPath);
|
||||
} else {
|
||||
$real = file_exists($fullPath)?$fullPath:false;
|
||||
}
|
||||
|
||||
// If $real is FALSE the file does not exist.
|
||||
if ($real===false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Resolve the base directory to validate against path traversal.
|
||||
$basePath = realpath($path);
|
||||
if ($basePath===false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the resolved path does not start with the base directory then this is Path Traversal.
|
||||
if ($real !== $basePath && strpos($real, $basePath . DS) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns the email without illegal characters.
|
||||
public static function email($email)
|
||||
{
|
||||
return( filter_var($email, FILTER_SANITIZE_EMAIL) );
|
||||
}
|
||||
|
||||
public static function url($url)
|
||||
{
|
||||
return( filter_var($url, FILTER_SANITIZE_URL) );
|
||||
}
|
||||
|
||||
public static function int($value)
|
||||
{
|
||||
$value = (int)$value;
|
||||
|
||||
if($value>=0)
|
||||
return $value;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Session {
|
||||
|
||||
private static $started = false;
|
||||
private static $sessionName = 'BLUDIT-KEY';
|
||||
|
||||
public static function start($path, $secure)
|
||||
{
|
||||
// Try to set the session timeout on server side, 1 hour of timeout
|
||||
ini_set('session.gc_maxlifetime', SESSION_GC_MAXLIFETIME);
|
||||
|
||||
// If set to TRUE then PHP will attempt to send the httponly flag when setting the session cookie.
|
||||
$httponly = true;
|
||||
|
||||
// Gets current cookies params.
|
||||
$cookieParams = session_get_cookie_params();
|
||||
|
||||
if (empty($path)) {
|
||||
$httponly = true;
|
||||
$path = '/';
|
||||
}
|
||||
|
||||
session_set_cookie_params([
|
||||
'lifetime' => $cookieParams["lifetime"],
|
||||
'path' => $path,
|
||||
'domain' => $cookieParams["domain"],
|
||||
'secure' => $secure,
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax'
|
||||
]);
|
||||
|
||||
// Sets the session name to the one set above.
|
||||
// Use the __Secure- prefix when served over HTTPS to prevent cookie hijacking.
|
||||
$sessionName = $secure ? '__Secure-' . self::$sessionName : self::$sessionName;
|
||||
session_name($sessionName);
|
||||
|
||||
// Start session.
|
||||
self::$started = session_start();
|
||||
|
||||
// Regenerated the session, delete the old one. There are problems with AJAX.
|
||||
//session_regenerate_id(true);
|
||||
|
||||
if (!self::$started) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to start the session.');
|
||||
}
|
||||
}
|
||||
|
||||
public static function started()
|
||||
{
|
||||
return self::$started;
|
||||
}
|
||||
|
||||
public static function destroy()
|
||||
{
|
||||
$sessionName = session_name();
|
||||
session_destroy();
|
||||
unset($_SESSION);
|
||||
unset($_COOKIE[$sessionName]);
|
||||
Cookie::set($sessionName, '', -1);
|
||||
self::$started = false;
|
||||
Log::set(__METHOD__.LOG_SEP.'Session destroyed.');
|
||||
return !isset($_SESSION);
|
||||
}
|
||||
|
||||
public static function set($key, $value)
|
||||
{
|
||||
$key = 's_'.$key;
|
||||
|
||||
$_SESSION[$key] = $value;
|
||||
}
|
||||
|
||||
public static function get($key)
|
||||
{
|
||||
$key = 's_'.$key;
|
||||
|
||||
if (isset($_SESSION[$key])) {
|
||||
return $_SESSION[$key];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function remove($key)
|
||||
{
|
||||
$key = 's_'.$key;
|
||||
|
||||
unset($_SESSION[$key]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class TCP {
|
||||
|
||||
public static function http($url, $method='GET', $verifySSL=true, $timeOut=10, $followRedirections=true, $binary=true, $headers=false)
|
||||
{
|
||||
if (function_exists('curl_version')) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $followRedirections);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
|
||||
if ($method=='POST') {
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
}
|
||||
$output = curl_exec($ch);
|
||||
if ($output===false) {
|
||||
Log::set('Curl error: '.curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
} else {
|
||||
$options = array(
|
||||
'http'=>array(
|
||||
'method'=>$method,
|
||||
'timeout'=>$timeOut,
|
||||
'follow_location'=>$followRedirections
|
||||
),
|
||||
"ssl"=>array(
|
||||
"verify_peer"=>$verifySSL,
|
||||
"verify_peer_name"=>$verifySSL
|
||||
)
|
||||
);
|
||||
$stream = stream_context_create($options);
|
||||
$output = file_get_contents($url, false, $stream);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function download($url, $destination)
|
||||
{
|
||||
$data = self::http($url, $method='GET', $verifySSL=true, $timeOut=30, $followRedirections=true, $binary=true, $headers=false);
|
||||
return file_put_contents($destination, $data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Text {
|
||||
|
||||
private static $unicodeChars = array(
|
||||
// Latin
|
||||
'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'AE', 'Ç'=>'C',
|
||||
'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I',
|
||||
'Ð'=>'D', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ő'=>'O',
|
||||
'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ű'=>'U', 'Ý'=>'Y', 'Þ'=>'TH',
|
||||
'ß'=>'ss',
|
||||
'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'ae', 'ç'=>'c',
|
||||
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i',
|
||||
'ð'=>'d', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ő'=>'o',
|
||||
'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ü'=>'u', 'ű'=>'u', 'ý'=>'y', 'þ'=>'th',
|
||||
'ÿ'=>'y',
|
||||
// Latin symbols
|
||||
'©'=>'(c)',
|
||||
// Greek
|
||||
'Α'=>'A', 'Β'=>'B', 'Γ'=>'G', 'Δ'=>'D', 'Ε'=>'E', 'Ζ'=>'Z', 'Η'=>'H', 'Θ'=>'8',
|
||||
'Ι'=>'I', 'Κ'=>'K', 'Λ'=>'L', 'Μ'=>'M', 'Ν'=>'N', 'Ξ'=>'3', 'Ο'=>'O', 'Π'=>'P',
|
||||
'Ρ'=>'R', 'Σ'=>'S', 'Τ'=>'T', 'Υ'=>'Y', 'Φ'=>'F', 'Χ'=>'X', 'Ψ'=>'PS', 'Ω'=>'W',
|
||||
'Ά'=>'A', 'Έ'=>'E', 'Ί'=>'I', 'Ό'=>'O', 'Ύ'=>'Y', 'Ή'=>'H', 'Ώ'=>'W', 'Ϊ'=>'I',
|
||||
'Ϋ'=>'Y',
|
||||
'α'=>'a', 'β'=>'b', 'γ'=>'g', 'δ'=>'d', 'ε'=>'e', 'ζ'=>'z', 'η'=>'h', 'θ'=>'8',
|
||||
'ι'=>'i', 'κ'=>'k', 'λ'=>'l', 'μ'=>'m', 'ν'=>'n', 'ξ'=>'3', 'ο'=>'o', 'π'=>'p',
|
||||
'ρ'=>'r', 'σ'=>'s', 'τ'=>'t', 'υ'=>'y', 'φ'=>'f', 'χ'=>'x', 'ψ'=>'ps', 'ω'=>'w',
|
||||
'ά'=>'a', 'έ'=>'e', 'ί'=>'i', 'ό'=>'o', 'ύ'=>'y', 'ή'=>'h', 'ώ'=>'w', 'ς'=>'s',
|
||||
'ϊ'=>'i', 'ΰ'=>'y', 'ϋ'=>'y', 'ΐ'=>'i',
|
||||
// Turkish
|
||||
'Ş'=>'S', 'İ'=>'I', 'Ç'=>'C', 'Ü'=>'U', 'Ö'=>'O', 'Ğ'=>'G',
|
||||
'ş'=>'s', 'ı'=>'i', 'ç'=>'c', 'ü'=>'u', 'ö'=>'o', 'ğ'=>'g',
|
||||
// Russian
|
||||
'А'=>'A', 'Б'=>'B', 'В'=>'V', 'Г'=>'G', 'Д'=>'D', 'Е'=>'E', 'Ё'=>'Yo', 'Ж'=>'Zh',
|
||||
'З'=>'Z', 'И'=>'I', 'Й'=>'J', 'К'=>'K', 'Л'=>'L', 'М'=>'M', 'Н'=>'N', 'О'=>'O',
|
||||
'П'=>'P', 'Р'=>'R', 'С'=>'S', 'Т'=>'T', 'У'=>'U', 'Ф'=>'F', 'Х'=>'H', 'Ц'=>'C',
|
||||
'Ч'=>'Ch', 'Ш'=>'Sh', 'Щ'=>'Sh', 'Ъ'=>'', 'Ы'=>'Y', 'Ь'=>'', 'Э'=>'E', 'Ю'=>'Yu',
|
||||
'Я'=>'Ya',
|
||||
'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ё'=>'yo', 'ж'=>'zh',
|
||||
'з'=>'z', 'и'=>'i', 'й'=>'j', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o',
|
||||
'п'=>'p', 'р'=>'r', 'с'=>'s', 'т'=>'t', 'у'=>'u', 'ф'=>'f', 'х'=>'h', 'ц'=>'c',
|
||||
'ч'=>'ch', 'ш'=>'sh', 'щ'=>'sh', 'ъ'=>'', 'ы'=>'y', 'ь'=>'', 'э'=>'e', 'ю'=>'yu',
|
||||
'я'=>'ya',
|
||||
// Bulgarian
|
||||
'А'=>'A', 'Б'=>'B', 'В'=>'V', 'Г'=>'G', 'Д'=>'D', 'Е'=>'E', 'Ж'=>'Zh', 'З'=>'Z',
|
||||
'И'=>'I', 'Й'=>'J', 'К'=>'K', 'Л'=>'L', 'М'=>'M', 'Н'=>'N', 'О'=>'O', 'П'=>'P',
|
||||
'Р'=>'R', 'С'=>'S', 'Т'=>'T', 'У'=>'U', 'Ф'=>'F', 'Х'=>'H', 'Ц'=>'C', 'Ч'=>'Ch',
|
||||
'Ш'=>'Sh', 'Щ'=>'Sh', 'Ъ'=>'', 'Ь'=>'J','Ю'=>'Yu','Я'=>'Ya',
|
||||
'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ж'=>'zh','з'=>'z',
|
||||
'и'=>'i', 'й'=>'j', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o','п'=>'p',
|
||||
'р'=>'r', 'с'=>'s', 'т'=>'t', 'у'=>'u', 'ф'=>'f', 'х'=>'h', 'ц'=>'c', 'ч'=>'ch',
|
||||
'ш'=>'sh', 'щ'=>'sh', 'ъ'=>'', 'ь'=>'j', 'ю'=>'yu', 'я'=>'ya',
|
||||
// Ukrainian
|
||||
'Є'=>'Ye', 'І'=>'I', 'Ї'=>'Yi', 'Ґ'=>'G',
|
||||
'є'=>'ye', 'і'=>'i', 'ї'=>'yi', 'ґ'=>'g',
|
||||
// Czech
|
||||
'Č'=>'C', 'Ď'=>'D', 'Ě'=>'E', 'Ň'=>'N', 'Ř'=>'R', 'Š'=>'S', 'Ť'=>'T', 'Ů'=>'U',
|
||||
'Ž'=>'Z',
|
||||
'č'=>'c', 'ď'=>'d', 'ě'=>'e', 'ň'=>'n', 'ř'=>'r', 'š'=>'s', 'ť'=>'t', 'ů'=>'u',
|
||||
'ž'=>'z',
|
||||
// Polish
|
||||
'Ą'=>'A', 'Ć'=>'C', 'Ę'=>'e', 'Ł'=>'L', 'Ń'=>'N', 'Ó'=>'o', 'Ś'=>'S', 'Ź'=>'Z',
|
||||
'Ż'=>'Z',
|
||||
'ą'=>'a', 'ć'=>'c', 'ę'=>'e', 'ł'=>'l', 'ń'=>'n', 'ó'=>'o', 'ś'=>'s', 'ź'=>'z',
|
||||
'ż'=>'z',
|
||||
// Latvian
|
||||
'Ā'=>'A', 'Č'=>'C', 'Ē'=>'E', 'Ģ'=>'G', 'Ī'=>'i', 'Ķ'=>'k', 'Ļ'=>'L', 'Ņ'=>'N',
|
||||
'Š'=>'S', 'Ū'=>'u', 'Ž'=>'Z',
|
||||
'ā'=>'a', 'č'=>'c', 'ē'=>'e', 'ģ'=>'g', 'ī'=>'i', 'ķ'=>'k', 'ļ'=>'l', 'ņ'=>'n',
|
||||
'š'=>'s', 'ū'=>'u', 'ž'=>'z'
|
||||
);
|
||||
|
||||
public static function addSlashes($string, $begin=true, $end=true)
|
||||
{
|
||||
if ($begin) {
|
||||
$string = '/'.ltrim($string, '/');
|
||||
}
|
||||
|
||||
if ($end) {
|
||||
$string = rtrim($string, '/').'/';
|
||||
}
|
||||
|
||||
if ($string=='//') {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
// Escape quotes and backslash
|
||||
public static function escapeQuotes($string)
|
||||
{
|
||||
return addslashes($string);
|
||||
}
|
||||
|
||||
public static function startsWith($string, $startString)
|
||||
{
|
||||
$length = self::length($startString);
|
||||
|
||||
return( mb_substr($string, 0, $length)===$startString );
|
||||
}
|
||||
|
||||
public static function endsWith($string, $endsString)
|
||||
{
|
||||
$length = (-1) * self::length($endsString);
|
||||
return (mb_substr($string, $length) === $endsString);
|
||||
}
|
||||
|
||||
public static function endsWithNumeric($string)
|
||||
{
|
||||
return( is_numeric(mb_substr($string, -1, 1)) );
|
||||
}
|
||||
|
||||
public static function randomText($length)
|
||||
{
|
||||
$characteres = "1234567890abcdefghijklmnopqrstuvwxyz!@#%^&*";
|
||||
$text = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$text .= $characteres[random_int(0, strlen($characteres) - 1)];
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
public static function replaceAssoc(array $replace, $text)
|
||||
{
|
||||
return str_replace(array_keys($replace), array_values($replace), $text);
|
||||
}
|
||||
|
||||
public static function removeSpecialCharacters($string, $replace='')
|
||||
{
|
||||
return preg_replace("/[\/_|+:!@#$%^&*()'\"<>\\\`}{;=,?\[\]~. -]+/", $replace, $string);
|
||||
}
|
||||
|
||||
public static function removeQuotes($string, $replace='')
|
||||
{
|
||||
$remove = array('\''=>$replace, '"'=>$replace);
|
||||
return self::replaceAssoc($remove, $string);
|
||||
}
|
||||
|
||||
public static function removeLineBreaks($string)
|
||||
{
|
||||
$remove = array("\r"=>'', "\n"=>'');
|
||||
return self::replaceAssoc($remove, $string);
|
||||
}
|
||||
|
||||
public static function removeSpaces($string, $replace='')
|
||||
{
|
||||
$remove = array(' '=>$replace);
|
||||
return self::replaceAssoc($remove, $string);
|
||||
}
|
||||
|
||||
// Convert unicode characters to utf-8 characters
|
||||
// Characters that cannot be converted will be removed from the string
|
||||
// This function can return an empty string
|
||||
public static function cleanUrl($string, $separator='-')
|
||||
{
|
||||
global $L;
|
||||
|
||||
if (EXTREME_FRIENDLY_URL) {
|
||||
$string = self::lowercase($string);
|
||||
$string = trim($string, $separator);
|
||||
$string = self::removeSpecialCharacters($string, $separator);
|
||||
$string = self::removeLineBreaks($string);
|
||||
$string = trim($string, $separator);
|
||||
return $string;
|
||||
}
|
||||
|
||||
// Transliterate characters to ASCII
|
||||
$unicodeCharsFromDictionary = $L->getunicodeChars();
|
||||
$string = str_replace(array_keys($unicodeCharsFromDictionary), $unicodeCharsFromDictionary, $string);
|
||||
$string = str_replace(array_keys(self::$unicodeChars), self::$unicodeChars, $string);
|
||||
|
||||
if (function_exists('iconv')) {
|
||||
if (@iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string)!==false) {
|
||||
$string = iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string);
|
||||
}
|
||||
}
|
||||
|
||||
$string = preg_replace("/[^a-zA-Z0-9\/_|+. -]/", '', $string);
|
||||
$string = self::lowercase($string);
|
||||
$string = preg_replace("/[\/_|+ -]+/", $separator, $string);
|
||||
$string = trim($string, '-');
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
// Replace all occurrences of the search string with the replacement string.
|
||||
// replace("%body%", "black", "<body text='%body%'>");
|
||||
public static function replace($search, $replace, $string)
|
||||
{
|
||||
return str_replace($search,$replace,$string);
|
||||
}
|
||||
|
||||
// String to lowercase
|
||||
public static function lowercase($string)
|
||||
{
|
||||
return mb_strtolower($string, CHARSET);
|
||||
}
|
||||
|
||||
// Make a string's first character uppercase
|
||||
public static function firstCharUp($string)
|
||||
{
|
||||
// Thanks http://stackoverflow.com/questions/2517947/ucfirst-function-for-multibyte-character-encodings
|
||||
$strlen = mb_strlen($string, CHARSET);
|
||||
$firstChar = mb_substr($string, 0, 1, CHARSET);
|
||||
$then = mb_substr($string, 1, $strlen - 1, CHARSET);
|
||||
|
||||
return mb_strtoupper($firstChar, CHARSET).$then;
|
||||
}
|
||||
|
||||
// Find position of first occurrence of substring in a string otherwise returns FALSE.
|
||||
public static function stringPosition($string, $substring, $caseSensitive=true)
|
||||
{
|
||||
if ($caseSensitive) {
|
||||
return mb_strpos($string, $substring, 0, CHARSET);
|
||||
}
|
||||
|
||||
return mb_stripos($string, $substring, 0, CHARSET);
|
||||
}
|
||||
|
||||
public static function stringContains($string, $substring, $caseSensitive=true)
|
||||
{
|
||||
return (self::stringPosition($string, $substring, $caseSensitive) !== false);
|
||||
}
|
||||
|
||||
// Returns the portion of string specified by the start and length parameters.
|
||||
public static function cut($string, $start, $length)
|
||||
{
|
||||
$cut = mb_substr($string, $start, $length, CHARSET);
|
||||
|
||||
if(empty($cut)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $cut;
|
||||
}
|
||||
|
||||
public static function removeHTMLTags($string)
|
||||
{
|
||||
return strip_tags($string);
|
||||
}
|
||||
|
||||
// Return string length
|
||||
public static function length($string)
|
||||
{
|
||||
return mb_strlen($string, CHARSET);
|
||||
}
|
||||
|
||||
public static function isEmpty($string)
|
||||
{
|
||||
$string = trim($string);
|
||||
|
||||
if(empty($string)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isNotEmpty($string)
|
||||
{
|
||||
return !self::isEmpty($string);
|
||||
}
|
||||
|
||||
public static function imgRel2Abs($string, $base)
|
||||
{
|
||||
$pattern = '/<img([^>]*)(src)=\"(?!https:)(?!http:)(?!\/\/)(.*?)\"(.*?)>/';
|
||||
$replace = "<img\${1} src=\"".$base."\${3}\" \${4}>";
|
||||
|
||||
return preg_replace($pattern, $replace, $string);
|
||||
}
|
||||
|
||||
public static function pre2htmlentities($string)
|
||||
{
|
||||
return preg_replace_callback('/<pre.*?><code(.*?)>(.*?)<\/code><\/pre>/imsu',
|
||||
function ($input) {
|
||||
return "<pre><code $input[1]>".htmlentities($input[2])."</code></pre>";
|
||||
},
|
||||
$string);
|
||||
}
|
||||
|
||||
// Truncates the string under the limit specified by the limit parameter
|
||||
public static function truncate($string, $limit, $end='...')
|
||||
{
|
||||
// Check if over $limit
|
||||
if (mb_strlen($string) > $limit) {
|
||||
$truncate = trim(mb_substr($string, 0, $limit, CHARSET));
|
||||
$truncate = $truncate.$end;
|
||||
} else {
|
||||
$truncate = $string;
|
||||
}
|
||||
|
||||
if (empty($truncate)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $truncate;
|
||||
}
|
||||
|
||||
public static function toBytes($value) {
|
||||
$value = trim($value);
|
||||
$s = [ 'g'=> 1<<30, 'm' => 1<<20, 'k' => 1<<10 ];
|
||||
return intval($value) * ($s[strtolower(substr($value,-1))] ?: 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
class Theme
|
||||
{
|
||||
|
||||
public static function socialNetworks()
|
||||
{
|
||||
global $site;
|
||||
$socialNetworks = array(
|
||||
'github' => 'Github',
|
||||
'gitlab' => 'GitLab',
|
||||
'twitter' => 'Twitter',
|
||||
'facebook' => 'Facebook',
|
||||
'instagram' => 'Instagram',
|
||||
'codepen' => 'Codepen',
|
||||
'linkedin' => 'Linkedin',
|
||||
'xing' => 'Xing',
|
||||
'telegram' => 'Telegram',
|
||||
'mastodon' => 'Mastodon',
|
||||
'vk' => 'VK',
|
||||
'dribbble' => 'Dribbble',
|
||||
'youtube' => 'Youtube',
|
||||
'bluesky' => 'Bluesky'
|
||||
);
|
||||
|
||||
foreach ($socialNetworks as $key => $label) {
|
||||
if (!$site->{$key}()) {
|
||||
unset($socialNetworks[$key]);
|
||||
}
|
||||
}
|
||||
return $socialNetworks;
|
||||
}
|
||||
|
||||
public static function title()
|
||||
{
|
||||
global $site;
|
||||
return $site->title();
|
||||
}
|
||||
|
||||
public static function description()
|
||||
{
|
||||
global $site;
|
||||
return $site->description();
|
||||
}
|
||||
|
||||
public static function slogan()
|
||||
{
|
||||
global $site;
|
||||
return $site->slogan();
|
||||
}
|
||||
|
||||
public static function footer()
|
||||
{
|
||||
global $site;
|
||||
return $site->footer();
|
||||
}
|
||||
|
||||
public static function lang()
|
||||
{
|
||||
global $language;
|
||||
return $language->currentLanguageShortVersion();
|
||||
}
|
||||
|
||||
public static function rssUrl()
|
||||
{
|
||||
if (pluginActivated('pluginRSS')) {
|
||||
return DOMAIN_BASE . 'rss.xml';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function sitemapUrl()
|
||||
{
|
||||
if (pluginActivated('pluginSitemap')) {
|
||||
return DOMAIN_BASE . 'sitemap.xml';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns the absolute URL of the site
|
||||
// Ex. https://example.com the method returns https://example.com/
|
||||
// Ex. https://example.com/bludit/ the method returns https://example.com/bludit/
|
||||
public static function siteUrl()
|
||||
{
|
||||
return DOMAIN_BASE;
|
||||
}
|
||||
|
||||
// Returns the absolute URL of admin panel
|
||||
// Ex. https://example.com/admin/ the method returns https://example.com/admin/
|
||||
// Ex. https://example.com/bludit/admin/ the method returns https://example.com/bludit/admin/
|
||||
public static function adminUrl()
|
||||
{
|
||||
return DOMAIN_ADMIN;
|
||||
}
|
||||
|
||||
public static function metaTags($tag)
|
||||
{
|
||||
if ($tag == 'title') {
|
||||
return self::metaTagTitle();
|
||||
} elseif ($tag == 'description') {
|
||||
return self::metaTagDescription();
|
||||
}
|
||||
}
|
||||
|
||||
public static function metaTagTitle()
|
||||
{
|
||||
global $url;
|
||||
global $site;
|
||||
global $tags;
|
||||
global $categories;
|
||||
global $WHERE_AM_I;
|
||||
global $page;
|
||||
|
||||
if ($WHERE_AM_I == 'page') {
|
||||
$format = $site->titleFormatPages();
|
||||
$format = Text::replace('{{page-title}}', $page->title(), $format);
|
||||
$format = Text::replace('{{page-description}}', $page->description(), $format);
|
||||
} elseif ($WHERE_AM_I == 'tag') {
|
||||
try {
|
||||
$tagKey = $url->slug();
|
||||
$tag = new Tag($tagKey);
|
||||
$format = $site->titleFormatTag();
|
||||
$format = Text::replace('{{tag-name}}', $tag->name(), $format);
|
||||
} catch (Exception $e) {
|
||||
// Tag doesn't exist
|
||||
}
|
||||
} elseif ($WHERE_AM_I == 'category') {
|
||||
try {
|
||||
$categoryKey = $url->slug();
|
||||
$category = new Category($categoryKey);
|
||||
$format = $site->titleFormatCategory();
|
||||
$format = Text::replace('{{category-name}}', $category->name(), $format);
|
||||
} catch (Exception $e) {
|
||||
// Category doesn't exist
|
||||
}
|
||||
} else {
|
||||
$format = $site->titleFormatHomepage();
|
||||
}
|
||||
|
||||
$format = Text::replace('{{site-title}}', $site->title(), $format);
|
||||
$format = Text::replace('{{site-slogan}}', $site->slogan(), $format);
|
||||
$format = Text::replace('{{site-description}}', $site->description(), $format);
|
||||
|
||||
return '<title>' . $format . '</title>' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function metaTagDescription()
|
||||
{
|
||||
global $site;
|
||||
global $WHERE_AM_I;
|
||||
global $page;
|
||||
global $url;
|
||||
|
||||
$description = $site->description();
|
||||
|
||||
if ($WHERE_AM_I == 'page') {
|
||||
$description = $page->description();
|
||||
} elseif ($WHERE_AM_I == 'category') {
|
||||
try {
|
||||
$categoryKey = $url->slug();
|
||||
$category = new Category($categoryKey);
|
||||
$description = $category->description();
|
||||
} catch (Exception $e) {
|
||||
// description from the site
|
||||
}
|
||||
}
|
||||
|
||||
return '<meta name="description" content="' . $description . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
// DEPRECATED v3.0.0
|
||||
// Return the metatag <title> with a predefine structure
|
||||
public static function headTitle()
|
||||
{
|
||||
return self::metaTagTitle();
|
||||
}
|
||||
|
||||
// DEPRECATED v3.0.0
|
||||
// Return the metatag <decription> with a predefine structure
|
||||
public static function headDescription()
|
||||
{
|
||||
return self::metaTagDescription();
|
||||
}
|
||||
|
||||
public static function charset($charset)
|
||||
{
|
||||
return '<meta charset="' . $charset . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function viewport($content)
|
||||
{
|
||||
return '<meta name="viewport" content="' . $content . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function src($file, $base = DOMAIN_THEME)
|
||||
{
|
||||
return $base . $file;
|
||||
}
|
||||
|
||||
public static function css($files, $base = DOMAIN_THEME)
|
||||
{
|
||||
if (!is_array($files)) {
|
||||
$files = array($files);
|
||||
}
|
||||
|
||||
$links = '';
|
||||
foreach ($files as $file) {
|
||||
$links .= '<link rel="stylesheet" type="text/css" href="' . $base . $file . '?version=' . BLUDIT_VERSION . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public static function javascript($files, $base = DOMAIN_THEME, $attributes = '')
|
||||
{
|
||||
if (!is_array($files)) {
|
||||
$files = array($files);
|
||||
}
|
||||
|
||||
$scripts = '';
|
||||
foreach ($files as $file) {
|
||||
$scripts .= '<script ' . $attributes . ' src="' . $base . $file . '?version=' . BLUDIT_VERSION . '"></script>' . PHP_EOL;
|
||||
}
|
||||
|
||||
return $scripts;
|
||||
}
|
||||
|
||||
public static function js($files, $base = DOMAIN_THEME, $attributes = '')
|
||||
{
|
||||
return self::javascript($files, $base, $attributes);
|
||||
}
|
||||
|
||||
public static function plugins($type, $args = array())
|
||||
{
|
||||
global $plugins;
|
||||
foreach ($plugins[$type] as $plugin) {
|
||||
echo call_user_func_array(array($plugin, $type), $args);
|
||||
}
|
||||
}
|
||||
|
||||
public static function favicon($file = 'favicon.png', $typeIcon = 'image/png')
|
||||
{
|
||||
return '<link rel="icon" href="' . DOMAIN_THEME . $file . '" type="' . $typeIcon . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function keywords($keywords)
|
||||
{
|
||||
if (is_array($keywords)) {
|
||||
$keywords = implode(',', $keywords);
|
||||
}
|
||||
return '<meta name="keywords" content="' . $keywords . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function jquery()
|
||||
{
|
||||
return '<script src="' . DOMAIN_CORE_JS . 'jquery.min.js?version=' . BLUDIT_VERSION . '"></script>' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function jsBootstrap($attributes = '')
|
||||
{
|
||||
return '<script ' . $attributes . ' src="' . DOMAIN_CORE_JS . 'bootstrap.bundle.min.js?version=' . BLUDIT_VERSION . '"></script>' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function cssBootstrap()
|
||||
{
|
||||
return '<link rel="stylesheet" type="text/css" href="' . DOMAIN_CORE_CSS . 'bootstrap.min.css?version=' . BLUDIT_VERSION . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function cssBootstrapIcons()
|
||||
{
|
||||
// https://icons.getbootstrap.com/
|
||||
return '<link rel="stylesheet" type="text/css" href="' . DOMAIN_CORE_CSS . 'bootstrap-icons/bootstrap-icons.css?version=' . BLUDIT_VERSION . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function cssLineAwesome()
|
||||
{
|
||||
return '<link rel="stylesheet" type="text/css" href="' . DOMAIN_CORE_CSS . 'line-awesome/css/line-awesome-font-awesome.min.css?version=' . BLUDIT_VERSION . '">' . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function jsSortable($attributes = '')
|
||||
{
|
||||
// https://github.com/psfpro/bootstrap-html5sortable
|
||||
return '<script ' . $attributes . ' src="' . DOMAIN_CORE_JS . 'jquery.sortable.min.js?version=' . BLUDIT_VERSION . '"></script>' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class Valid {
|
||||
|
||||
public static function ip($ip)
|
||||
{
|
||||
return filter_var($ip, FILTER_VALIDATE_IP);
|
||||
}
|
||||
|
||||
// Returns the email filtered or FALSE if the filter fails.
|
||||
public static function email($email)
|
||||
{
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
|
||||
public static function int($int)
|
||||
{
|
||||
if($int === 0) {
|
||||
return true;
|
||||
}
|
||||
elseif(filter_var($int, FILTER_VALIDATE_INT) === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Thanks, http://php.net/manual/en/function.checkdate.php#113205
|
||||
public static function date($date, $format='Y-m-d H:i:s')
|
||||
{
|
||||
$tmp = DateTime::createFromFormat($format, $date);
|
||||
|
||||
return $tmp && $tmp->format($format)==$date;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user