first commit
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Modified for Template Creator CK by Cédric KEIFLIN
|
||||
* @copyright Copyright (C) 2011 Cédric KEIFLIN alias ced1870
|
||||
* https://www.template-creator.com
|
||||
* Component Template Creator CK
|
||||
* @license GNU/GPL
|
||||
* */
|
||||
// No direct access
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
include_once PAGEBUILDERCK_PATH . '/helpers/zip.php';
|
||||
|
||||
class ZipArchiver extends stdClass {
|
||||
/* creates a compressed zip file */
|
||||
|
||||
function create($files = array(), $destination = '', $path = '', $overwrite = true) {
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$files = Pagebuilderck\CKFolder::files($path, false, true, true);
|
||||
|
||||
if (file_exists($path . $destination) && !$overwrite) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check to see if directory for archive exists
|
||||
if (!Pagebuilderck\CKFolder::exists($path)) {
|
||||
// Try to create the directory if it does not exists
|
||||
if (!Pagebuilderck\CKFolder::create($path)) {
|
||||
// Raise error, unable to create dir
|
||||
$this->setError('Unable to create directory for archive');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if archive exists
|
||||
// $archiveFilePath = $path . $destination;
|
||||
if (file_exists($destination)) {
|
||||
// If overwrite flag is set
|
||||
if ($overwrite) {
|
||||
// Delete archive
|
||||
Pagebuilderck\CKFile::delete($destination);
|
||||
} else {
|
||||
// Set error and return
|
||||
$this->setError('Archive exists');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare files for the zip archiver
|
||||
$filesToZip = array();
|
||||
$path = $this->cleanPath($path);
|
||||
foreach ($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
$file = $this->cleanPath($file);
|
||||
$filename = str_replace($path . '/', '', $file);
|
||||
$filesToZip[] = array(
|
||||
'data' => file_get_contents($file),
|
||||
'name' => $filename
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Create ZIP archiver
|
||||
$archiver = new CKArchiveZip();
|
||||
|
||||
// Create Archive
|
||||
$isSuccess = $archiver->create($destination, $filesToZip);
|
||||
|
||||
// Check of operation was successful
|
||||
if (!$isSuccess) {
|
||||
// Set Error
|
||||
$this->setError('Unable to create archive');
|
||||
}
|
||||
|
||||
//
|
||||
return $isSuccess;
|
||||
}
|
||||
|
||||
protected function cleanPath($path) {
|
||||
// $ds = DIRECTORY_SEPARATOR;
|
||||
// $path = str_replace("/", $ds, $path);
|
||||
$path = str_replace("\\", '/', $path);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
}
|
||||
384
administrator/components/com_pagebuilderck/helpers/ckbrowse.php
Normal file
384
administrator/components/com_pagebuilderck/helpers/ckbrowse.php
Normal file
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @package com_pagebuilderck
|
||||
* @copyright Copyright (C) 2016. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
use Pagebuilderck\CKPath;
|
||||
use Pagebuilderck\CKFolder;
|
||||
use Pagebuilderck\CKFile;
|
||||
use Pagebuilderck\CKFof;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Object\CMSObject;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
class CKBrowse {
|
||||
|
||||
static $isRestrictedUser = false;
|
||||
|
||||
public static function getFileTypes($type, $auto = true) {
|
||||
$input = JFactory::getApplication()->input;
|
||||
$type = $auto ? $input->get('type', $type, 'string') : $type;
|
||||
|
||||
switch ($type) {
|
||||
case 'video' :
|
||||
$filetypes = array('.mp4', '.ogv', '.webm', '.MP4', '.OGV', '.WEBM');
|
||||
break;
|
||||
case 'audio' :
|
||||
$filetypes = array('.mp3', '.ogg', '.MP3', '.OGG');
|
||||
break;
|
||||
case 'image' :
|
||||
default :
|
||||
$filetypes = array('.jpg', '.jpeg', '.png', '.gif', '.tiff', '.JPG', '.JPEG', '.PNG', '.GIF', '.TIFF', '.ico', '.svg', '.webp', '.WEBP');
|
||||
break;
|
||||
case 'all' :
|
||||
case 'files' :
|
||||
$filetypes = array('.pdf', '.jpg', '.jpeg', '.png', '.gif', '.tiff', '.JPG', '.JPEG', '.PNG', '.GIF', '.TIFF', '.ico', '.svg', '.mp3', '.ogg', '.MP3', '.OGG', '.mp4', '.ogv', '.webm', '.MP4', '.OGV', '.WEBM', '.WEBP', '.webp', '.zip');
|
||||
break;
|
||||
}
|
||||
|
||||
return $filetypes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a list of folders and files
|
||||
*/
|
||||
public static function getItemsList($type = 'image') {
|
||||
$input = JFactory::getApplication()->input;
|
||||
|
||||
$type = $input->get('type', $type, 'string');
|
||||
|
||||
$filetypes = self::getFileTypes($type);
|
||||
// switch ($type) {
|
||||
// case 'video' :
|
||||
// $filetypes = array('.mp4', '.ogv', '.webm', '.MP4', '.OGV', '.WEBM');
|
||||
// break;
|
||||
// case 'audio' :
|
||||
// $filetypes = array('.mp3', '.ogg', '.MP3', '.OGG');
|
||||
// break;
|
||||
// case 'image' :
|
||||
// default :
|
||||
// $filetypes = array('.jpg', '.jpeg', '.png', '.gif', '.tiff', '.JPG', '.JPEG', '.PNG', '.GIF', '.TIFF', '.ico', '.svg', '.WEBP', '.webp');
|
||||
// break;
|
||||
// case 'all' :
|
||||
// case 'files' :
|
||||
// $filetypes = array('.pdf', '.jpg', '.jpeg', '.png', '.gif', '.tiff', '.JPG', '.JPEG', '.PNG', '.GIF', '.TIFF', '.ico', '.svg', '.mp3', '.ogg', '.MP3', '.OGG', '.mp4', '.ogv', '.webm', '.MP4', '.OGV', '.WEBM', '.WEBP', '.webp');
|
||||
// break;
|
||||
// }
|
||||
$folder = $input->get('folder', '', 'string') ? '/' . trim($input->get('folder', '', 'string'), '/') : '/' . trim(JComponentHelper::getParams('com_pagebuilderck')->get('imagespath', 'images/pagebuilderck'), '/');
|
||||
|
||||
// makes replacement if specific user management is set
|
||||
if (stristr($folder, '$userid')) {
|
||||
self::$isRestrictedUser = true;
|
||||
$user = JFactory::getUser();
|
||||
$folder = str_replace('$userid', 'user_' . $user->id, $folder);
|
||||
if (! file_exists(JPATH_SITE . '/' . $folder)) {
|
||||
JFolder::create(JPATH_SITE . '/' . $folder);
|
||||
}
|
||||
}
|
||||
|
||||
// no folder filtering
|
||||
if (JComponentHelper::getParams('com_pagebuilderck')->get('imagespathexclusive', '0') == '0') {
|
||||
$folder = $input->get('folder', 'images', 'string');
|
||||
} else {
|
||||
// check if folder exists, if not then create it
|
||||
if (!JFolder::exists(JPATH_SITE . $folder)) {
|
||||
JFolder::create(JPATH_SITE . $folder);
|
||||
}
|
||||
}
|
||||
|
||||
$tree = new stdClass();
|
||||
|
||||
// list the files in the root folder
|
||||
$fName = self::createFolderObj(JPATH_SITE . '/' . $folder, $tree, 1);
|
||||
$tree->$fName->files = self::getImagesInFolder(JPATH_SITE . '/' . $folder, implode('|', $filetypes));
|
||||
|
||||
// look for all folder and files
|
||||
self::getSubfolder(JPATH_SITE . '/' . $folder, $tree, implode('|', $filetypes), 2);
|
||||
$tree = self::prepareList($tree);
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/*
|
||||
* List the subfolders and files according to the filter
|
||||
*/
|
||||
private static function getSubfolder($folder, &$tree, $filter, $level) {
|
||||
$folders = JFolder::folders($folder, '.', $recurse = false, $fullpath = true);
|
||||
natcasesort($folders);
|
||||
|
||||
if (! count($folders)) return;
|
||||
|
||||
foreach ($folders as $f) {
|
||||
$fName = self::createFolderObj($f, $tree, $level);
|
||||
|
||||
// list all authorized files from the folder
|
||||
// self::getImagesInFolder($f, $tree, $fName, $filter, $level);
|
||||
|
||||
// recursive loop
|
||||
self::getSubfolder($f, $tree, $filter, $level+1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private static function createFolderObj($f, &$tree, $level) {
|
||||
$fName = JFile::makeSafe(str_replace(JPATH_SITE, '', $f));
|
||||
$tree->$fName = new stdClass();
|
||||
$name = explode('/', $f);
|
||||
$name = end($name);
|
||||
$tree->$fName->name = ($level == 1 && self::$isRestrictedUser == true) ? 'images' : $name;
|
||||
$tree->$fName->path = $f;
|
||||
$tree->$fName->level = $level;
|
||||
$tree->$fName->files = false;
|
||||
|
||||
return $fName;
|
||||
}
|
||||
|
||||
/*
|
||||
* List the subfolders and files according to the filter
|
||||
*/
|
||||
public static function getImagesInFolder($f, $filter = '.') {
|
||||
|
||||
// list all authorized files from the folder
|
||||
$files = JFolder::files($f, $filter, $recurse = false, $fullpath = false);
|
||||
if (is_array($files)) natcasesort($files);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set level diff and check for depth
|
||||
*/
|
||||
private static function prepareList($items) {
|
||||
if (! $items) return $items;
|
||||
|
||||
$lastitem = 0;
|
||||
foreach ($items as $i => $item)
|
||||
{
|
||||
self::prepareItem($item);
|
||||
|
||||
if ($item->level != 0) {
|
||||
if (isset($items->$lastitem))
|
||||
{
|
||||
$items->$lastitem->deeper = ($item->level > $items->$lastitem->level);
|
||||
$items->$lastitem->shallower = ($item->level < $items->$lastitem->level);
|
||||
$items->$lastitem->level_diff = ($items->$lastitem->level - $item->level);
|
||||
}
|
||||
}
|
||||
$lastitem = $i;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// for the last item
|
||||
if (isset($items->$lastitem))
|
||||
{
|
||||
$items->$lastitem->deeper = (1 > $items->$lastitem->level);
|
||||
$items->$lastitem->shallower = (1 < $items->$lastitem->level);
|
||||
$items->$lastitem->level_diff = ($item->level - 1);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the default values
|
||||
*/
|
||||
private static function prepareItem(&$item) {
|
||||
$item->deeper = false;
|
||||
$item->shallower = false;
|
||||
$item->level_diff = 0;
|
||||
$item->basepath = str_replace(JPATH_SITE, '', $item->path);
|
||||
$item->basepath = str_replace('\\', '/', $item->basepath);
|
||||
$item->basepath = trim($item->basepath, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file and store it on the server
|
||||
*
|
||||
* @return mixed, the method return
|
||||
*/
|
||||
public static function ajaxAddPicture() {
|
||||
// check the token for security
|
||||
if (! JSession::checkToken('get')) {
|
||||
$msg = JText::_('JINVALID_TOKEN');
|
||||
echo '{"error" : "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$input = $app->input;
|
||||
$file = $input->files->get('file', array(), 'array');
|
||||
// $imgpath = '/' . trim($input->get('path', '', 'string'), '/') . '/';
|
||||
$imgpath = $input->get('path', '', 'string') ? '/' . trim($input->get('path', '', 'string'), '/') . '/' : '/' . trim(JComponentHelper::getParams('com_pagebuilderck')->get('imagespath', 'images/pagebuilderck'), '/') . '/';
|
||||
|
||||
// makes replacement if specific user management is set
|
||||
$user = JFactory::getUser();
|
||||
$imgpath = str_replace('$userid', 'user_' . $user->id, $imgpath);
|
||||
|
||||
if (!is_array($file)) {
|
||||
$msg = JText::_('CK_NO_FILE_RECEIVED');
|
||||
echo '{"error" : "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
// If there are no files to upload - then bail
|
||||
if (empty($file))
|
||||
{
|
||||
$msg = JText::_('CK_NO_FILE_RECEIVED');
|
||||
echo '{"error" : "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Total length of post back data in bytes.
|
||||
// $contentLength = (int) $_SERVER['CONTENT_LENGTH'];
|
||||
|
||||
// Instantiate the media helper
|
||||
// $mediaHelper = new JHelperMedia;
|
||||
|
||||
// Maximum allowed size of post back data in MB.
|
||||
// $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size'));
|
||||
|
||||
// Maximum allowed size of script execution in MB.
|
||||
// $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit'));
|
||||
|
||||
// Check for the total size of post back data.
|
||||
// if (($postMaxSize > 0 && $contentLength > $postMaxSize)
|
||||
// || ($memoryLimit != -1 && $contentLength > $memoryLimit))
|
||||
// {
|
||||
// JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNUPLOADTOOLARGE'));
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
$filename = JFile::makeSafe($file['name']);
|
||||
|
||||
// check the file extension // TODO recup preg_match de local dev
|
||||
// if (JFile::getExt($filename) != 'jpg') {
|
||||
// $msg = JText::_('CK_NOT_JPG_FILE');
|
||||
// echo '{"error" : "' $msg '"}';
|
||||
// exit;
|
||||
// }
|
||||
|
||||
//Set up the source and destination of the file
|
||||
$src = $file['tmp_name'];
|
||||
|
||||
// check if the file exists
|
||||
if (!$src || !file_exists($src)) {
|
||||
$msg = JText::_('CK_FILE_NOT_EXISTS');
|
||||
echo '{"error" : "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
// check if folder exists, if not then create it
|
||||
if (!JFolder::exists(JPATH_SITE . $imgpath)) {
|
||||
if (!JFolder::create(JPATH_SITE . $imgpath)) {
|
||||
$msg = JText::_('CK_UNABLE_TO_CREATE_FOLDER') . ' : ' . $imgpath;
|
||||
echo '{"error" : "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$file['filepath'] = JPATH_SITE . $imgpath;
|
||||
|
||||
// Trigger the onContentBeforeSave event.
|
||||
// $object_file = new JObject($file);
|
||||
$type = JFile::getExt($filename);
|
||||
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$object = new CMSObject();
|
||||
// $object->adapter = $adapter;
|
||||
$object->name = $filename;
|
||||
$object->path = $imgpath;
|
||||
$object->data = file_get_contents($src);
|
||||
$object->extension = strtolower(File::getExt($filename));
|
||||
|
||||
|
||||
CKFof::importPlugin('media-action');
|
||||
$result = CKFof::triggerEvent('onContentBeforeSave', array('com_media.file', &$object, true));
|
||||
|
||||
if (in_array(false, $result, true))
|
||||
{
|
||||
// There are some errors in the plugins
|
||||
JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object->getErrors()), implode('<br />', $errors)));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// write the file
|
||||
// if (! JFile::copy($src, JPATH_SITE . $imgpath . $filename)) {
|
||||
// $msg = JText::_('CK_UNABLE_WRITE_FILE');
|
||||
// echo '{"error" : "' . $msg . '"}';
|
||||
// exit;
|
||||
// }
|
||||
if (! file_put_contents(JPATH_SITE . $imgpath . $filename, $object->data)) {
|
||||
$msg = JText::_('CK_UNABLE_WRITE_FILE');
|
||||
echo '{"error" : "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Trigger the onContentAfterSave event.
|
||||
CKFof::triggerEvent('onContentAfterSave', array('com_media.file', &$object, true));
|
||||
// $this->setMessage(JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($object->filepath, strlen(COM_MEDIA_BASE))));
|
||||
|
||||
|
||||
|
||||
switch ($type) {
|
||||
case 'video' :
|
||||
$fileicon = PAGEBUILDERCK_MEDIA_URI . '/images/' . 'file_video.png';
|
||||
break;
|
||||
case 'audio' :
|
||||
$fileicon = PAGEBUILDERCK_MEDIA_URI . '/images/' . 'file_audio.png';
|
||||
break;
|
||||
case 'pdf' :
|
||||
$fileicon = PAGEBUILDERCK_MEDIA_URI . '/images/' . 'file_pdf.png';
|
||||
break;
|
||||
default :
|
||||
$fileicon = $imgpath . $filename;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
echo '{"img" : "' . $fileicon . '", "filename" : "' . $filename . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function createFolder($path, $folder) {
|
||||
$path = CKPath::clean(JPATH_SITE . '/' . $path . '/' . $folder);
|
||||
|
||||
if (!is_dir($path) && !is_file($path))
|
||||
{
|
||||
if (CKFolder::create($path))
|
||||
{
|
||||
$data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
|
||||
file_put_contents($path . '/index.html', $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getTypeByFilename($filename) {
|
||||
$videoFiletypes = self::getFileTypes('video', false);
|
||||
$audioFiletypes = self::getFileTypes('audio', false);
|
||||
$imageFiletypes = self::getFileTypes('image', false);
|
||||
$allFiletypes = self::getFileTypes('all', false);
|
||||
$ext = JFile::getExt($filename);
|
||||
|
||||
if (in_array('.' . $ext, $videoFiletypes)) return 'video';
|
||||
if (in_array('.' . $ext, $audioFiletypes)) return 'audio';
|
||||
if (in_array('.' . $ext, $imageFiletypes)) return 'image';
|
||||
if (in_array('.' . $ext, $allFiletypes)) return 'all';
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
Namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
// class CKController extends \JControllerLegacy {
|
||||
class CKController {
|
||||
|
||||
protected $input;
|
||||
|
||||
protected $model;
|
||||
|
||||
protected $name;
|
||||
|
||||
protected $prefix;
|
||||
|
||||
protected $view;
|
||||
|
||||
protected $redirect;
|
||||
|
||||
protected static $instance;
|
||||
|
||||
protected static $views;
|
||||
|
||||
function __construct() {
|
||||
$this->input = CKFof::getInput();
|
||||
}
|
||||
|
||||
static function getInstance($prefix) {
|
||||
if (is_object(self::$instance))
|
||||
{
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
$basePath = PAGEBUILDERCK_BASE_PATH;
|
||||
|
||||
// Check for a controller.task command.
|
||||
$input = CKFof::getInput();
|
||||
$cmd = $input->get('task', '', 'cmd');
|
||||
if (strpos($cmd, '.') !== false)
|
||||
{
|
||||
// Explode the controller.task command.
|
||||
list ($name, $task) = explode('.', $cmd);
|
||||
|
||||
// Define the controller filename and path.
|
||||
$file = self::createFileName('controller', array('name' => $name));
|
||||
$path = $basePath . '/controllers/' . $file;
|
||||
$backuppath = $basePath . '/controller/' . $file;
|
||||
|
||||
// Reset the task without the controller context.
|
||||
$input->set('task', $task);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Base controller.
|
||||
$name = null;
|
||||
|
||||
// Define the controller filename and path.
|
||||
$file = self::createFileName('controller', array('name' => 'controller'));
|
||||
$path = $basePath . '/' . $file;
|
||||
}
|
||||
|
||||
// Get the controller class name.
|
||||
$class = ucfirst((string) $prefix) . 'Controller' . ucfirst((string) $name);
|
||||
|
||||
// Include the class if not present.
|
||||
if (!class_exists($class))
|
||||
{
|
||||
// If the controller file path exists, include it.
|
||||
if (file_exists($path))
|
||||
{
|
||||
require_once $path;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \InvalidArgumentException(\JText::sprintf('ERROR_INVALID_CONTROLLER', $type, $format));
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate the class.
|
||||
if (!class_exists($class))
|
||||
{
|
||||
throw new \InvalidArgumentException(\JText::sprintf('ERROR_INVALID_CONTROLLER_CLASS', $class));
|
||||
}
|
||||
|
||||
// Instantiate the class, store it to the static container, and return it
|
||||
return self::$instance = new $class();
|
||||
}
|
||||
|
||||
protected static function createFileName($type, $parts = array())
|
||||
{
|
||||
$filename = '';
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'controller':
|
||||
|
||||
$filename = strtolower($parts['name'] . '.php');
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
|
||||
$filename = strtolower($parts['name'] . '/view.html.php');
|
||||
break;
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
// public function getModel($base = '\Pagebuilderck\CKModel') {
|
||||
// if (empty($this->model)) {
|
||||
// $name = $this->getName();
|
||||
// require_once(PAGEBUILDERCK_BASE_PATH . '/helpers/ckmodel.php');
|
||||
// require_once(PAGEBUILDERCK_BASE_PATH . '/models/' . strtolower($name) . '.php');
|
||||
// $className = ucfirst($base) . ucfirst($name);
|
||||
// $this->model = new $className;
|
||||
// }
|
||||
// return $this->model;
|
||||
// }
|
||||
|
||||
public function getView($name = '', $type = 'html', $prefix = '')
|
||||
{
|
||||
// @note We use self so we only access stuff in this class rather than in all classes.
|
||||
if (!isset(self::$views))
|
||||
{
|
||||
self::$views = array();
|
||||
}
|
||||
|
||||
if (empty($name))
|
||||
{
|
||||
$name = $this->getName();
|
||||
}
|
||||
|
||||
if (empty($prefix))
|
||||
{
|
||||
$prefix = $this->getPrefix() . 'View';
|
||||
}
|
||||
|
||||
if (empty(self::$views[$name][$type][$prefix]))
|
||||
{
|
||||
if ($view = $this->createView($name, $prefix))
|
||||
{
|
||||
self::$views[$name][$type][$prefix] = & $view;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(\JText::sprintf('ERROR_VIEW_NOT_FOUND', $name, $type, $prefix), 404);
|
||||
}
|
||||
}
|
||||
|
||||
return self::$views[$name][$type][$prefix];
|
||||
}
|
||||
|
||||
protected function createView($name, $prefix = '')
|
||||
{
|
||||
// Clean the view name
|
||||
$viewName = preg_replace('/[^A-Z0-9_]/i', '', $name);
|
||||
$classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
|
||||
|
||||
// Build the view class name
|
||||
$viewClass = $classPrefix . ucfirst($viewName);
|
||||
|
||||
if (!class_exists($viewClass))
|
||||
{
|
||||
$path = PAGEBUILDERCK_BASE_PATH . '/views/' . $this->createFileName('view', array('name' => $viewName));
|
||||
|
||||
if (!file_exists($path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
require_once $path;
|
||||
|
||||
if (!class_exists($viewClass))
|
||||
{
|
||||
throw new \Exception(\JText::_('ERROR_VIEW_CLASS_NOT_FOUND : ' . $viewClass . ' - ' . $path), 500);
|
||||
}
|
||||
}
|
||||
|
||||
return new $viewClass();
|
||||
}
|
||||
|
||||
public function display() {
|
||||
$viewName = $this->input->get('view', $this->getName());
|
||||
$viewLayout = $this->input->get('layout', 'default', 'string');
|
||||
|
||||
$view = $this->getView($viewName, 'html', '');
|
||||
$view->setName($viewName);
|
||||
|
||||
// Get/Create the model
|
||||
if ($model = $this->getModel($viewName))
|
||||
{
|
||||
// Push the model into the view (as default)
|
||||
$view->setModel($model);
|
||||
}
|
||||
|
||||
$view->display();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModel($name = '', $prefix = '', $config = array())
|
||||
{
|
||||
if (empty($name))
|
||||
{
|
||||
$name = ucfirst($this->getName());
|
||||
}
|
||||
|
||||
if (empty($prefix))
|
||||
{
|
||||
$prefix = ucfirst($this->getPrefix());
|
||||
}
|
||||
|
||||
$model = $this->createModel($name, $prefix, $config);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
protected function createModel($name, $prefix = '', $config = array())
|
||||
{
|
||||
// Clean the model name
|
||||
$modelName = preg_replace('/[^A-Z0-9_]/i', '', $name);
|
||||
$classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
|
||||
|
||||
return CKModel::getInstance($modelName, $classPrefix, $config);
|
||||
}
|
||||
|
||||
|
||||
public function execute($task) {
|
||||
if (! $task) $task = 'display';
|
||||
if (is_callable(array($this, $task))) {
|
||||
return $this->$task();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(\JText::sprintf('ERROR_TASK_NOT_FOUND', $task), 404);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (empty($this->name))
|
||||
{
|
||||
$r = null;
|
||||
|
||||
if (!preg_match('/Controller(.*)/i', get_class($this), $r))
|
||||
{
|
||||
throw new \Exception(\CKText::_('Error : Can not get controller name'), 500);
|
||||
}
|
||||
|
||||
$this->name = strtolower($r[1]);
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getPrefix()
|
||||
{
|
||||
if (empty($this->prefix))
|
||||
{
|
||||
$r = null;
|
||||
|
||||
if (!preg_match('/(.*)Controller/i', get_class($this), $r))
|
||||
{
|
||||
throw new \Exception(\CKText::_('Error : Can not get controller name'), 500);
|
||||
}
|
||||
|
||||
$this->prefix = strtolower($r[1]);
|
||||
}
|
||||
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function add() {
|
||||
return $this->edit(0);
|
||||
}
|
||||
|
||||
public function edit($id = null, $appendUrl = '') {
|
||||
$editIds = $this->input->get('cid', $id, 'array');
|
||||
if (is_array($editIds)) {
|
||||
$editId = (int) $editIds[0];
|
||||
} else {
|
||||
$editId = (int) $this->input->get('id', $id, 'int');
|
||||
}
|
||||
|
||||
$model = $this->getModel($this->getName());
|
||||
$model->checkout($editId);
|
||||
|
||||
// Redirect to the edit screen.
|
||||
CKFof::redirect(PAGEBUILDERCK_BASE_URL . '&view=' . $this->getName() . '&layout=edit&id=' . $editId . $appendUrl);
|
||||
}
|
||||
|
||||
public function copy() {
|
||||
$editIds = $this->input->get('cid', null, 'array');
|
||||
if (count($editIds)) {
|
||||
$id = (int) $editIds[0];
|
||||
} else {
|
||||
$id = (int) $this->input->get('id', null, 'int');
|
||||
}
|
||||
|
||||
$model = $this->getModel($this->getName());
|
||||
if ($model->copy($id)) {
|
||||
CKFof::enqueueMessage('Item copied with success');
|
||||
} else {
|
||||
CKFof::enqueueMessage('Error : Item not copied', 'error');
|
||||
}
|
||||
|
||||
if (! $this->redirect) $this->redirect = PAGEBUILDERCK_ADMIN_GENERAL_URL;
|
||||
|
||||
// Redirect to the edit screen.
|
||||
CKFof::redirect($this->redirect);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$ids = $this->input->get('cid', null, 'array');
|
||||
if (count($ids)) {
|
||||
$ids = (array) $ids;
|
||||
} else {
|
||||
$ids = (array) $this->input->get('id', null, 'array');
|
||||
}
|
||||
$model = $this->getModel($this->getName());
|
||||
foreach($ids as $id) {
|
||||
$return = $model->delete($id);
|
||||
if ($return) {
|
||||
CKFof::enqueueMessage('Item deleted with success');
|
||||
} else {
|
||||
CKFof::enqueueMessage('Error : Item not deleted', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->redirect) $this->redirect = PAGEBUILDERCK_ADMIN_GENERAL_URL;
|
||||
|
||||
// Redirect to the edit screen.
|
||||
CKFof::redirect($this->redirect);
|
||||
}
|
||||
|
||||
public function trash() {
|
||||
$ids = $this->input->get('cid', null, 'array');
|
||||
if (count($ids)) {
|
||||
$ids = (array) $ids;
|
||||
} else {
|
||||
$ids = (array) $this->input->get('id', null, 'array');
|
||||
}
|
||||
$model = $this->getModel($this->getName());
|
||||
foreach($ids as $id) {
|
||||
$return = $model->trash($id);
|
||||
if ($return) {
|
||||
CKFof::enqueueMessage('CK_ITEM_TRASH_SUCCESS');
|
||||
} else {
|
||||
CKFof::enqueueMessage('CK_ITEM_TRASH_FAILED', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
CKFof::redirect(PAGEBUILDERCK_ADMIN_GENERAL_URL);
|
||||
}
|
||||
|
||||
public function publish() {
|
||||
$ids = $this->input->get('cid', null, 'array');
|
||||
if (count($ids)) {
|
||||
$ids = (array) $ids;
|
||||
} else {
|
||||
$ids = (array) $this->input->get('id', null, 'array');
|
||||
}
|
||||
if (! empty($ids)) {
|
||||
$model = $this->getModel($this->getName());
|
||||
foreach($ids as $id) {
|
||||
if ($model->publish($id)) {
|
||||
CKFof::enqueueMessage('Item published with success');
|
||||
} else {
|
||||
CKFof::enqueueMessage('Error : Item not published', 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
CKFof::redirect(PAGEBUILDERCK_ADMIN_GENERAL_URL);
|
||||
}
|
||||
|
||||
public function unpublish() {
|
||||
$ids = $this->input->get('cid', null, 'array');var_dump($ids);
|
||||
if (count($ids)) {
|
||||
$ids = (array) $ids;
|
||||
} else {
|
||||
$ids = (array) $this->input->get('id', null, 'array');
|
||||
}
|
||||
// var_dump($ids);die;
|
||||
if (! empty($ids)) {
|
||||
$model = $this->getModel($this->getName());
|
||||
foreach($ids as $id) {
|
||||
if ($model->unpublish($id)) {
|
||||
CKFof::enqueueMessage('Item unpublished with success');
|
||||
} else {
|
||||
CKFof::enqueueMessage('Error : Item not unpublished', 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
CKFof::redirect(PAGEBUILDERCK_ADMIN_GENERAL_URL);
|
||||
}
|
||||
}
|
||||
536
administrator/components/com_pagebuilderck/helpers/ckeditor.php
Normal file
536
administrator/components/com_pagebuilderck/helpers/ckeditor.php
Normal file
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage Editor
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
/**
|
||||
* CKEditor class to handle WYSIWYG editors
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class CKEditor extends JObject
|
||||
{
|
||||
/**
|
||||
* An array of Observer objects to notify
|
||||
*
|
||||
* @var array
|
||||
* @since 1.5
|
||||
*/
|
||||
protected $_observers = array();
|
||||
|
||||
/**
|
||||
* The state of the observable object
|
||||
*
|
||||
* @var mixed
|
||||
* @since 1.5
|
||||
*/
|
||||
protected $_state = null;
|
||||
|
||||
/**
|
||||
* A multi dimensional array of [function][] = key for observers
|
||||
*
|
||||
* @var array
|
||||
* @since 1.5
|
||||
*/
|
||||
protected $_methods = array();
|
||||
|
||||
/**
|
||||
* Editor Plugin object
|
||||
*
|
||||
* @var object
|
||||
* @since 1.5
|
||||
*/
|
||||
protected $_editor = null;
|
||||
|
||||
/**
|
||||
* Editor Plugin name
|
||||
*
|
||||
* @var string
|
||||
* @since 1.5
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* Object asset
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $asset = null;
|
||||
|
||||
/**
|
||||
* Object author
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $author = null;
|
||||
|
||||
/**
|
||||
* @var array CKEditor instances container.
|
||||
* @since 2.5
|
||||
*/
|
||||
protected static $instances = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $editor The editor name
|
||||
*/
|
||||
public function __construct($editor = 'none')
|
||||
{
|
||||
$this->_name = $editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global Editor object, only creating it
|
||||
* if it doesn't already exist.
|
||||
*
|
||||
* @param string $editor The editor to use.
|
||||
*
|
||||
* @return CKEditor The Editor object.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function getInstance($editor = 'none')
|
||||
{
|
||||
$signature = serialize($editor);
|
||||
|
||||
if (empty(self::$instances[$signature]))
|
||||
{
|
||||
self::$instances[$signature] = new CKEditor($editor);
|
||||
}
|
||||
|
||||
return self::$instances[$signature];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of the CKEditor object
|
||||
*
|
||||
* @return mixed The state of the object.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach an observer object
|
||||
*
|
||||
* @param object $observer An observer object to attach
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function attach($observer)
|
||||
{
|
||||
if (is_array($observer))
|
||||
{
|
||||
if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we haven't already attached this array as an observer
|
||||
foreach ($this->_observers as $check)
|
||||
{
|
||||
if (is_array($check) && $check['event'] == $observer['event'] && $check['handler'] == $observer['handler'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_observers[] = $observer;
|
||||
end($this->_observers);
|
||||
$methods = array($observer['event']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!($observer instanceof CKEditor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we haven't already attached this object as an observer
|
||||
$class = get_class($observer);
|
||||
|
||||
foreach ($this->_observers as $check)
|
||||
{
|
||||
if ($check instanceof $class)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_observers[] = $observer;
|
||||
$methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin'));
|
||||
}
|
||||
|
||||
$key = key($this->_observers);
|
||||
|
||||
foreach ($methods as $method)
|
||||
{
|
||||
$method = strtolower($method);
|
||||
|
||||
if (!isset($this->_methods[$method]))
|
||||
{
|
||||
$this->_methods[$method] = array();
|
||||
}
|
||||
|
||||
$this->_methods[$method][] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach an observer object
|
||||
*
|
||||
* @param object $observer An observer object to detach.
|
||||
*
|
||||
* @return boolean True if the observer object was detached.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function detach($observer)
|
||||
{
|
||||
$retval = false;
|
||||
|
||||
$key = array_search($observer, $this->_observers);
|
||||
|
||||
if ($key !== false)
|
||||
{
|
||||
unset($this->_observers[$key]);
|
||||
$retval = true;
|
||||
|
||||
foreach ($this->_methods as &$method)
|
||||
{
|
||||
$k = array_search($key, $method);
|
||||
|
||||
if ($k !== false)
|
||||
{
|
||||
unset($method[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the editor
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function initialise()
|
||||
{
|
||||
// Check if editor is already loaded
|
||||
if (is_null(($this->_editor)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$args['event'] = 'onInit';
|
||||
|
||||
$return = '';
|
||||
$results[] = $this->_editor->update($args);
|
||||
|
||||
foreach ($results as $result)
|
||||
{
|
||||
if (trim($result))
|
||||
{
|
||||
// @todo remove code: $return .= $result;
|
||||
$return = $result;
|
||||
}
|
||||
}
|
||||
|
||||
$document = JFactory::getDocument();
|
||||
|
||||
// if (method_exists($document, "addCustomTag"))
|
||||
// {
|
||||
// $document->addCustomTag($return);
|
||||
// }
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the editor area.
|
||||
*
|
||||
* @param string $name The control name.
|
||||
* @param string $html The contents of the text area.
|
||||
* @param string $width The width of the text area (px or %).
|
||||
* @param string $height The height of the text area (px or %).
|
||||
* @param integer $col The number of columns for the textarea.
|
||||
* @param integer $row The number of rows for the textarea.
|
||||
* @param boolean $buttons True and the editor buttons will be displayed.
|
||||
* @param string $id An optional ID for the textarea (note: since 1.6). If not supplied the name is used.
|
||||
* @param string $asset The object asset
|
||||
* @param object $author The author.
|
||||
* @param array $params Associative array of editor parameters.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($name, $html, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null, $params = array())
|
||||
{
|
||||
$this->asset = $asset;
|
||||
$this->author = $author;
|
||||
$this->_loadEditor($params);
|
||||
|
||||
// Check whether editor is already loaded
|
||||
if (is_null(($this->_editor)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Backwards compatibility. Width and height should be passed without a semicolon from now on.
|
||||
// If editor plugins need a unit like "px" for CSS styling, they need to take care of that
|
||||
$width = str_replace(';', '', $width);
|
||||
$height = str_replace(';', '', $height);
|
||||
|
||||
$return = null;
|
||||
|
||||
$args['name'] = $name;
|
||||
$args['content'] = $html;
|
||||
$args['width'] = $width;
|
||||
$args['height'] = $height;
|
||||
$args['col'] = $col;
|
||||
$args['row'] = $row;
|
||||
$args['buttons'] = $buttons;
|
||||
$args['id'] = $id ? $id : $name;
|
||||
$args['event'] = 'onDisplay';
|
||||
|
||||
$results[] = $this->_editor->update($args);
|
||||
|
||||
foreach ($results as $result)
|
||||
{
|
||||
if (trim($result))
|
||||
{
|
||||
$return .= $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the editor content
|
||||
*
|
||||
* @param string $editor The name of the editor control
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function save($editor)
|
||||
{
|
||||
$this->_loadEditor();
|
||||
|
||||
// Check whether editor is already loaded
|
||||
if (is_null(($this->_editor)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$args[] = $editor;
|
||||
$args['event'] = 'onSave';
|
||||
|
||||
$return = '';
|
||||
$results[] = $this->_editor->update($args);
|
||||
|
||||
foreach ($results as $result)
|
||||
{
|
||||
if (trim($result))
|
||||
{
|
||||
$return .= $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the editor contents
|
||||
*
|
||||
* @param string $editor The name of the editor control
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getContent($editor)
|
||||
{
|
||||
$this->_loadEditor();
|
||||
|
||||
$args['name'] = $editor;
|
||||
$args['event'] = 'onGetContent';
|
||||
|
||||
$return = '';
|
||||
$results[] = $this->_editor->update($args);
|
||||
|
||||
foreach ($results as $result)
|
||||
{
|
||||
if (trim($result))
|
||||
{
|
||||
$return .= $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the editor contents
|
||||
*
|
||||
* @param string $editor The name of the editor control
|
||||
* @param string $html The contents of the text area
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function setContent($editor, $html)
|
||||
{
|
||||
$this->_loadEditor();
|
||||
|
||||
$args['name'] = $editor;
|
||||
$args['html'] = $html;
|
||||
$args['event'] = 'onSetContent';
|
||||
|
||||
$return = '';
|
||||
$results[] = $this->_editor->update($args);
|
||||
|
||||
foreach ($results as $result)
|
||||
{
|
||||
if (trim($result))
|
||||
{
|
||||
$return .= $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the editor extended buttons (usually from plugins)
|
||||
*
|
||||
* @param string $editor The name of the editor.
|
||||
* @param mixed $buttons Can be boolean or array, if boolean defines if the buttons are
|
||||
* displayed, if array defines a list of buttons not to show.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getButtons($editor, $buttons = true)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
if (is_bool($buttons) && !$buttons)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Get plugins
|
||||
$plugins = JPluginHelper::getPlugin('editors-xtd');
|
||||
|
||||
foreach ($plugins as $plugin)
|
||||
{
|
||||
if (is_array($buttons) && in_array($plugin->name, $buttons))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
JPluginHelper::importPlugin('editors-xtd', $plugin->name, false);
|
||||
$className = 'plgButton' . $plugin->name;
|
||||
|
||||
if (class_exists($className))
|
||||
{
|
||||
$plugin = new $className($this, (array) $plugin);
|
||||
}
|
||||
|
||||
// Try to authenticate
|
||||
if (method_exists($plugin, 'onDisplay') && $temp = $plugin->onDisplay($editor, $this->asset, $this->author))
|
||||
{
|
||||
$result[] = $temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the editor
|
||||
*
|
||||
* @param array $config Associative array of editor config paramaters
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
protected function _loadEditor($config = array())
|
||||
{
|
||||
// Check whether editor is already loaded
|
||||
if (!is_null(($this->_editor)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the path to the needed editor plugin
|
||||
$name = JFilterInput::getInstance()->clean($this->_name, 'cmd');
|
||||
$path = JPATH_PLUGINS . '/editors/' . $name . '/' . $name . '.php';
|
||||
|
||||
if (!is_file($path))
|
||||
{
|
||||
JLog::add(JText::_('JLIB_HTML_EDITOR_CANNOT_LOAD'), JLog::WARNING, 'jerror');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Require plugin file
|
||||
require_once $path;
|
||||
|
||||
// Get the plugin
|
||||
$plugin = JPluginHelper::getPlugin('editors', $this->_name);
|
||||
$params = new Registry;
|
||||
$params->loadString($plugin->params);
|
||||
$params->loadArray($config);
|
||||
$plugin->params = $params;
|
||||
|
||||
// Build editor plugin classname
|
||||
$name = 'plgEditor' . $this->_name;
|
||||
|
||||
if ($this->_editor = new $name($this, (array) $plugin))
|
||||
{
|
||||
// Load plugin parameters
|
||||
return $this->initialise();
|
||||
// JPluginHelper::importPlugin('editors-xtd');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the editor
|
||||
*
|
||||
* @param array $config Associative array of editor config paramaters
|
||||
*
|
||||
* @return the JS and CSS as string
|
||||
*
|
||||
*/
|
||||
public function loadEditor($params = array())
|
||||
{
|
||||
return $this->_loadEditor($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
class CKFile extends \JFile {
|
||||
|
||||
}
|
||||
556
administrator/components/com_pagebuilderck/helpers/ckfof.php
Normal file
556
administrator/components/com_pagebuilderck/helpers/ckfof.php
Normal file
@@ -0,0 +1,556 @@
|
||||
<?php
|
||||
namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use \Pagebuilderck\CKInput;
|
||||
use \Pagebuilderck\CKText;
|
||||
|
||||
/**
|
||||
* CK Development Framework layer
|
||||
*/
|
||||
class CKFof {
|
||||
|
||||
static $keepMessages = false;
|
||||
|
||||
static protected $environment = 'com_pagebuilderck'; // for joomla only
|
||||
|
||||
static protected $input;
|
||||
|
||||
// public static function loadHelper($name) {
|
||||
// require_once(SLIDESHOWCK_PATH . '/helpers/ck' . $name . '.php');
|
||||
// }
|
||||
|
||||
public static function getInput() {
|
||||
if (empty(self::$input)) {
|
||||
self::$input = Factory::getApplication()->input;
|
||||
}
|
||||
return self::$input;
|
||||
}
|
||||
|
||||
public static function userCan($task, $environment = false) {
|
||||
$environment = $environment ? $environment : self::$environment;
|
||||
$user = CKFof::getUser();
|
||||
switch ($task) {
|
||||
case 'edit' :
|
||||
// return current_user_can('edit_plugins');
|
||||
return $user->authorise('core.edit', $environment);
|
||||
break;
|
||||
case 'create' :
|
||||
// return current_user_can('manage_options');
|
||||
return $user->authorise('core.create', $environment);
|
||||
break;
|
||||
case 'manage' :
|
||||
// return current_user_can('manage_options');
|
||||
return $user->authorise('core.manage', $environment);
|
||||
break;
|
||||
case 'admin' :
|
||||
// return current_user_can('manage_options');
|
||||
return $user->authorise('core.admin', $environment);
|
||||
break;
|
||||
default :
|
||||
// return current_user_can('edit_plugins');
|
||||
return $user->authorise($task, $environment);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUser($id = 0) {
|
||||
if ($id) {
|
||||
return $user = Factory::getUser($id);
|
||||
}
|
||||
return $user = Factory::getUser();
|
||||
}
|
||||
|
||||
public static function isAdmin() {
|
||||
return Factory::getApplication()->isClient('administrator') ;
|
||||
}
|
||||
|
||||
public static function isSite() {
|
||||
return Factory::getApplication()->isClient('site') ;
|
||||
}
|
||||
|
||||
public static function _die($msg = '') {
|
||||
$msg = $msg ? $msg : CKText::_('JERROR_ALERTNOAUTHOR');
|
||||
jexit($msg);
|
||||
}
|
||||
|
||||
public static function getCurrentUri() {
|
||||
// $uri = \JFactory::getURI();
|
||||
$uri = \JUri::getInstance();
|
||||
return $uri->toString();
|
||||
}
|
||||
|
||||
public static function redirect($url = '', $msg = '', $type = '') {
|
||||
if (! $url) {
|
||||
$url = self::getCurrentUri();
|
||||
}
|
||||
if ($msg) {
|
||||
self::enqueueMessage($msg, $type);
|
||||
}
|
||||
Factory::getApplication()->redirect($url);
|
||||
// If the headers have been sent, then we cannot send an additional location header
|
||||
// so we will output a javascript redirect statement.
|
||||
/*if (headers_sent())
|
||||
{
|
||||
self::$keepMessages = true;
|
||||
echo "<script>document.location.href='" . str_replace("'", ''', $url) . "';</script>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$keepMessages = true;
|
||||
// All other browsers, use the more efficient HTTP header method
|
||||
header('HTTP/1.1 303 See other');
|
||||
header('Location: ' . $url);
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
}*/
|
||||
}
|
||||
|
||||
public static function enqueueMessage($msg, $type = 'message') {
|
||||
// add the information message
|
||||
Factory::getApplication()->enqueueMessage(CKText::_($msg), $type);
|
||||
}
|
||||
|
||||
public static function displayMessages() {
|
||||
// manage the information messages
|
||||
// not needed in joomla
|
||||
}
|
||||
|
||||
public static function getToken($name = '') {
|
||||
return \JFactory::getSession()->getFormToken() . '=1';
|
||||
}
|
||||
|
||||
public static function renderToken($name = '') {
|
||||
echo \JHtml::_('form.token');
|
||||
}
|
||||
|
||||
public static function checkToken($token = '') {
|
||||
if (! \JSession::checkToken()) {
|
||||
$msg = CKText::_('Invalid token');
|
||||
jexit($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkAjaxToken($json = true) {
|
||||
// check the token for security
|
||||
if (! \JSession::checkToken('get')) {
|
||||
$msg = CKText::_('JINVALID_TOKEN');
|
||||
if ($json === false) {
|
||||
jexit($msg);
|
||||
}
|
||||
echo '{"result": "0", "message": "' . $msg . '"}';
|
||||
exit;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getDbo() {
|
||||
return Factory::getDbo();
|
||||
}
|
||||
|
||||
public static function dbQuote($name) {
|
||||
$db = self::getDbo();
|
||||
return $db->quoteName($name);
|
||||
}
|
||||
|
||||
public static function dbLoadObjectList($query) {
|
||||
$db = self::getDbo();
|
||||
// $query = $db->getQuery(true);
|
||||
$db->setQuery($query);
|
||||
$results = $db->loadObjectList();
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function dbLoadObject($query) {
|
||||
$db = self::getDbo();
|
||||
$db->setQuery($query);
|
||||
$results = $db->loadObject();
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function dbLoadResult($query) {
|
||||
$db = self::getDbo();
|
||||
// $query = $db->getQuery(true);
|
||||
$db->setQuery($query);
|
||||
$result = $db->loadResult();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function dbExecute($query) {
|
||||
$db = self::getDbo();
|
||||
$db->setQuery($query);
|
||||
$result = $db->execute();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function dbLoadColumn($tableName, $column) {
|
||||
$db = self::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($column);
|
||||
$query->from($tableName);
|
||||
|
||||
$db->setQuery($query);
|
||||
$result = $db->loadColumn();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function dbCheckTableExists($tableName) {
|
||||
$db = self::getDbo();
|
||||
$tablesList = $db->getTableList();
|
||||
|
||||
$tableName = str_replace('#__', $db->getPrefix(), $tableName);
|
||||
$tableExists = in_array($tableName, $tablesList);
|
||||
return $tableExists;
|
||||
}
|
||||
|
||||
public static function dbLoadTable($tableName) {
|
||||
$db = self::getDbo();
|
||||
$tableName = self::getTableName($tableName);
|
||||
$query = "DESCRIBE " . $tableName;
|
||||
$db->setQuery($query);
|
||||
$columns = $db->loadObjectList();
|
||||
|
||||
$table = new \stdClass();
|
||||
foreach ($columns as $col) {
|
||||
$table->{$col->Field} = '';
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
public static function dbLoad($tableName, $id) {
|
||||
// if no existing row, then load empty table
|
||||
if ($id == 0) return self::dbLoadTable($tableName);
|
||||
|
||||
$db = self::getDbo();
|
||||
$query = "SELECT * FROM " . $tableName . " WHERE id = " . (int)$id;
|
||||
$db->setQuery($query);
|
||||
$result = $db->loadAssoc();
|
||||
|
||||
if (! $result) return self::dbLoadTable($tableName);
|
||||
|
||||
$result = self::convertArrayToObject($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function dbBindData($table, $data) {
|
||||
if (is_object($table)) $table = self::convertObjectToArray($table);
|
||||
if (is_object($data)) $data = self::convertObjectToArray($data);
|
||||
|
||||
foreach ($table as $col => $val) {
|
||||
if (isset($data[$col])) $table[$col] = $data[$col];
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
public static function getTableName($tableName) {
|
||||
return $tableName;
|
||||
}
|
||||
|
||||
public static function getTableStructure($tableName) {
|
||||
$db = self::getDbo();
|
||||
$query = "SHOW COLUMNS FROM " . $tableName;
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadObjectList('Field');
|
||||
}
|
||||
|
||||
public static function dbStore($tableName, $data, $format = array()) {
|
||||
$db = self::getDbo();
|
||||
if (is_object($data)) $data = self::convertObjectToArray($data);
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
$columsData = self::getTableStructure($tableName);
|
||||
|
||||
if ((int)$data['id'] === 0) {
|
||||
$columns = array();
|
||||
$values = array();
|
||||
$fields = self::dbLoadTable($tableName);
|
||||
|
||||
|
||||
foreach($fields as $key => $val) {
|
||||
$columns[] = $key;
|
||||
if (isset($data[$key]) && !empty($data[$key])) {
|
||||
$values[] = is_numeric($data[$key]) ? $data[$key] : $db->quote($data[$key]);
|
||||
} else {
|
||||
if (strpos($columsData[$key]->Type, 'int') === 0 || strpos($columsData[$key]->Type, 'tinyint') === 0) {
|
||||
$values[] = 0;
|
||||
} else if (strpos($columsData[$key]->Type, 'date') === 0) {
|
||||
$values[] = $db->quote('0000-00-00 00:00:00');
|
||||
// array_pop($columns);
|
||||
} else {
|
||||
$values[] = $db->quote('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the insert query.
|
||||
$query
|
||||
->insert($db->quoteName($tableName))
|
||||
->columns($db->quoteName($columns))
|
||||
->values(implode(',', $values));
|
||||
|
||||
// Set the query using our newly populated query object and execute it.
|
||||
$db->setQuery($query);
|
||||
if ($db->execute()) {
|
||||
$id = $db->insertid();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Fields to update.
|
||||
$fields = self::dbLoadTable($tableName);
|
||||
$fieldsToInsert = array();
|
||||
foreach($fields as $key => $val) {
|
||||
if (strpos($columsData[$key]->Type, 'date') === 0 && empty($data[$key])) {
|
||||
continue;
|
||||
}
|
||||
if (isset($data[$key])) {
|
||||
$value = is_numeric($data[$key]) ? (int)$data[$key] : $db->quote($data[$key]);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$fieldsToInsert[] = $db->quoteName($key) . ' = ' . $value;
|
||||
}
|
||||
// Conditions for which records should be updated.
|
||||
$conditions = array(
|
||||
$db->quoteName('id') . ' = ' . $data['id']
|
||||
);
|
||||
|
||||
$query->update($db->quoteName($tableName))->set($fieldsToInsert)->where($conditions);
|
||||
|
||||
// Set the query using our newly populated query object and execute it.
|
||||
$db->setQuery($query);
|
||||
if ($db->execute()) {
|
||||
$id = $data['id'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function dbUpdate($tableName, $id, $fields) {
|
||||
// Create a new query object.
|
||||
$db = self::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Conditions for which records should be updated.
|
||||
$conditions = array(
|
||||
$db->quoteName('id') . ' = ' . $id
|
||||
);
|
||||
|
||||
$fieldsToInsert = array();
|
||||
foreach ($fields as $key => $value) {
|
||||
$fieldsToInsert[] = $db->quoteName($key) . ' = ' . $value;
|
||||
}
|
||||
|
||||
$query->update($db->quoteName($tableName))->set($fieldsToInsert)->where($conditions);
|
||||
|
||||
// Set the query using our newly populated query object and execute it.
|
||||
$db->setQuery($query);
|
||||
if ($result = $db->execute()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function dbDelete($tableName, $id) {
|
||||
$db = CKFof::getDbo();
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$conditions = array(
|
||||
$db->quoteName('id') . ' = ' . (int) $id
|
||||
// , $db->quoteName('profile_key') . ' = ' . $db->quote('custom.%')
|
||||
);
|
||||
|
||||
$query->delete($db->quoteName($tableName));
|
||||
$query->where($conditions);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$result = $db->execute();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function convertObjectToArray($data) {
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public static function convertArrayToObject(array $array, $class = 'stdClass', $recursive = true)
|
||||
{
|
||||
$obj = new $class;
|
||||
|
||||
foreach ($array as $k => $v)
|
||||
{
|
||||
if ($recursive && is_array($v))
|
||||
{
|
||||
$obj->$k = static::toObject($v, $class);
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj->$k = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public static function dump($anything){
|
||||
echo "<pre>";
|
||||
var_dump($anything);
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
public static function print_r($anything){
|
||||
echo "<pre>";
|
||||
print_r($anything);
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
public static function addToolbarTitle($title, $image = '') {
|
||||
\JToolBarHelper::title($title, $image);
|
||||
}
|
||||
|
||||
private static function getToolbar() {
|
||||
// Get the toolbar object instance
|
||||
$bar = \JToolBar::getInstance('toolbar');
|
||||
return $bar;
|
||||
}
|
||||
|
||||
public static function addToolbarButton($name, $html, $id) {
|
||||
$bar = self::getToolbar();
|
||||
$bar->appendButton($name, $html, $id);
|
||||
}
|
||||
|
||||
public static function addToolbarPreferences() {
|
||||
$bar = self::getToolbar();
|
||||
// add the options of the component
|
||||
if (self::userCan('admin')) {
|
||||
\JToolBarHelper::preferences(self::$environment);
|
||||
}
|
||||
}
|
||||
|
||||
private static function getFileName($file) {
|
||||
$f = explode('/', $file);
|
||||
$fileName = end($f);
|
||||
$f = explode('.', $fileName);
|
||||
$ext = end($f);
|
||||
$fileName = str_replace('.' . $ext, '', $fileName);
|
||||
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
public static function addScriptDeclaration($js) {
|
||||
echo '<script>' . $js . '</script>';
|
||||
}
|
||||
|
||||
public static function addScriptDeclarationInline($js) {
|
||||
echo '<script>' . $js . '</script>';
|
||||
}
|
||||
|
||||
public static function addScript($file) {
|
||||
$doc = Factory::getDocument();
|
||||
$doc->addScript($file);
|
||||
}
|
||||
|
||||
public static function addScriptInline($file) {
|
||||
echo '<script src="' . $file . '"></script>';
|
||||
}
|
||||
|
||||
public static function addStyleDeclaration($css) {
|
||||
$doc = Factory::getDocument();
|
||||
$doc->addStyleDeclaration($css);
|
||||
}
|
||||
|
||||
public static function addStyleDeclarationInline($css) {
|
||||
echo '<style>' . $css . '</style>';
|
||||
}
|
||||
|
||||
public static function addStylesheet($file) {
|
||||
$doc = Factory::getDocument();
|
||||
$doc->addStylesheet($file);
|
||||
}
|
||||
|
||||
public static function addStylesheetInline($file) {
|
||||
echo '<link href="' . $file . '"" rel="stylesheet" />';
|
||||
}
|
||||
|
||||
public static function error($msg) {
|
||||
throw new \Exception($msg);
|
||||
}
|
||||
|
||||
public static function triggerEvent($name, $e = array()) {
|
||||
if (version_compare(JVERSION,'4') < 1) {
|
||||
$dispatcher = \JEventDispatcher::getInstance();
|
||||
return $dispatcher->trigger($name, $e);
|
||||
} else {
|
||||
return Factory::getApplication()->triggerEvent($name, $e);
|
||||
}
|
||||
}
|
||||
|
||||
public static function importPlugin($group) {
|
||||
if (version_compare(JVERSION,'4') < 1) {
|
||||
\JPluginHelper::importPlugin($group);
|
||||
} else {
|
||||
PluginHelper::importPlugin($group);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getModel($modelName, $classPrefix = 'Pagebuilderck') {
|
||||
require_once PAGEBUILDERCK_PATH . '/helpers/ckmodel.php';
|
||||
return CKModel::getInstance($modelName, $classPrefix);
|
||||
}
|
||||
|
||||
public static function getUserState($name, $default = '', $type = 'string') {
|
||||
$session = \JFactory::getSession();
|
||||
$state = $session->get(self::$environment . '.' . $name, $default);
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
public static function setUserState($name, $value) {
|
||||
$session = \JFactory::getSession();
|
||||
$session->set(self::$environment . '.' . $name, $value);
|
||||
}
|
||||
|
||||
public static function getSession($name, $default = null) {
|
||||
$namespace = self::$environment;
|
||||
|
||||
if (isset($_SESSION[$namespace][$name]))
|
||||
{
|
||||
return $_SESSION[$namespace][$name];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public static function setSession($name, $value) {
|
||||
$namespace = self::$environment;
|
||||
|
||||
$old = isset($_SESSION[$namespace][$name]) ? $_SESSION[$namespace][$name] : null;
|
||||
|
||||
if ($value === null)
|
||||
{
|
||||
unset($_SESSION[$namespace][$name]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION[$namespace][$name] = $value;
|
||||
}
|
||||
|
||||
return $old;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.filesystem.folder');
|
||||
|
||||
class CKFolder extends \JFolder {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @name CK Framework
|
||||
* @copyright Copyright (C) 2019. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
namespace Pagebuilderck;
|
||||
|
||||
// No direct access to this file
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
//require_once 'cktext.php';
|
||||
|
||||
//use Joomla\CMS\Language\Text as CKText;
|
||||
use Joomla\CMS\Uri\Uri as CKUri;
|
||||
|
||||
/**
|
||||
* Framework Helper
|
||||
*/
|
||||
class CKFramework {
|
||||
|
||||
private static $assetsPath = '/media/com_pagebuilderck/assets';
|
||||
|
||||
private static $version = '1.0.0';
|
||||
|
||||
private static $doload;
|
||||
|
||||
public static function init() {
|
||||
global $ckframeworkloaded;
|
||||
global $ckframeworkloadedversion;
|
||||
|
||||
// if the framework is already loaded with a same or better version, do nothing
|
||||
if ($ckframeworkloaded && version_compare($ckframeworkloadedversion, self::$version, '>=')) {
|
||||
self::$doload = false;
|
||||
}
|
||||
|
||||
self::$doload = true;
|
||||
}
|
||||
|
||||
public static function getInline() {
|
||||
if (self::$doload === false) return '';
|
||||
|
||||
$assets = self::getInlineCss() . self::getInlineJs();
|
||||
|
||||
return $assets;
|
||||
}
|
||||
|
||||
public static function getInlineCss() {
|
||||
if (self::$doload === false) return '';
|
||||
|
||||
$assets = '<link rel="stylesheet" href="' . CKUri::root(true) . self::$assetsPath . '/ckframework.css" type="text/css" />';
|
||||
|
||||
return $assets;
|
||||
}
|
||||
|
||||
public static function getInlineJs() {
|
||||
if (self::$doload === false) return '';
|
||||
|
||||
$assets = '<script src="' . CKUri::root(true) . self::$assetsPath . '/ckframework.js" type="text/javascript"></script>';
|
||||
|
||||
return $assets;
|
||||
}
|
||||
|
||||
public static function loadInline() {
|
||||
echo self::getInline();
|
||||
}
|
||||
|
||||
public static function load() {
|
||||
if (self::$doload === false) return;
|
||||
|
||||
\JHtml::_('jquery.framework');
|
||||
$doc = \JFactory::getDocument();
|
||||
$doc->addStylesheet(CKUri::root(true) . self::$assetsPath . '/ckframework.css');
|
||||
$doc->addScript(CKUri::root(true) . self::$assetsPath . '/ckframework.js');
|
||||
}
|
||||
|
||||
public static function loadCss() {
|
||||
if (self::$doload === false) return;
|
||||
|
||||
$doc = \JFactory::getDocument();
|
||||
$doc->addStylesheet(CKUri::root(true) . self::$assetsPath . '/ckframework.css');
|
||||
}
|
||||
|
||||
public static function loadJs() {
|
||||
if (self::$doload === false) return;
|
||||
|
||||
$doc = \JFactory::getDocument();
|
||||
$doc->addScript(CKUri::root(true) . self::$assetsPath . '/ckframework.js');
|
||||
}
|
||||
|
||||
public static function getFaIconsInline() {
|
||||
return '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" />';
|
||||
}
|
||||
|
||||
public static function loadFaIconsInline() {
|
||||
echo self::getFaIconsInline();
|
||||
}
|
||||
}
|
||||
|
||||
CKFramework::init();
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class CKInput extends \JInput {
|
||||
|
||||
}
|
||||
202
administrator/components/com_pagebuilderck/helpers/ckmodel.php
Normal file
202
administrator/components/com_pagebuilderck/helpers/ckmodel.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
Namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use Pagebuilderck\CKFof;
|
||||
|
||||
class CKModel {
|
||||
|
||||
var $_item = null;
|
||||
|
||||
private static $instance = array();
|
||||
|
||||
protected $input;
|
||||
|
||||
protected $table;
|
||||
|
||||
protected $__state_set = null;
|
||||
|
||||
protected $state;
|
||||
|
||||
protected $pagination;
|
||||
|
||||
private static $name;
|
||||
|
||||
private static $prefix;
|
||||
|
||||
function __construct() {
|
||||
$this->input = CKFof::getInput();
|
||||
$this->state = new \JObject;
|
||||
}
|
||||
|
||||
static function getInstance($name, $prefix, $config = array()) {
|
||||
self::$name = $name;
|
||||
self::$prefix = $prefix;
|
||||
if (isset(self::$instance[$name . $prefix]) && is_object(self::$instance[$name . $prefix]))
|
||||
{
|
||||
return self::$instance[$name . $prefix];
|
||||
}
|
||||
|
||||
$basePath = PAGEBUILDERCK_BASE_PATH;
|
||||
// Check for a controller.task command.
|
||||
$input = CKFof::getInput();
|
||||
|
||||
// Define the controller filename and path.
|
||||
$file = strtolower($name . '.php');
|
||||
$path = $basePath . '/models/' . $file;
|
||||
|
||||
// Get the controller class name.
|
||||
$class = ucfirst($prefix) . 'Model' . ucfirst($name);
|
||||
|
||||
// Include the class if not present.
|
||||
if (!class_exists($class))
|
||||
{
|
||||
// If the controller file path exists, include it.
|
||||
if (file_exists($path))
|
||||
{
|
||||
require_once $path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// throw new \InvalidArgumentException(\JText::sprintf('ERROR_INVALID_MODEL', $type, $format));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate the class.
|
||||
if (!class_exists($class))
|
||||
{
|
||||
throw new \InvalidArgumentException(\JText::sprintf('ERROR_INVALID_MODEL_CLASS', $class));
|
||||
}
|
||||
|
||||
// Instantiate the class, store it to the static container, and return it
|
||||
return self::$instance[$name . $prefix] = new $class();
|
||||
}
|
||||
|
||||
public function save($data) {
|
||||
|
||||
}
|
||||
|
||||
public function delete($id) {
|
||||
$return = CKFof::dbDelete( $this->table, (int)$id );
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function trash($id) {
|
||||
$fields = array('state' => '-2');
|
||||
$return = CKFof::dbUpdate($this->table, (int)$id, $fields);
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function setState($property, $value = null)
|
||||
{
|
||||
return $this->state->set($property, $value);
|
||||
}
|
||||
|
||||
public function getState($property = null, $default = null)
|
||||
{
|
||||
if (!$this->__state_set)
|
||||
{
|
||||
// Protected method to auto-populate the model state.
|
||||
$this->populateState();
|
||||
|
||||
// Set the model state set flag to true.
|
||||
$this->__state_set = true;
|
||||
}
|
||||
|
||||
return $property === null ? $this->state : $this->state->get($property, $default);
|
||||
}
|
||||
|
||||
protected function populateState()
|
||||
{
|
||||
$config = \JFactory::getConfig();
|
||||
$state = CKFof::getUserState(self::$prefix . '.' . self::$name, null);
|
||||
|
||||
// first request, or custom user request
|
||||
if ($state === null || $this->input->get('state_request', 0, 'int') === 1) {
|
||||
$this->state->set('filter_order', $this->input->get('filter_order', 'a.id'));
|
||||
$this->state->set('filter_order_Dir', $this->input->get('filter_order_Dir', 'asc'));
|
||||
$this->state->set('filter_search', $this->input->get('filter_search', '', 'string'));
|
||||
$this->state->set('limitstart', $this->input->get('limitstart', 0));
|
||||
$this->state->set('limit_total', $this->input->get('limittotal', 0));
|
||||
$this->state->set('limit', $this->input->get('limit', $config->get('list_limit')));
|
||||
$state = CKFof::setUserState(self::$prefix . '.' . self::$name, $this->state);
|
||||
} else {
|
||||
$this->state = $state;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPagination($total = null, $start = null, $limit = null)
|
||||
{
|
||||
if (!$this->pagination)
|
||||
{
|
||||
$total = $this->state->get('limit_total', $total);
|
||||
// $total = $this->getTotal();
|
||||
$start = $this->state->get('limitstart', $start);
|
||||
$limit = $this->state->get('limit', $limit);
|
||||
|
||||
$this->pagination = new \JPagination($total, $start, $limit);
|
||||
}
|
||||
|
||||
return $this->pagination;
|
||||
}
|
||||
|
||||
public function getTotal($query) {
|
||||
$db = CKFof::getDbo();
|
||||
$query = clone $query;
|
||||
$query->clear('select')->clear('order')->clear('limit')->clear('offset')->select('COUNT(*)');
|
||||
$db->setQuery($query);
|
||||
|
||||
return (int) $db->loadResult();
|
||||
}
|
||||
|
||||
public function copy($id) {
|
||||
$row = CKFof::dbLoad($this->table, (int)$id);
|
||||
$row->id = 0;
|
||||
$row->title = $row->title . ' - copy';
|
||||
|
||||
$newid = CKFof::dbStore($this->table, $row);
|
||||
|
||||
return $newid;
|
||||
}
|
||||
|
||||
public function checkout($id) {
|
||||
$user = CKFof::getUser();
|
||||
$query= "SELECT checked_out from " . $this->table . " WHERE id = " . (int)$id;
|
||||
$checkedout = CKFof::dbLoadResult($query);
|
||||
|
||||
if ($checkedout && $checkedout != $user->id) return false;
|
||||
|
||||
return CKFof::dbUpdate($this->table, $id, array('checked_out' => $user->id));
|
||||
}
|
||||
|
||||
public function checkin($id) {
|
||||
$user = CKFof::getUser();
|
||||
$row = CKFof::dbLoad($this->table, (int)$id);
|
||||
$canCheckIn = $row->checked_out == $user->get('id') || CKFof::userCan('core.edit.state');
|
||||
if ($canCheckIn) {
|
||||
return CKFof::dbUpdate($this->table, $id, array('checked_out' => '0'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function publish($id) {
|
||||
$row = CKFof::dbLoad($this->table, (int)$id);
|
||||
$row->state = 1;
|
||||
|
||||
$result = CKFof::dbStore($this->table, $row);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function unpublish($id) {
|
||||
$row = CKFof::dbLoad($this->table, (int)$id);
|
||||
$row->state = 0;
|
||||
|
||||
$result = CKFof::dbStore($this->table, $row);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
class CKPath extends \JPath {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class CKText extends \JText {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
Namespace Pagebuilderck;
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
class CKView {
|
||||
|
||||
protected $name;
|
||||
|
||||
protected $model;
|
||||
|
||||
protected $input;
|
||||
|
||||
protected $item;
|
||||
|
||||
protected $state;
|
||||
|
||||
protected $items;
|
||||
|
||||
protected $pagination;
|
||||
|
||||
public function __construct() {
|
||||
$this->input = CKFof::getInput();
|
||||
// check if the user has the rights to access this page
|
||||
if ( (CKFof::isAdmin()
|
||||
|| $this->input->get('layout') == 'edit'
|
||||
|| $this->input->get('task') == 'edit')
|
||||
&& !CKFof::userCan('edit')) {
|
||||
CKFof::_die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method since PHP 8.2
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __set(string $name, mixed $value): void {
|
||||
|
||||
}
|
||||
|
||||
public function display($tpl = 'default') {
|
||||
if ($tpl === null) $tpl = 'default';
|
||||
if ($this->model) {
|
||||
$this->state = $this->model->getState();
|
||||
$this->pagination = $this->model->getPagination();
|
||||
}
|
||||
|
||||
$tpl = $this->input->get('layout', $tpl);
|
||||
require_once PAGEBUILDERCK_BASE_PATH . '/views/' . strtolower($this->name) . '/tmpl/' . $tpl . '.php';
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setModel($model) {
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function get($func, $params = array()) {
|
||||
$model = $this->getModel();
|
||||
if ($model === false) return false;
|
||||
$funcName = 'get' . ucfirst($func);
|
||||
return $model->$funcName($params);
|
||||
}
|
||||
|
||||
public function getModel() {
|
||||
if (empty($this->model)) {
|
||||
$file = PAGEBUILDERCK_BASE_PATH . '/models/' . strtolower($this->name) . '.php';
|
||||
if (! file_exists($file)) return false;
|
||||
require_once($file);
|
||||
$className = '\Pagebuilderck\CKModel' . ucfirst($this->name);
|
||||
$this->model = new $className;
|
||||
}
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2019. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Pagebuilderck\CKfof;
|
||||
|
||||
// get global component params
|
||||
$pagebuilderckParams = JComponentHelper::getParams('com_pagebuilderck');
|
||||
// loads shared colors from the template
|
||||
$colorsFromTemplate = PagebuilderckHelper::loadTemplateColors();
|
||||
$colorsFromSettings = PagebuilderckHelper::loadSettingsColors();
|
||||
?>
|
||||
<script>
|
||||
var PAGEBUILDERCK = {
|
||||
TOKEN : '<?php echo JFactory::getSession()->getFormToken() ?>=1',
|
||||
URIBASE : '<?php echo JUri::base(true) ?>',
|
||||
URIBASEABS : '<?php echo JUri::base() ?>',
|
||||
URIROOT : '<?php echo JUri::root(true) ?>',
|
||||
URIROOTABS : '<?php echo JUri::root() ?>',
|
||||
URIPBCK : '<?php echo JUri::base() ?>index.php?option=com_pagebuilderck',
|
||||
MEDIA_URI : '<?php echo PAGEBUILDERCK_MEDIA_URI ?>',
|
||||
ADMIN_URL : '<?php echo PAGEBUILDERCK_ADMIN_URL ?>',
|
||||
NESTEDROWS : '<?php echo $pagebuilderckParams->get('nestedrows', '0', 'int') ?>',
|
||||
COLORSFROMTEMPLATE : '<?php echo $colorsFromTemplate ?>',
|
||||
COLORSFROMSETTINGS : '<?php echo $colorsFromSettings ?>',
|
||||
ITEMACL : '<?php echo (int)CKFof::userCan('core.itemacl') ?>',
|
||||
USERGROUPS : '<?php echo implode(',', JFactory::getUser()->groups) ?>',
|
||||
TOOLTIPS : '<?php echo $pagebuilderckParams->get('tooltips', '1', 'int') ?>',
|
||||
RESPONSIVERANGE : '<?php echo $pagebuilderckParams->get('responsiverange', 'reducing', 'string') ?>',
|
||||
IMAGE_PATH_FIX : '<?php echo $pagebuilderckParams->get('image_path_fix', '1') ?>',
|
||||
USERID : '<?php echo JFactory::getUser()->id ?>',
|
||||
CLIPBOARD : '',
|
||||
ISJ4 : '<?php echo version_compare(JVERSION, "4") ?>',
|
||||
MEDIAMANAGER : 'pagebuliderck', // pagebuliderck, joomla
|
||||
FASTEDITION : '<?php echo $pagebuilderckParams->get('fastedition', '1', 'int') ?>',
|
||||
STYLESTOLOAD : '<?php echo implode(',',(array)$pagebuilderckParams->get('stylestoload', '', 'array')) ?>'
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @package com_pagebuilderck
|
||||
* @copyright Copyright (C) 2015. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// get global component params
|
||||
$pagebuilderckParams = JComponentHelper::getParams('com_pagebuilderck');
|
||||
|
||||
//if (! defined('CK_LOADED')) define('CK_LOADED', 1);
|
||||
|
||||
// set variables
|
||||
define('PAGEBUILDERCK_PLATFORM', 'joomla');
|
||||
define('PAGEBUILDERCK_BASE_PATH', JPATH_BASE . '/components/com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_PATH', JPATH_SITE . '/administrator/components/com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_PARAMS_PATH', JPATH_SITE . '/administrator/components/com_pagebuilderck/pro');
|
||||
define('PAGEBUILDERCK_PROJECTS_PATH', JPATH_SITE . '/administrator/components/com_pagebuilderck/projects');
|
||||
define('PAGEBUILDERCK_ADMIN_URL', JUri::root(true) . '/administrator/index.php?option=com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_BASE_URL', JUri::base(true) . '/index.php?option=com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_ADMIN_GENERAL_URL', JUri::root(true) . '/administrator/index.php?option=com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_MEDIA_URI', JUri::root(true) . '/media/com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_MEDIA_URL', PAGEBUILDERCK_MEDIA_URI);
|
||||
define('PAGEBUILDERCK_MEDIA_PATH', JPATH_ROOT . '/media/com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_PLUGIN_URL', PAGEBUILDERCK_MEDIA_URI);
|
||||
define('PAGEBUILDERCK_TEMPLATES_PATH', JPATH_SITE . '/templates');
|
||||
define('PAGEBUILDERCK_SITE_ROOT', JPATH_ROOT);
|
||||
define('PAGEBUILDERCK_URI', JUri::root(true) . '/administrator/components/com_pagebuilderck');
|
||||
define('PAGEBUILDERCK_URI_ROOT', JUri::root(true));
|
||||
define('PAGEBUILDERCK_URI_BASE', JUri::base(true));
|
||||
define('PAGEBUILDERCK_NESTEDROWS', $pagebuilderckParams->get('nestedrows', '0', 'int'));
|
||||
define('PAGEBUILDERCK_VERSION', simplexml_load_file(PAGEBUILDERCK_PATH . '/pagebuilderck.xml')->version);
|
||||
define('PAGEBUILDERCK_ISJ4', version_compare(JVERSION, "4") >= 0);
|
||||
define('PAGEBUILDERCK_LOADEDITORCSS', $pagebuilderckParams->get('loadeditorcss', '0', 'int'));
|
||||
|
||||
// include the classes
|
||||
require_once PAGEBUILDERCK_PATH . '/helpers/ckinput.php';
|
||||
require_once PAGEBUILDERCK_PATH . '/helpers/cktext.php';
|
||||
require_once PAGEBUILDERCK_PATH . '/helpers/ckfile.php';
|
||||
require_once PAGEBUILDERCK_PATH . '/helpers/ckfolder.php';
|
||||
require_once PAGEBUILDERCK_PATH . '/helpers/ckfof.php';
|
||||
//require_once PAGEBUILDERCK_PATH . '/helpers/helper.php';
|
||||
//require_once PAGEBUILDERCK_PATH . '/helpers/ckcontroller.php';
|
||||
//require_once PAGEBUILDERCK_PATH . '/helpers/ckmodel.php';
|
||||
//require_once PAGEBUILDERCK_PATH . '/helpers/ckview.php';
|
||||
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @copyright Copyright (C) since 2011. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
namespace Pagebuilderck;
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
if (! defined('CK_LOADED')) define('CK_LOADED', 1);
|
||||
|
||||
require_once 'ckinput.php';
|
||||
require_once 'cktext.php';
|
||||
// require_once 'ckpath.php';
|
||||
require_once 'ckfile.php';
|
||||
require_once 'ckfolder.php';
|
||||
require_once 'ckfof.php';
|
||||
//use Joomla\CMS\Language\Text as CKText;
|
||||
use Joomla\CMS\Uri\Uri as CKUri;
|
||||
|
||||
use Pagebuilderck\CKFof;
|
||||
|
||||
/**
|
||||
* Front Edition helper
|
||||
*/
|
||||
class FrontEdition {
|
||||
|
||||
public static function init() {
|
||||
// return; // TODO remove to enable front edition
|
||||
if (! self::canUseFrontendEdition()) return;
|
||||
|
||||
$pagebuilderckParams = \JComponentHelper::getParams('com_pagebuilderck');
|
||||
// check if the front edition is enabled from the options
|
||||
$enableFrontedition = $pagebuilderckParams->get('frontedition', '1', 'int');
|
||||
if ($enableFrontedition == 0) return;
|
||||
|
||||
// load language file
|
||||
$lang = \JFactory::getLanguage();
|
||||
$lang->load('com_pagebuilderck', JPATH_SITE . '/components/com_pagebuilderck', $lang->getTag(), false);
|
||||
|
||||
global $pagebuilderckEditionLoaded, $ckFrontEditionLoaded;
|
||||
$pagebuilderckEditionLoaded = true;
|
||||
|
||||
$input = CKFof::getInput();
|
||||
$user = CKFof::getUser();
|
||||
if ($user->id && $input->get('tckedition', 0, 'int') === 1) {
|
||||
if (! $ckFrontEditionLoaded) echo self::renderMenu();
|
||||
|
||||
$editor = \JFactory::getConfig()->get('editor') == 'jce' ? 'jce' : 'tinymce';
|
||||
$editor = \JEditor::getInstance($editor);
|
||||
$editor->display('ckeditor', $html = '', $width = '', $height = '200px', $col='', $row='', $buttons = true, $id = 'ckeditor');
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/menustyles.php';
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/stylescss.php';
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/ckeditor.php';
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/pagebuilderck.php';
|
||||
include_once(JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/views/page/tmpl/include.php');
|
||||
include_once(JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/views/page/tmpl/menu.php');
|
||||
include_once(JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/views/page/tmpl/toolbar.php');
|
||||
?>
|
||||
<link rel="stylesheet" href="<?php echo PAGEBUILDERCK_MEDIA_URI ?>/assets/frontedition.css" type="text/css" />
|
||||
<script src="<?php echo PAGEBUILDERCK_MEDIA_URI ?>/assets/frontedition.js" type="text/javascript"></script>
|
||||
<?php
|
||||
} else {
|
||||
if ($user->id) {
|
||||
$buttons = self::getActivationButton();
|
||||
$html = self::getEmptyMenu($buttons);
|
||||
echo $html;
|
||||
?>
|
||||
<link rel="stylesheet" href="<?php echo PAGEBUILDERCK_MEDIA_URI ?>/assets/ckframework.css" type="text/css" />
|
||||
<link rel="stylesheet" href="<?php echo PAGEBUILDERCK_MEDIA_URI ?>/assets/frontedition.css" type="text/css" />
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
// check if modules manager ck is used and if the correct version is insalled
|
||||
self::checkModulesmanagerckCompatibility();
|
||||
|
||||
$ckFrontEditionLoaded = true;
|
||||
/*$user = CKFof::getUser();
|
||||
$input = CKFof::getInput();
|
||||
// if user logged in
|
||||
if ($user->id && $input->get('tckedition', 0, 'int') === 1) {
|
||||
// self::renderMenu();
|
||||
// get current uri
|
||||
$uri = JFactory::getURI();
|
||||
$current_url = $uri->toString();
|
||||
// CKFof::redirect(JUri::root(true) . '/index.php?option=com_pagebuilderck&view=frontedition&url=' . urlencode($current_url));
|
||||
|
||||
// $this->callTemplateEdition();
|
||||
}*/
|
||||
// self::callTemplateEdition();
|
||||
}
|
||||
|
||||
public static function getEmptyMenu($buttons = '') {
|
||||
ob_start();
|
||||
?>
|
||||
<div id="ckheader">
|
||||
<div class="ckheaderlogo"><a href="https://www.joomlack.fr" target="_blank"><img width="35" height="35" title="JoomlaCK" src="https://media.joomlack.fr/images/logo_ck_white.png" /></a></div>
|
||||
<div class="ckheadermenu">
|
||||
<?php echo $buttons; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
echo self::getCssForEdition();
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/* load only if page builder ck is not already loaded */
|
||||
public static function renderMenu() {
|
||||
$current_url = self::getCurrentUri();
|
||||
ob_start();
|
||||
$mmckbuttons = '';
|
||||
$editionfilemmck = JPATH_SITE . '/components/com_modulesmanagerck/helpers/frontedition.php';
|
||||
if (file_exists($editionfilemmck)) {
|
||||
require_once $editionfilemmck;
|
||||
if (\Modulesmanagerck\FrontEdition::canUseFrontendEdition()) {
|
||||
$mmckbuttons = \Modulesmanagerck\FrontEdition::getMenuButtons();
|
||||
echo \Modulesmanagerck\FrontEdition::getCssForEdition();
|
||||
}
|
||||
}
|
||||
?>
|
||||
<a href="<?php echo str_replace('tckedition=1', '', $current_url); ?>" class="ckheadermenuitem ckcancel" >
|
||||
<span class="fa fa-times cktip" data-placement="bottom" title="<?php echo CKText::_('CK_EXIT'); ?>"></span>
|
||||
<span class="ckheadermenuitemtext"><?php echo CKText::_('CK_EXIT') ?></span>
|
||||
</a>
|
||||
<a href="javascript:void(0);" class="ckheadermenuitem cksave" onclick="ckPagebuilderFrontEditionSave()">
|
||||
<span class="fa fa-check cktip" data-placement="bottom" title="<?php echo CKText::_('CK_SAVE'); ?>"></span>
|
||||
<span class="ckheadermenuitemtext"><?php echo CKText::_('CK_SAVE') ?></span>
|
||||
</a>
|
||||
<?php
|
||||
echo self::getCssForEdition();
|
||||
$buttons = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$html = self::getEmptyMenu($mmckbuttons . $buttons);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function that can be called by others like Page Builder CK to integrate the buttons in another toolbar
|
||||
*/
|
||||
public static function getActivationButton() {
|
||||
$link = (CKURI::getInstance()->getQuery() ? self::getCurrentUri() . '&tckedition=1' : self::getCurrentUri() . '?tckedition=1');
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<a href="<?php echo $link ?>" class="ckheadermenuitem">
|
||||
<span class="fa fa-toggle-on cktip" title="<?php echo CKText::_('CK_ENABLE'); ?> <?php echo CKText::_('CK_FRONT_EDITION'); ?>"></span>
|
||||
<span class="ckheadermenuitemtext"><?php echo CKText::_('CK_ENABLE'); ?> <?php echo CKText::_('CK_FRONT_EDITION'); ?></span>
|
||||
</a>
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private static function getCurrentUri() {
|
||||
// $uri = \JFactory::getURI();
|
||||
$uri = \Juri::getInstance();
|
||||
return $uri->toString();
|
||||
}
|
||||
|
||||
public static function getCssForEdition() {
|
||||
ob_start();
|
||||
?>
|
||||
<style>
|
||||
.menuck {
|
||||
top: 65px !important;
|
||||
}
|
||||
|
||||
#ckheader .ckheadermenu .ckheadermenuitem {
|
||||
font-size: 13px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
|
||||
html {
|
||||
padding-top: 66px! important;
|
||||
}
|
||||
|
||||
body.tck-edition-body #ckheader {
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
body.tck-edition-body .tab_fullscreen {
|
||||
top:65px;
|
||||
}
|
||||
|
||||
div.menuck > .inner {
|
||||
height: calc(100vh - 115px);
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public static function canUseFrontendEdition() {
|
||||
// check that the user has the rights to edit
|
||||
$user = \JFactory::getUser();
|
||||
$app = \JFactory::getApplication();
|
||||
$authorised = ($user->authorise('core.edit', 'com_pagebuilderck'));
|
||||
// check the ACL from the component config
|
||||
$canusefrontedition = $user->authorise('core.frontedition', 'com_pagebuilderck');
|
||||
if (! $canusefrontedition) return false;
|
||||
|
||||
if ($authorised !== true)
|
||||
{
|
||||
return false;
|
||||
// if ($user->guest === 1)
|
||||
// {
|
||||
// $return = base64_encode(CKUri::getInstance());
|
||||
// $login_url_with_return = \JRoute::_('index.php?option=com_users&return=' . $return);
|
||||
// $app->enqueueMessage(CKText::_('JERROR_ALERTNOAUTHOR'), 'notice');
|
||||
// $app->redirect($login_url_with_return, 403);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $app->enqueueMessage(CKText::_('JERROR_ALERTNOAUTHOR'), 'error');
|
||||
// $app->setHeader('status', 403, true);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
// check that the template is compatible
|
||||
$app = \JFactory::getApplication();
|
||||
$template = $app->getTemplate();
|
||||
|
||||
// load xml file from the template
|
||||
$xml = simplexml_load_file(JPATH_SITE . '/templates/' . $template . '/templateDetails.xml');
|
||||
|
||||
// check that the template is made with a compatible version of Template Creator CK
|
||||
if ($xml->generator != 'Template Creator CK') {
|
||||
// JError::raiseWarning(403, CKText::_('The template you are trying to edit has not been created with Template Creator CK, or not the latest version of if. You can download Template Creator CK on <a href="https://www.template-creator.com">https://www.template-creator.com</a>'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function checkModulesmanagerckCompatibility() {
|
||||
if (! file_exists(JPATH_ROOT . '/components/com_modulesmanagerck/modulesmanagerck.php')) return true;
|
||||
$xmlData = self::getXmlData(JPATH_ROOT . '/administrator/components/com_modulesmanagerck/modulesmanagerck.xml');
|
||||
$installedVersion = ((string)($xmlData->version));
|
||||
|
||||
// if the installed version is the V1
|
||||
if(version_compare($installedVersion, '1.3.1', '<')) {
|
||||
// if the params is also installed
|
||||
if (\JPluginHelper::isEnabled('system', 'modulesmanagersystemck')) {
|
||||
// throw new \RuntimeException('Slideshow CK Light cannot be installed over Slideshow CK V1 + Params. Please install Slideshow CK Pro to get the same features as previously, else you may loose your existing settings. To downgrade, please first uninstall Slideshow CK Params. <a href="https://www.joomlack.fr/en/documentation/48-slideshow-ck/246-migration-from-slideshow-ck-version-1-to-version-2" target="_blank">Read more</a>');
|
||||
echo '<p style="color:red;font-size: 20px">WARNING : Modules Manager CK has been detected but its version is not up to date. You must set up your system correctly or it will not work.<br/> <a href="https://www.joomlack.fr/documentation/page-builder-ck/250-front-edtion" target="_blank">Please check the documentation</a></p>';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getXmlData($file) {
|
||||
if ( ! is_file($file))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$xml = simplexml_load_file($file);
|
||||
|
||||
if ( ! $xml || ! isset($xml['version']))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
||||
// autoload the edition
|
||||
//PBCK_FrontEdition::init();
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @package com_pagebuilderck
|
||||
* @copyright Copyright (C) 2015. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Loader Class.
|
||||
*/
|
||||
class PagebuilderckLoaderArticles {
|
||||
|
||||
private static $params;
|
||||
|
||||
/*
|
||||
* Get the items from the source
|
||||
*/
|
||||
public static function getItems($params) {
|
||||
if (empty(self::$params)) {
|
||||
self:$params = $params;
|
||||
}
|
||||
|
||||
// load the content articles file
|
||||
$com_path = JPATH_SITE . '/components/com_content/';
|
||||
if (! PAGEBUILDERCK_ISJ4) {
|
||||
include_once $com_path . 'router.php';
|
||||
include_once $com_path . 'helpers/route.php';
|
||||
}
|
||||
JModelLegacy::addIncludePath($com_path . '/models', 'ContentModel');
|
||||
|
||||
// Get an instance of the generic articles model
|
||||
$articles = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
|
||||
|
||||
// Set application parameters in model
|
||||
$app = JFactory::getApplication();
|
||||
$appParams = $app->getParams();
|
||||
$articles->setState('params', $appParams);
|
||||
|
||||
// Set the filters based on the module params
|
||||
$articles->setState('list.start', 0);
|
||||
if ($params->get('articleimgsource', 'introimage') == 'text') {
|
||||
$articles->setState('list.limit', $params->get('numberslides',0));
|
||||
} else {
|
||||
$articles->setState('list.limit', 0);
|
||||
}
|
||||
$articles->setState('filter.published', 1);
|
||||
|
||||
// Access filter
|
||||
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
|
||||
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
|
||||
$articles->setState('filter.access', $access);
|
||||
|
||||
// Prep for Normal or Dynamic Modes
|
||||
$mode = $params->get('mode', 'normal');
|
||||
$option = $app->input->get('option', '', 'cmd');
|
||||
$view = $app->input->get('view', '', 'cmd');
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'dynamic':
|
||||
if ($option === 'com_content') {
|
||||
switch($view)
|
||||
{
|
||||
case 'category':
|
||||
$catids = array($app->input->get('id', 0, 'int'));
|
||||
break;
|
||||
case 'categories':
|
||||
$catids = array($app->input->get('id', 0, 'int'));
|
||||
break;
|
||||
case 'article':
|
||||
if ($params->get('show_on_article_page', 1)) {
|
||||
$article_id = $app->input->get('id', 0, 'int');
|
||||
$catid = $app->input->get('catid', 0, 'int');
|
||||
|
||||
if (!$catid) {
|
||||
// Get an instance of the generic article model
|
||||
$article = JModelLegacy::getInstance('Article', 'ContentModel', array('ignore_request' => true));
|
||||
|
||||
$article->setState('params', $appParams);
|
||||
$article->setState('filter.published', 1);
|
||||
$article->setState('article.id', (int) $article_id);
|
||||
$item = $article->getItem();
|
||||
|
||||
$catids = array($item->catid);
|
||||
}
|
||||
else {
|
||||
$catids = array($catid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Return right away if show_on_article_page option is off
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'featured':
|
||||
default:
|
||||
// Return right away if not on the category or article views
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Return right away if not on a com_content page
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'normal':
|
||||
default:
|
||||
$catids = explode(',', $params->get('catid', ''));
|
||||
$category_filtering_type = $params->get('category_filtering_type_0', '') == 'checked' ? 0 : 1;
|
||||
$articles->setState('filter.category_id.include', (bool) $category_filtering_type);
|
||||
break;
|
||||
}
|
||||
|
||||
// Category filter
|
||||
if (! empty($catids) && isset($catids[0]) && ! empty($catids[0])) {
|
||||
$show_child_category_articles = $params->get('show_child_category_articles_1', 1) == 'checked' ? 1 : 0;
|
||||
if ($show_child_category_articles && (int) $params->get('levels', 0) > 0) {
|
||||
// Get an instance of the generic categories model
|
||||
$categories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
|
||||
$categories->setState('params', $appParams);
|
||||
$levels = $params->get('levels', 1) ? $params->get('levels', 1) : 9999;
|
||||
$categories->setState('filter.get_children', $levels);
|
||||
$categories->setState('filter.published', 1);
|
||||
$categories->setState('filter.access', $access);
|
||||
$additional_catids = array();
|
||||
foreach($catids as $catid)
|
||||
{
|
||||
$categories->setState('filter.parentId', $catid);
|
||||
$recursive = true;
|
||||
$items = $categories->getItems($recursive);
|
||||
|
||||
if ($items)
|
||||
{
|
||||
foreach($items as $category)
|
||||
{
|
||||
$condition = (($category->level - $categories->getParent()->level) <= $levels);
|
||||
if ($condition) {
|
||||
$additional_catids[] = $category->id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$catids = array_unique(array_merge($catids, $additional_catids));
|
||||
}
|
||||
|
||||
$articles->setState('filter.category_id', $catids);
|
||||
}
|
||||
|
||||
// Ordering
|
||||
$articles->setState('list.ordering', $params->get('article_ordering', 'a.ordering'));
|
||||
$articles->setState('list.direction', $params->get('article_ordering_direction', 'ASC'));
|
||||
|
||||
// New Parameters
|
||||
$articles->setState('filter.featured', $params->get('show_front', 'show'));
|
||||
// $articles->setState('filter.author_id', $params->get('created_by', ""));
|
||||
// $articles->setState('filter.author_id.include', $params->get('author_filtering_type', 1));
|
||||
// $articles->setState('filter.author_alias', $params->get('created_by_alias', ""));
|
||||
// $articles->setState('filter.author_alias.include', $params->get('author_alias_filtering_type', 1));
|
||||
$excluded_articles = $params->get('excluded_articles', '');
|
||||
|
||||
// exclude by default the current article
|
||||
$option = $app->input->get('option', '', 'cmd');
|
||||
$view = $app->input->get('view', '', 'cmd');
|
||||
if ($option == 'com_content' && $view == 'article') {
|
||||
$excluded_articles .= ',' . $app->input->get('id', 0, 'int');
|
||||
}
|
||||
if ($excluded_articles) {
|
||||
// $excluded_articles = explode("\r\n", $excluded_articles);
|
||||
$excluded_articles = explode(",", $excluded_articles);
|
||||
$articles->setState('filter.article_id', $excluded_articles);
|
||||
$articles->setState('filter.article_id.include', false); // Exclude
|
||||
}
|
||||
|
||||
$date_filtering = $params->get('date_filtering', 'off');
|
||||
if ($date_filtering !== 'off') {
|
||||
$articles->setState('filter.date_filtering', $date_filtering);
|
||||
$articles->setState('filter.date_field', $params->get('date_field', 'a.created'));
|
||||
$articles->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00'));
|
||||
$articles->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59'));
|
||||
$articles->setState('filter.relative_date', $params->get('relative_date', 30));
|
||||
}
|
||||
|
||||
// Filter by language
|
||||
$articles->setState('filter.language', $app->getLanguageFilter());
|
||||
|
||||
$items = $articles->getItems();
|
||||
|
||||
// Display options
|
||||
// $show_date = $params->get('show_date', 0);
|
||||
$show_date_field = $params->get('show_date_field', 'created');
|
||||
$show_date_format = $params->get('show_date_format', JText::_('DATE_FORMAT_LC6'));
|
||||
// $show_category = $params->get('show_category', 0);
|
||||
// $show_hits = $params->get('show_hits', 0);
|
||||
// $show_author = $params->get('show_author', 0);
|
||||
// $show_introtext = $params->get('show_introtext', 0);
|
||||
// $introtext_limit = $params->get('text_limit', 100);
|
||||
|
||||
// Find current Article ID if on an article page
|
||||
// if ($option === 'com_content' && $view === 'article') {
|
||||
// $active_article_id = $app->input->get('id', 0, 'int');
|
||||
// }
|
||||
// else {
|
||||
// $active_article_id = 0;
|
||||
// }
|
||||
|
||||
// Prepare data for display using display options
|
||||
$slideItems = Array();
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
$item->slug = $item->id.':'.$item->alias;
|
||||
$item->catslug = $item->catid ? $item->catid .':'.$item->category_alias : $item->catid;
|
||||
|
||||
if ($access || in_array($item->access, $authorised)) {
|
||||
// We know that user has the privilege to view the article
|
||||
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
|
||||
}
|
||||
else {
|
||||
// Angie Fixed Routing
|
||||
$app = JFactory::getApplication();
|
||||
$menu = $app->getMenu();
|
||||
$menuitems = $menu->getItems('link', 'index.php?option=com_users&view=login');
|
||||
if(isset($menuitems[0])) {
|
||||
$Itemid = $menuitems[0]->id;
|
||||
} elseif ($app->input->get('Itemid', 0, 'int') > 0) { //use Itemid from requesting page only if there is no existing menu
|
||||
$Itemid = $app->input->get('Itemid', 0, 'int');
|
||||
}
|
||||
|
||||
$item->link = JRoute::_('index.php?option=com_users&view=login&Itemid='.$Itemid);
|
||||
}
|
||||
|
||||
// Used for styling the active article
|
||||
// $item->active = $item->id == $active_article_id ? 'active' : '';
|
||||
|
||||
$item->displayDate = '';
|
||||
// if ($show_date) {
|
||||
$item->displayDate = JHTML::_('date', $item->$show_date_field, $show_date_format);
|
||||
// }
|
||||
|
||||
// if ($item->catid) {
|
||||
// $item->displayCategoryLink = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catid));
|
||||
// $item->displayCategoryTitle = $show_category ? '<a href="'.$item->displayCategoryLink.'">'.$item->category_title.'</a>' : '';
|
||||
// }
|
||||
// else {
|
||||
// $item->displayCategoryTitle = $show_category ? $item->category_title : '';
|
||||
// }
|
||||
|
||||
// $item->displayHits = $show_hits ? $item->hits : '';
|
||||
// $item->displayAuthorName = $show_author ? $item->author : '';
|
||||
// if ($show_introtext) {
|
||||
// $item->introtext = JHtml::_('content.prepare', $item->introtext, '', 'mod_articles_category.content');
|
||||
// $item->introtext = self::_cleanIntrotext($item->introtext);
|
||||
// }
|
||||
// $item->displayIntrotext = $show_introtext ? self::truncate($item->introtext, $introtext_limit) : '';
|
||||
// $item->displayReadmore = $item->alternative_readmore;
|
||||
|
||||
// add the article to the slide
|
||||
$registry = new JRegistry;
|
||||
$registry->loadString($item->images);
|
||||
$item->images = $registry->toArray();
|
||||
$article_image = false;
|
||||
$slideItem_article_text = '';
|
||||
|
||||
switch ($params->get('imgsource', 'introimage')) {
|
||||
case 'firstimage':
|
||||
$search_images = preg_match('/<img(.*?)src="(.*?)"(.*?)>/is', $item->introtext, $imgresult);
|
||||
$article_image = (isset($imgresult[2]) && $imgresult[2] != '') ? $imgresult[2] : false;
|
||||
$slideItem_article_text = (isset($imgresult[2])) ? str_replace($imgresult[0], '', $item->introtext) : $item->introtext;
|
||||
break;
|
||||
case 'fullimage':
|
||||
$article_image = (isset($item->images['image_fulltext']) && $item->images['image_fulltext']) ? $item->images['image_fulltext'] : false;
|
||||
$slideItem_article_text = $item->introtext;
|
||||
break;
|
||||
case 'introimage':
|
||||
default:
|
||||
$article_image = (isset($item->images['image_intro']) && $item->images['image_intro']) ? $item->images['image_intro'] : false;
|
||||
$slideItem_article_text = $item->introtext;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ($article_image || $params->get('articleimgsource', 'introimage') == 'text')
|
||||
&& (count($slideItems) < (int) $params->get('numberslides', 0) || (int) $params->get('numberslides', 0) == 0)) {
|
||||
$slideItem = new stdClass();
|
||||
$slideItem->image = $article_image;
|
||||
$slideItem->images = $item->images;
|
||||
$slideItem->link = $item->link;
|
||||
$slideItem->title = $item->title;
|
||||
$slideItem->displayDate = $item->displayDate;
|
||||
// $slideItem->text = JHTML::_('content.prepare', $slideItem_article_text);
|
||||
$slideItem->text = $slideItem_article_text;
|
||||
$slideItem->article = $item;
|
||||
$slideItems[] = $slideItem;
|
||||
}
|
||||
}
|
||||
|
||||
return $slideItems;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @package com_pagebuilderck
|
||||
* @copyright Copyright (C) 2015. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Pagebuilderck\CKFolder;
|
||||
use Pagebuilderck\CKFile;
|
||||
|
||||
/**
|
||||
* Loader Class.
|
||||
*/
|
||||
class PagebuilderckLoaderFolder {
|
||||
|
||||
private static $params;
|
||||
|
||||
private static $folderLabels = array();
|
||||
|
||||
private static $imagesOrderByLabels = array();
|
||||
|
||||
public static function getItems(&$params) {
|
||||
self::$params = $params;
|
||||
|
||||
$authorisedExt = array('png', 'jpg', 'JPG', 'JPEG', 'jpeg', 'bmp', 'tiff', 'gif', 'webp', 'WEBP');
|
||||
$folder = trim($params->get('autoloadfoldername'), '/');
|
||||
if (file_exists($folder . '/labels.txt') && $params->get('autoloadfolderorderby', 'default') == 'default') {
|
||||
$items = self::loadImagesFromFolder($folder);
|
||||
} else {
|
||||
$items = CKFolder::files(JPATH_ROOT . '/' . $folder, '\.(?:png|jpe?g|bmp|tiff|PNG|JPE?G|BMP|TIFF|webp|WEBP?)$', false, false);
|
||||
|
||||
if ($params->get('autoloadfolderorderby', 'default') == 'exif') {
|
||||
foreach ($items as $i => $name) {
|
||||
$filename = JPATH_ROOT . '/' . $folder . '/' . $name;
|
||||
$exif = exif_read_data($filename, 'IFD0');
|
||||
if ($exif) {
|
||||
$items[strtotime($exif['DateTime'])] = $name;
|
||||
} else {
|
||||
$t = filemtime($filename) + $i;
|
||||
$items[$t] = $name;
|
||||
}
|
||||
unset($items[$i]);
|
||||
}
|
||||
if ($params->get('autoloadfolderorderdir', 'asc') == 'desc') {
|
||||
krsort($items);
|
||||
} else {
|
||||
ksort($items);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($items as $i => $name) {
|
||||
$item = self::initItem();
|
||||
$item->image = trim(str_replace('\\','/',$name), '/');
|
||||
$item->image = JUri::root(true) . '/' . $folder . '/' . trim($item->image, '\\');
|
||||
|
||||
if (!in_array(strToLower(CKFile::getExt($item->image)), $authorisedExt))
|
||||
continue;
|
||||
|
||||
// load the image data from txt
|
||||
$item = self::getImageDataFromfolderLegacy($item, $params);
|
||||
$items[$i] = $item;
|
||||
|
||||
// route the url
|
||||
$item->link = (string)$item->link;
|
||||
if (strcasecmp(substr($item->link, 0, 4), 'http') && (strpos($item->link, 'index.php?') !== false)) {
|
||||
$item->link = JRoute::_($item->link, true, false);
|
||||
} else {
|
||||
$item->link = JRoute::_($item->link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old method that looks for a txt file that has the same name as the image
|
||||
* @param type $item
|
||||
* @param type $params
|
||||
* @return type
|
||||
*/
|
||||
static function getImageDataFromfolderLegacy(&$item, $params) {
|
||||
// load the image data from txt
|
||||
$datafile = JPATH_ROOT . '/' . str_replace(JFile::getExt($item->image), 'txt', $item->image);
|
||||
$data = file_exists($datafile) ? file_get_contents($datafile) : '';
|
||||
$imgdatatmp = explode("\n", $data);
|
||||
|
||||
$parmsnumb = count($imgdatatmp);
|
||||
for ($i = 0; $i < $parmsnumb; $i++) {
|
||||
$imgdatatmp[$i] = trim($imgdatatmp[$i]);
|
||||
$item->text = stristr($imgdatatmp[$i], "caption=") ? str_replace('caption=', '', $imgdatatmp[$i]) : $item->text;
|
||||
$item->articleid = stristr($imgdatatmp[$i], "articleid=") ? str_replace('articleid=', '', $imgdatatmp[$i]) : $item->articleid;
|
||||
$item->video = stristr($imgdatatmp[$i], "video=") ? str_replace('video=', '', $imgdatatmp[$i]) : $item->video;
|
||||
$item->link = stristr($imgdatatmp[$i], "link=") ? str_replace('link=', '', $imgdatatmp[$i]) : $item->link;
|
||||
$item->time = stristr($imgdatatmp[$i], "time=") ? str_replace('time=', '', $imgdatatmp[$i]) : $item->time;
|
||||
$item->target = stristr($imgdatatmp[$i], "target=") ? str_replace('target=', '', $imgdatatmp[$i]) : $item->target;
|
||||
}
|
||||
|
||||
if ($item->video)
|
||||
$item->slideselect = 'video';
|
||||
|
||||
// manage the title and description
|
||||
$item->text = (string)$item->text;
|
||||
if (stristr($item->text, "||")) {
|
||||
$splitcaption = explode("||", $item->text);
|
||||
$item->text = '<div class="pagebuilderck_title">' . $splitcaption[0] . '</div><div class="pagebuilderck_description">' . $splitcaption[1] . '</div>';
|
||||
}
|
||||
|
||||
if (isset($item->articleid) && $item->articleid) {
|
||||
$item = PagebuilderckHelper::getArticle($item, $params);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
private static function getImageLabelsFromFolder($directory) {
|
||||
$dirindex = PagebuilderckHelper::cleanName($directory);
|
||||
if (! empty(self::$folderLabels[$dirindex])) return;
|
||||
|
||||
$items = array();
|
||||
$item = new stdClass();
|
||||
|
||||
// get the language
|
||||
$lang = JFactory::getLanguage();
|
||||
$langtag = $lang->getTag(); // returns fr-FR or en-GB
|
||||
|
||||
// load the image data from txt
|
||||
if (file_exists(JPATH_ROOT . '/' . $directory . '/labels.' . $langtag . '.txt')) {
|
||||
$data = file_get_contents(JPATH_ROOT . '/' . $directory . '/labels.' . $langtag . '.txt');
|
||||
} else if (file_exists(JPATH_ROOT . '/' . $directory . '/labels.txt')) {
|
||||
$data = file_get_contents(JPATH_ROOT . '/' . $directory . '/labels.txt');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
$doUTF8encode = true;
|
||||
// remove UTF-8 BOM and normalize line endings
|
||||
if (!strcmp("\xEF\xBB\xBF", substr($data,0,3))) { // file starts with UTF-8 BOM
|
||||
$data = substr($data, 3); // remove UTF-8 BOM
|
||||
$doUTF8encode = false;
|
||||
}
|
||||
$data = str_replace("\r", "\n", $data); // normalize line endings
|
||||
|
||||
// if no data found, exit
|
||||
if(! $data) return null;
|
||||
|
||||
// explode the file into rows
|
||||
// $imgdatatmp = explode("\n", $data);
|
||||
$imgdatatmp = preg_split("/\r\n|\n|\r/", $data, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$parmsnumb = count($imgdatatmp);
|
||||
for ($i = 0; $i < $parmsnumb; $i++) {
|
||||
$imgdatatmp[$i] = trim($imgdatatmp[$i]);
|
||||
$line = explode('|', $imgdatatmp[$i]);
|
||||
|
||||
// store the order or files from the TXT file
|
||||
self::$imagesOrderByLabels[] = $line[0];
|
||||
|
||||
$item = self::initItem();
|
||||
$item->index = PagebuilderckHelper::cleanName($line[0]);
|
||||
$item->title = (isset($line[1])) ? ( $doUTF8encode ? htmlspecialchars($line[1]) : htmlspecialchars($line[1]) ) : '';
|
||||
$item->text = (isset($line[2])) ? ( $doUTF8encode ? htmlspecialchars($line[2]) : htmlspecialchars($line[2]) ) : '';
|
||||
$item->link = (isset($line[3])) ? ( $doUTF8encode ? $line[3] : ($line[3]) ) : '';
|
||||
$item->video = (isset($line[4])) ? ( $doUTF8encode ? $line[4] : ($line[4]) ) : '';
|
||||
$item->articleid = (isset($line[5])) ? $line[5] : '';
|
||||
if ($item->articleid) $item = PagebuilderckHelper::getArticle($item);
|
||||
|
||||
$items[$item->index] = $item;
|
||||
}
|
||||
|
||||
self::$folderLabels[$dirindex] = $items;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the data for the image (title and description)
|
||||
*/
|
||||
private static function getImageDataFromfolder($file, $directory) {
|
||||
$filename = explode('/', $file);
|
||||
$filename = end($filename);
|
||||
$dirindex = PagebuilderckHelper::cleanName($directory);
|
||||
$fileindex = PagebuilderckHelper::cleanName($filename);
|
||||
|
||||
if (! empty(self::$folderLabels[$dirindex]) && ! empty(self::$folderLabels[$dirindex][$fileindex])) {
|
||||
$item = self::$folderLabels[$dirindex][$fileindex];
|
||||
} else {
|
||||
$item = self::initItem();
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load the image from the specified folder
|
||||
*/
|
||||
public static function loadImagesFromFolder($directory) {
|
||||
|
||||
// encode the folder path, needed if contains an accent
|
||||
try {
|
||||
$translatedDirectory = iconv("UTF-8", "ISO-8859-1//TRANSLIT", urldecode($directory));
|
||||
if ($translatedDirectory) $directory = $translatedDirectory;
|
||||
} catch (Exception $e) {
|
||||
echo 'CK Message : ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
// load the files from the folder
|
||||
$files = CKFolder::files(trim(trim($directory), '/'), '.', false, true);
|
||||
|
||||
if (! $files) return 'CK message : No files found in the directory : ' . $directory;
|
||||
|
||||
self::$imagesOrderByLabels = array();
|
||||
// load the labels from the folder
|
||||
self::getImageLabelsFromFolder($directory);
|
||||
|
||||
$order = self::$params->get('displayorder');
|
||||
// set the images order
|
||||
if ($order == 'shuffle') {
|
||||
shuffle($files);
|
||||
} else {
|
||||
natsort($files);
|
||||
$files = array_map(array('PagebuilderckHelper', 'formatPath'), $files);
|
||||
$baseDir = PagebuilderckHelper::formatPath($directory);
|
||||
$labelsOrder = array_reverse(self::$imagesOrderByLabels);
|
||||
foreach ($labelsOrder as $name) {
|
||||
$imgFile = $baseDir . '/' . $name;
|
||||
array_unshift($files, $imgFile);
|
||||
}
|
||||
// now make it unique
|
||||
$files = array_unique($files);
|
||||
}
|
||||
|
||||
$authorisedExt = array('png','jpg','jpeg','bmp','tiff','gif','webp');
|
||||
$items = array();
|
||||
$i = 0;
|
||||
foreach ($files as $file) {
|
||||
$fileExt = CKFile::getExt($file);
|
||||
if (!in_array(strToLower($fileExt),$authorisedExt)) continue;
|
||||
|
||||
$item = self::initItem();
|
||||
|
||||
// get the data for the image
|
||||
$filedata = self::getImageDataFromfolder($file, $directory);
|
||||
|
||||
$file = str_replace("\\", "/", PagebuilderckHelper::utf8_encode($file));
|
||||
|
||||
$item->image = JUri::base(true) . '/' . $file;
|
||||
$item->title = $filedata->title;
|
||||
$item->text = $filedata->text;
|
||||
$item->video = $filedata->video;
|
||||
$items[$i] = $item;
|
||||
if (isset($filedata->link) && $filedata->link) {
|
||||
$item->link = $filedata->link;
|
||||
} else {
|
||||
$videoFile = str_replace($fileExt, 'mp4', $file);
|
||||
$hasVideo = file_exists($videoFile);
|
||||
$item->link = $hasVideo ? $videoFile : $item->image;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax method called from the module to list the images
|
||||
*/
|
||||
public static function loadLabelsFile() {
|
||||
$input = \Pagebuilderck\CKFof::getInput();
|
||||
$path = $input->get('path', '', 'string');
|
||||
|
||||
// outputs the heading
|
||||
echo '<div id="labelseditor">';
|
||||
echo '<div class="ckheader">'
|
||||
. '<div class="col ckmove">' . JText::_('CK_ORDERING') . '</div>'
|
||||
. '<div class="col ckimage">' . JText::_('CK_IMAGE') . '</div>'
|
||||
. '<div class="col">' . JText::_('CK_TEXT') . '</div>'
|
||||
. '<div class="col">' . JText::_('CK_LINK') . '</div>'
|
||||
. '</div>';
|
||||
|
||||
$params = new JRegistry();
|
||||
$params->set('autoloadfoldername', $path);
|
||||
$items = self::getItems($params);
|
||||
$images = Array();
|
||||
foreach ($items as $item) {
|
||||
$filename = explode('/', $item->image);
|
||||
$filename = end($filename);
|
||||
$images[] = $filename;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$labels = Array();
|
||||
if (file_exists(JPATH_SITE . '/' . $path . '/labels.txt')) {
|
||||
$labels = file_get_contents(JPATH_SITE . '/' . $path . '/labels.txt');
|
||||
$lines = explode("\n", $labels);
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (!$line) continue;
|
||||
$t = explode('|', $line);
|
||||
$image = isset($t[0]) ? $t[0] : '';
|
||||
if (! $image) continue;
|
||||
$title = isset($t[1]) ? htmlspecialchars($t[1]) : '';
|
||||
$desc = isset($t[2]) ? htmlspecialchars($t[2]) : '';
|
||||
$link = isset($t[3]) ? htmlspecialchars($t[3]) : '';
|
||||
if (in_array($image, $images)) {
|
||||
$key = array_search($image, $images);
|
||||
unset($images[$key]);
|
||||
self::renderLabelEdition($path, $image, $i, $title, $desc, $link);
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($images as $image) {
|
||||
self::renderLabelEdition($path, $image, $i, $title = '', $desc = '', $link = '');
|
||||
$i++;
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Output the html code for the label edition
|
||||
*/
|
||||
private static function renderLabelEdition($path, $image, $i, $title, $desc, $link) {
|
||||
echo '<div class="ckrow">'
|
||||
. '<div class="col ckmove"> </div>'
|
||||
. '<div class="col ckfile cktip" data-image="' . PagebuilderckHelper::utf8_encode($image) . '" title="' . PagebuilderckHelper::utf8_encode($image) . '" style="background-image: url(\'' . JUri::root(true) . '/' . $path . '/' . $image . '\');" ></div>'
|
||||
. '<div class="col">'
|
||||
.'<div><label style="display: inline-block;padding: 5px;min-width: 100px">' . JText::_('CK_TITLE') . '</label><input class="labeltitle" type="text" value="' . $title . '" /></div>'
|
||||
. '<div><label style="display: inline-block;padding: 5px;min-width: 100px">' . JText::_('CK_DESCRIPTION') . '</label><input class="labeldesc" type="text" value="' . $desc . '" /></div>'
|
||||
. '</div>'
|
||||
. '<div class="col input-append"><input id="labellink'.$i.'" class="labellink" type="text" value="' . $link . '" /><button class="btn" onclick="CKBox.open({url: \''.JUri::root(true).'/administrator/index.php?option=com_pagebuilderck&view=menus&tmpl=component&fieldid=labellink'.$i.'\', id:\'ckmenusmodal\', style: {padding: \'10px\'} })">' . JText::_('CK_SELECT') . '</button></div>'
|
||||
. '</div>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the labels.txt file in the folder
|
||||
*/
|
||||
public static function writeLabelsFile() {
|
||||
$input = \Pagebuilderck\CKFof::getInput();
|
||||
$path = $input->get('path', '', 'string');
|
||||
$labels = $input->get('labels', '', 'html');
|
||||
// $labels = utf8_decode($input->get('labels', '', 'html'));
|
||||
$labelsFile = JPATH_SITE . '/' . $path . '/labels.txt';
|
||||
|
||||
echo (bool)file_put_contents($labelsFile, $labels);
|
||||
exit();
|
||||
}
|
||||
|
||||
public static function importFromFolder() {
|
||||
$input = \Pagebuilderck\CKFof::getInput();
|
||||
$folder = $input->get('folder', '', 'string');
|
||||
$imgdir = JPATH_ROOT . '/' . trim(trim($folder, "/"), "\\");
|
||||
$imgs = CKFolder::files($imgdir, '\.(?:png|jpe?g|bmp|tiff|webp?)$', false, true);
|
||||
$imgs = str_replace(JPATH_ROOT, "", $imgs);
|
||||
$imgs = str_replace("\\", "/", $imgs);
|
||||
foreach ($imgs as &$img) {
|
||||
$img = trim($img, "/");
|
||||
}
|
||||
$imgs = json_encode($imgs);
|
||||
|
||||
echo $imgs;
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make empty slide object
|
||||
*/
|
||||
private static function initItem() {
|
||||
$item = new stdClass();
|
||||
$item->image = null;
|
||||
$item->link = null;
|
||||
$item->title = null;
|
||||
$item->text = null;
|
||||
$item->more = array();
|
||||
$item->alignment = null;
|
||||
$item->time = null;
|
||||
$item->target = 'default';
|
||||
$item->video = null;
|
||||
$item->texttype = null;
|
||||
$item->articleid = null;
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
2163
administrator/components/com_pagebuilderck/helpers/menustyles.php
Normal file
2163
administrator/components/com_pagebuilderck/helpers/menustyles.php
Normal file
File diff suppressed because it is too large
Load Diff
1030
administrator/components/com_pagebuilderck/helpers/pagebuilderck.php
Normal file
1030
administrator/components/com_pagebuilderck/helpers/pagebuilderck.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @package com_pagebuilderck
|
||||
* @copyright Copyright (C) 2015. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// load the helper to help us to use the parameters
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/pagebuilderckparams.php';
|
||||
|
||||
/**
|
||||
* Helper Class.
|
||||
*/
|
||||
class PagebuilderckFrontHelper {
|
||||
|
||||
protected static $cssDeclaration;
|
||||
|
||||
protected static $cssSheet = array();
|
||||
|
||||
protected static $compile = null;
|
||||
|
||||
/**
|
||||
* Gets a list of the actions that can be performed.
|
||||
*
|
||||
* @return JObject
|
||||
* @since 1.6
|
||||
*/
|
||||
public static function createParamsFromElement($obj) {
|
||||
if (is_array($obj) && isset($obj[0]->attr)) {
|
||||
$result = new PagebuilderckParams($obj[0]->attr);
|
||||
} else {
|
||||
$result = new PagebuilderckParams();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the needed url for the source
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSource($src) {
|
||||
$isLocal = substr($src, 0, 4) == 'http' ? false : true;
|
||||
if ($isLocal) $src = JUri::root(true) . '/' . $src;
|
||||
return $src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if there is already a unit, else add the px
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function testUnit($value, $defaultunit = "px") {
|
||||
|
||||
if (
|
||||
(stristr($value, 'px'))
|
||||
OR (stristr($value, 'em'))
|
||||
OR (stristr($value, 'rem'))
|
||||
OR (stristr($value, '%'))
|
||||
OR (stristr($value, 'vh'))
|
||||
OR (stristr($value, 'vw'))
|
||||
OR (stristr($value, 'vmin'))
|
||||
OR (stristr($value, 'vmax'))
|
||||
OR (stristr($value, 'mm'))
|
||||
OR (stristr($value, 'in'))
|
||||
OR (stristr($value, 'pt'))
|
||||
OR (stristr($value, 'pc'))
|
||||
OR $value == 'auto'
|
||||
)
|
||||
return $value;
|
||||
|
||||
return $value . $defaultunit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have to compile according to component options
|
||||
*/
|
||||
private static function doCompile() {
|
||||
// if admin, then exit immediately
|
||||
if (\Pagebuilderck\CKFof::isAdmin()) return false;
|
||||
// if in edition mode, then exit immediately
|
||||
$input = JFactory::getApplication()->input;
|
||||
if ($input->get('layout', '', 'cmd') === 'edit') return false;
|
||||
// check the option from the component
|
||||
if (self::$compile == null) {
|
||||
$params = JComponentHelper::getParams('com_pagebuilderck');
|
||||
self::$compile = $params->get('compile', '0');
|
||||
}
|
||||
return self::$compile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the needed JS and CSS files to render in frontend
|
||||
*/
|
||||
public static function loadFrontendAssets() {
|
||||
$params = JComponentHelper::getParams('com_pagebuilderck');
|
||||
JHtml::_('jquery.framework');
|
||||
$doc = JFactory::getDocument();
|
||||
// $doc->addScript(JUri::root(true) . '/media/jui/js/jquery.min.js');
|
||||
PagebuilderckFrontHelper::addStyleSheet(JUri::root(true) . '/components/com_pagebuilderck/assets/pagebuilderck.css?ver=' . PAGEBUILDERCK_VERSION);
|
||||
if ($params->get('loadfontawesome','1')) $doc->addStyleSheet(JUri::root(true) . '/components/com_pagebuilderck/assets/font-awesome.min.css');
|
||||
// if ($params->get('loadfontawesome','2')) $doc->addStyleSheet(JUri::root(true) . '/components/com_pagebuilderck/assets/font-awesome-4-to-5.css');
|
||||
$doc->addScriptDeclaration('var PAGEBUILDERCK_DISABLE_ANIMATIONS = "' . (int)$params->get('disableanimations','') . '";');
|
||||
$doc->addScript(JUri::root(true) . '/components/com_pagebuilderck/assets/jquery-uick.min.js?ver=' . PAGEBUILDERCK_VERSION);
|
||||
$doc->addScript(JUri::root(true) . '/components/com_pagebuilderck/assets/pagebuilderck.js?ver=' . PAGEBUILDERCK_VERSION);
|
||||
$doc->addScript(JUri::root(true) . '/components/com_pagebuilderck/assets/parallaxbackground.js?ver=' . PAGEBUILDERCK_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the css inclusion in the page according to the component options
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public static function addStyleDeclaration($css) {
|
||||
$input = JFactory::getApplication()->input;
|
||||
// $compile = true; //TODO : tester si admin, ne pas compiler
|
||||
if (self::doCompile()) {
|
||||
self::$cssDeclaration .= $css;
|
||||
} else {
|
||||
$doc = JFactory::getDocument();
|
||||
$doc->addStyleDeclaration($css);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the css inclusion in the page according to the component options
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public static function addStylesheet($file) {
|
||||
// $input = JFactory::getApplication()->input;
|
||||
// $compile = true; //TODO : tester si admin, ne pas compiler
|
||||
if (self::doCompile()) {
|
||||
if (! in_array($file, self::$cssSheet)) self::$cssSheet[] = $file;
|
||||
} else {
|
||||
$doc = JFactory::getDocument();
|
||||
$doc->addStylesheet($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the global css styles stored
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public static function loadAllCss() {
|
||||
if (! self::doCompile()) return;
|
||||
$input = JFactory::getApplication()->input;
|
||||
$uri = JUri::getInstance();
|
||||
$query = $uri->getQuery();
|
||||
$query = str_replace(JUri::root(true), '', $query);
|
||||
|
||||
$clearPath = preg_replace("/[^a-zA-Z0-9]+/", "", $query);
|
||||
|
||||
$cssContent = '';
|
||||
// get the style sheets
|
||||
foreach(self::$cssSheet as $sheet) {
|
||||
if (stristr($sheet, 'googleapis.com')) continue;
|
||||
$path = str_replace(JUri::root(true), '', $sheet);
|
||||
// remove params in url
|
||||
if ($hashpos = strpos($path, '?')) {
|
||||
$path = substr($path, 0, $hashpos);
|
||||
}
|
||||
|
||||
$tmp = file_get_contents(JPATH_ROOT . $path);
|
||||
|
||||
// get the url for the images path in the css files
|
||||
$url = str_replace(JPATH_ROOT, JUri::root(), $path);
|
||||
$url = explode('/', $url);
|
||||
$num=count($url);
|
||||
$num=$num-1;
|
||||
unset($url[$num]); // remove the css filename from the path
|
||||
$url = implode('/', $url);
|
||||
|
||||
// replace the path to the images
|
||||
$tmp = str_replace("url('", "url('" . $url . "/", $tmp);
|
||||
$cssContent .= $tmp;
|
||||
}
|
||||
|
||||
// get the inline styles
|
||||
$cssContent .= self::$cssDeclaration;
|
||||
|
||||
if (trim($cssContent)) {
|
||||
$file = '/compiled/pagebuilderck_' . $clearPath . '_compiled.css';
|
||||
file_put_contents(PAGEBUILDERCK_MEDIA_PATH . $file, $cssContent);
|
||||
$doc = JFactory::getDocument();
|
||||
$doc->addStyleSheet(PAGEBUILDERCK_MEDIA_URI . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* @name Page Builder CK
|
||||
* @package com_pagebuilderck
|
||||
* @copyright Copyright (C) 2015. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// magic method since PHP 8.2 to allow creation of dynamic properties
|
||||
#[AllowDynamicProperties]
|
||||
|
||||
Class PagebuilderckParams {
|
||||
|
||||
protected $_attrs = array();
|
||||
|
||||
/**
|
||||
* Class constructor, overridden in descendant classes.
|
||||
*
|
||||
* @param mixed $properties Either and associative array or another
|
||||
* object to set the initial properties of the object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($properties = null)
|
||||
{
|
||||
if ($properties !== null)
|
||||
{
|
||||
$this->setProperties($properties);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a property of the object or the default value if the property is not set.
|
||||
*
|
||||
* @param string $property The name of the property.
|
||||
* @param mixed $default The default value.
|
||||
*
|
||||
* @return mixed The value of the property.
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @see JObject::getProperties()
|
||||
*/
|
||||
public function get($property, $default = null)
|
||||
{
|
||||
if (isset($this->$property))
|
||||
{
|
||||
return $this->$property;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies a property of the object, creating it if it does not already exist.
|
||||
*
|
||||
* @param string $property The name of the property.
|
||||
* @param mixed $value The value of the property to set.
|
||||
*
|
||||
* @return mixed Previous value of the property.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function set($property, $value = null)
|
||||
{
|
||||
$previous = isset($this->$property) ? $this->$property : null;
|
||||
$this->$property = $value;
|
||||
|
||||
return $previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object properties based on a named array/hash.
|
||||
*
|
||||
* @param mixed $properties Either an associative array or another object.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @see JObject::set()
|
||||
*/
|
||||
public function setProperties($properties)
|
||||
{
|
||||
if (is_array($properties) || is_object($properties))
|
||||
{
|
||||
foreach ((array) $properties as $k => $v)
|
||||
{
|
||||
// Use the set function which might be overridden.
|
||||
$this->set($k, $v);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
2253
administrator/components/com_pagebuilderck/helpers/stylescss.php
Normal file
2253
administrator/components/com_pagebuilderck/helpers/stylescss.php
Normal file
File diff suppressed because it is too large
Load Diff
658
administrator/components/com_pagebuilderck/helpers/zip.php
Normal file
658
administrator/components/com_pagebuilderck/helpers/zip.php
Normal file
@@ -0,0 +1,658 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage FileSystem
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* ZIP format adapter for the JArchive class
|
||||
*
|
||||
* The ZIP compression code is partially based on code from:
|
||||
* Eric Mueller <eric@themepark.com>
|
||||
* https://www.zend.com/codex.php?id=535&single=1
|
||||
*
|
||||
* Deins125 <webmaster@atlant.ru>
|
||||
* https://www.zend.com/codex.php?id=470&single=1
|
||||
*
|
||||
* The ZIP compression date code is partially based on code from
|
||||
* Peter Listiak <mlady@users.sourceforge.net>
|
||||
*
|
||||
* This class is inspired from and draws heavily in code and concept from the Compress package of
|
||||
* The Horde Project <https://www.horde.org>
|
||||
*
|
||||
* @contributor Chuck Hagenbuch <chuck@horde.org>
|
||||
* @contributor Michael Slusarz <slusarz@horde.org>
|
||||
* @contributor Michael Cochrane <mike@graftonhall.co.nz>
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage FileSystem
|
||||
* @since 11.1
|
||||
*/
|
||||
class CKArchiveZip extends stdClass
|
||||
{
|
||||
/**
|
||||
* ZIP compression methods.
|
||||
*
|
||||
* @var array
|
||||
* @since 11.1
|
||||
*/
|
||||
private $_methods = array(0x0 => 'None', 0x1 => 'Shrunk', 0x2 => 'Super Fast', 0x3 => 'Fast', 0x4 => 'Normal', 0x5 => 'Maximum', 0x6 => 'Imploded',
|
||||
0x8 => 'Deflated');
|
||||
|
||||
/**
|
||||
* Beginning of central directory record.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
private $_ctrlDirHeader = "\x50\x4b\x01\x02";
|
||||
|
||||
/**
|
||||
* End of central directory record.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
private $_ctrlDirEnd = "\x50\x4b\x05\x06\x00\x00\x00\x00";
|
||||
|
||||
/**
|
||||
* Beginning of file contents.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
private $_fileHeader = "\x50\x4b\x03\x04";
|
||||
|
||||
/**
|
||||
* ZIP file data buffer
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
private $_data = null;
|
||||
|
||||
/**
|
||||
* ZIP file metadata array
|
||||
*
|
||||
* @var array
|
||||
* @since 11.1
|
||||
*/
|
||||
private $_metadata = null;
|
||||
|
||||
/**
|
||||
* Create a ZIP compressed file from an array of file data.
|
||||
*
|
||||
* @param string $archive Path to save archive.
|
||||
* @param array $files Array of files to add to archive.
|
||||
* @param array $options Compression options (unused).
|
||||
*
|
||||
* @return boolean True if successful.
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @todo Finish Implementation
|
||||
*/
|
||||
public function create($archive, $files, $options = array())
|
||||
{
|
||||
// Initialise variables.
|
||||
$contents = array();
|
||||
$ctrldir = array();
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$this->_addToZIPFile($file, $contents, $ctrldir);
|
||||
}
|
||||
|
||||
return $this->_createZIPFile($contents, $ctrldir, $archive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a ZIP compressed file to a given path
|
||||
*
|
||||
* @param string $archive Path to ZIP archive to extract
|
||||
* @param string $destination Path to extract archive into
|
||||
* @param array $options Extraction options [unused]
|
||||
*
|
||||
* @return boolean True if successful
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function extract($archive, $destination, $options = array())
|
||||
{
|
||||
if (!is_file($archive))
|
||||
{
|
||||
$this->set('error.message', 'Archive does not exist');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->hasNativeSupport())
|
||||
{
|
||||
return ($this->_extractNative($archive, $destination, $options)) ? true : JError::raiseWarning(100, $this->get('error.message'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ($this->_extract($archive, $destination, $options)) ? true : JError::raiseWarning(100, $this->get('error.message'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this adapter can unpack files on this computer.
|
||||
*
|
||||
* @return boolean True if supported
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return (self::hasNativeSupport() || extension_loaded('zlib'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to determine if the server has native zip support for faster handling
|
||||
*
|
||||
* @return boolean True if php has native ZIP support
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function hasNativeSupport()
|
||||
{
|
||||
return (function_exists('ZipArchive::open') && function_exists('ZipArchive::read'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the data is a valid ZIP file.
|
||||
*
|
||||
* @param string &$data ZIP archive data buffer.
|
||||
*
|
||||
* @return boolean True if valid, false if invalid.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function checkZipData(&$data)
|
||||
{
|
||||
if (strpos($data, $this->_fileHeader) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a ZIP compressed file to a given path using a php based algorithm that only requires zlib support
|
||||
*
|
||||
* @param string $archive Path to ZIP archive to extract.
|
||||
* @param string $destination Path to extract archive into.
|
||||
* @param array $options Extraction options [unused].
|
||||
*
|
||||
* @return boolean True if successful
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
private function _extract($archive, $destination, $options)
|
||||
{
|
||||
// Initialise variables.
|
||||
$this->_data = null;
|
||||
$this->_metadata = null;
|
||||
|
||||
if (!extension_loaded('zlib'))
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_NOT_SUPPORTED'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->_data = file_get_contents($archive))
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_READ'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->_readZipInfo($this->_data))
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_INFO_FAILED'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = 0, $n = count($this->_metadata); $i < $n; $i++)
|
||||
{
|
||||
$lastPathCharacter = substr($this->_metadata[$i]['name'], -1, 1);
|
||||
|
||||
if ($lastPathCharacter !== '/' && $lastPathCharacter !== '\\')
|
||||
{
|
||||
$buffer = $this->_getFileData($i);
|
||||
$path = JPath::clean($destination . '/' . $this->_metadata[$i]['name']);
|
||||
|
||||
// Make sure the destination folder exists
|
||||
if (!JFolder::create(dirname($path)))
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_CREATE_DESTINATION'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Pagebuilderck\CKFile::write($path, $buffer) === false)
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_WRITE_ENTRY'));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a ZIP compressed file to a given path using native php api calls for speed
|
||||
*
|
||||
* @param string $archive Path to ZIP archive to extract
|
||||
* @param string $destination Path to extract archive into
|
||||
* @param array $options Extraction options [unused]
|
||||
*
|
||||
* @return boolean True if successful
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
private function _extractNative($archive, $destination, $options)
|
||||
{
|
||||
$zip = ZipArchive::open($archive);
|
||||
if (is_resource($zip))
|
||||
{
|
||||
// Make sure the destination folder exists
|
||||
if (!Pagebuilderck\CKFolder::create($destination))
|
||||
{
|
||||
$this->set('error.message', 'Unable to create destination');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read files in the archive
|
||||
while ($file = @ZipArchive::read($zip))
|
||||
{
|
||||
if (ZipArchive::entry_open($zip, $file, "r"))
|
||||
{
|
||||
if (substr(ZipArchive::entry_name($file), strlen(ZipArchive::entry_name($file)) - 1) != "/")
|
||||
{
|
||||
$buffer = ZipArchive::entry_read($file, ZipArchive::entry_filesize($file));
|
||||
|
||||
if (Pagebuilderck\CKFile::write($destination . '/' . ZipArchive::entry_name($file), $buffer) === false)
|
||||
{
|
||||
$this->set('error.message', 'Unable to write entry');
|
||||
return false;
|
||||
}
|
||||
|
||||
ZipArchive::entry_close($file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_READ_ENTRY'));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ZipArchive::close($zip);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_OPEN_ARCHIVE'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of files/data from a ZIP archive buffer.
|
||||
*
|
||||
* <pre>
|
||||
* KEY: Position in zipfile
|
||||
* VALUES: 'attr' -- File attributes
|
||||
* 'crc' -- CRC checksum
|
||||
* 'csize' -- Compressed file size
|
||||
* 'date' -- File modification time
|
||||
* 'name' -- Filename
|
||||
* 'method'-- Compression method
|
||||
* 'size' -- Original file size
|
||||
* 'type' -- File type
|
||||
* </pre>
|
||||
*
|
||||
* @param string &$data The ZIP archive buffer.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
private function _readZipInfo(&$data)
|
||||
{
|
||||
// Initialise variables.
|
||||
$entries = array();
|
||||
|
||||
// Find the last central directory header entry
|
||||
$fhLast = strpos($data, $this->_ctrlDirEnd);
|
||||
|
||||
do
|
||||
{
|
||||
$last = $fhLast;
|
||||
}
|
||||
while (($fhLast = strpos($data, $this->_ctrlDirEnd, $fhLast + 1)) !== false);
|
||||
|
||||
// Find the central directory offset
|
||||
$offset = 0;
|
||||
|
||||
if ($last)
|
||||
{
|
||||
$endOfCentralDirectory = unpack(
|
||||
'vNumberOfDisk/vNoOfDiskWithStartOfCentralDirectory/vNoOfCentralDirectoryEntriesOnDisk/' .
|
||||
'vTotalCentralDirectoryEntries/VSizeOfCentralDirectory/VCentralDirectoryOffset/vCommentLength',
|
||||
substr($data, $last + 4)
|
||||
);
|
||||
$offset = $endOfCentralDirectory['CentralDirectoryOffset'];
|
||||
}
|
||||
|
||||
// Get details from central directory structure.
|
||||
$fhStart = strpos($data, $this->_ctrlDirHeader, $offset);
|
||||
$dataLength = strlen($data);
|
||||
|
||||
do
|
||||
{
|
||||
if ($dataLength < $fhStart + 31)
|
||||
{
|
||||
$this->set('error.message', TCK_Text::_('JLIB_FILESYSTEM_ZIP_INVALID_ZIP_DATA'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength', substr($data, $fhStart + 10, 20));
|
||||
$name = substr($data, $fhStart + 46, $info['Length']);
|
||||
|
||||
$entries[$name] = array(
|
||||
'attr' => null,
|
||||
'crc' => sprintf("%08s", dechex($info['CRC32'])),
|
||||
'csize' => $info['Compressed'],
|
||||
'date' => null,
|
||||
'_dataStart' => null,
|
||||
'name' => $name,
|
||||
'method' => $this->_methods[$info['Method']],
|
||||
'_method' => $info['Method'],
|
||||
'size' => $info['Uncompressed'],
|
||||
'type' => null
|
||||
);
|
||||
|
||||
$entries[$name]['date'] = mktime(
|
||||
(($info['Time'] >> 11) & 0x1f),
|
||||
(($info['Time'] >> 5) & 0x3f),
|
||||
(($info['Time'] << 1) & 0x3e),
|
||||
(($info['Time'] >> 21) & 0x07),
|
||||
(($info['Time'] >> 16) & 0x1f),
|
||||
((($info['Time'] >> 25) & 0x7f) + 1980)
|
||||
);
|
||||
|
||||
if ($dataLength < $fhStart + 43)
|
||||
{
|
||||
$this->set('error.message', 'Invalid ZIP data');
|
||||
return false;
|
||||
}
|
||||
|
||||
$info = unpack('vInternal/VExternal/VOffset', substr($data, $fhStart + 36, 10));
|
||||
|
||||
$entries[$name]['type'] = ($info['Internal'] & 0x01) ? 'text' : 'binary';
|
||||
$entries[$name]['attr'] = (($info['External'] & 0x10) ? 'D' : '-') . (($info['External'] & 0x20) ? 'A' : '-')
|
||||
. (($info['External'] & 0x03) ? 'S' : '-') . (($info['External'] & 0x02) ? 'H' : '-') . (($info['External'] & 0x01) ? 'R' : '-');
|
||||
$entries[$name]['offset'] = $info['Offset'];
|
||||
|
||||
// Get details from local file header since we have the offset
|
||||
$lfhStart = strpos($data, $this->_fileHeader, $entries[$name]['offset']);
|
||||
|
||||
if ($dataLength < $lfhStart + 34)
|
||||
{
|
||||
$this->set('error.message', 'Invalid ZIP data');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength/vExtraLength', substr($data, $lfhStart + 8, 25));
|
||||
$name = substr($data, $lfhStart + 30, $info['Length']);
|
||||
$entries[$name]['_dataStart'] = $lfhStart + 30 + $info['Length'] + $info['ExtraLength'];
|
||||
|
||||
// Bump the max execution time because not using the built in php zip libs makes this process slow.
|
||||
@set_time_limit(ini_get('max_execution_time'));
|
||||
}
|
||||
while ((($fhStart = strpos($data, $this->_ctrlDirHeader, $fhStart + 46)) !== false));
|
||||
|
||||
$this->_metadata = array_values($entries);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file data for a file by offsest in the ZIP archive
|
||||
*
|
||||
* @param integer $key The position of the file in the archive.
|
||||
*
|
||||
* @return string Uncompressed file data buffer.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
private function _getFileData($key)
|
||||
{
|
||||
if ($this->_metadata[$key]['_method'] == 0x8)
|
||||
{
|
||||
return gzinflate(substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize']));
|
||||
}
|
||||
elseif ($this->_metadata[$key]['_method'] == 0x0)
|
||||
{
|
||||
/* Files that aren't compressed. */
|
||||
return substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize']);
|
||||
}
|
||||
elseif ($this->_metadata[$key]['_method'] == 0x12)
|
||||
{
|
||||
// Is bz2 extension loaded? If not try to load it
|
||||
if (!extension_loaded('bz2'))
|
||||
{
|
||||
if (JPATH_ISWIN)
|
||||
{
|
||||
@dl('php_bz2.dll');
|
||||
}
|
||||
else
|
||||
{
|
||||
@dl('bz2.so');
|
||||
}
|
||||
}
|
||||
|
||||
// If bz2 extension is successfully loaded use it
|
||||
if (extension_loaded('bz2'))
|
||||
{
|
||||
return bzdecompress(substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize']));
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a UNIX timestamp to a 4-byte DOS date and time format
|
||||
* (date in high 2-bytes, time in low 2-bytes allowing magnitude
|
||||
* comparison).
|
||||
*
|
||||
* @param integer $unixtime The current UNIX timestamp.
|
||||
*
|
||||
* @return integer The current date in a 4-byte DOS format.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
private function _unix2DOSTime($unixtime = null)
|
||||
{
|
||||
$timearray = (is_null($unixtime)) ? getdate() : getdate($unixtime);
|
||||
|
||||
if ($timearray['year'] < 1980)
|
||||
{
|
||||
$timearray['year'] = 1980;
|
||||
$timearray['mon'] = 1;
|
||||
$timearray['mday'] = 1;
|
||||
$timearray['hours'] = 0;
|
||||
$timearray['minutes'] = 0;
|
||||
$timearray['seconds'] = 0;
|
||||
}
|
||||
|
||||
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) |
|
||||
($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a "file" to the ZIP archive.
|
||||
*
|
||||
* @param array &$file File data array to add
|
||||
* @param array &$contents An array of existing zipped files.
|
||||
* @param array &$ctrldir An array of central directory information.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @todo Review and finish implementation
|
||||
*/
|
||||
private function _addToZIPFile(&$file, &$contents, &$ctrldir)
|
||||
{
|
||||
$data = &$file['data'];
|
||||
$name = str_replace('\\', '/', $file['name']);
|
||||
|
||||
/* See if time/date information has been provided. */
|
||||
$ftime = null;
|
||||
if (isset($file['time']))
|
||||
{
|
||||
$ftime = $file['time'];
|
||||
}
|
||||
|
||||
// Get the hex time.
|
||||
$dtime = dechex($this->_unix2DosTime($ftime));
|
||||
$hexdtime = chr(hexdec($dtime[6] . $dtime[7])) . chr(hexdec($dtime[4] . $dtime[5])) . chr(hexdec($dtime[2] . $dtime[3]))
|
||||
. chr(hexdec($dtime[0] . $dtime[1]));
|
||||
|
||||
/* Begin creating the ZIP data. */
|
||||
$fr = $this->_fileHeader;
|
||||
/* Version needed to extract. */
|
||||
$fr .= "\x14\x00";
|
||||
/* General purpose bit flag. */
|
||||
$fr .= "\x00\x00";
|
||||
/* Compression method. */
|
||||
$fr .= "\x08\x00";
|
||||
/* Last modification time/date. */
|
||||
$fr .= $hexdtime;
|
||||
|
||||
/* "Local file header" segment. */
|
||||
$unc_len = strlen($data);
|
||||
$crc = crc32($data);
|
||||
$zdata = gzcompress($data);
|
||||
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
|
||||
$c_len = strlen($zdata);
|
||||
|
||||
/* CRC 32 information. */
|
||||
$fr .= pack('V', $crc);
|
||||
/* Compressed filesize. */
|
||||
$fr .= pack('V', $c_len);
|
||||
/* Uncompressed filesize. */
|
||||
$fr .= pack('V', $unc_len);
|
||||
/* Length of filename. */
|
||||
$fr .= pack('v', strlen($name));
|
||||
/* Extra field length. */
|
||||
$fr .= pack('v', 0);
|
||||
/* File name. */
|
||||
$fr .= $name;
|
||||
|
||||
/* "File data" segment. */
|
||||
$fr .= $zdata;
|
||||
|
||||
/* Add this entry to array. */
|
||||
$old_offset = strlen(implode('', $contents));
|
||||
$contents[] = &$fr;
|
||||
|
||||
/* Add to central directory record. */
|
||||
$cdrec = $this->_ctrlDirHeader;
|
||||
/* Version made by. */
|
||||
$cdrec .= "\x00\x00";
|
||||
/* Version needed to extract */
|
||||
$cdrec .= "\x14\x00";
|
||||
/* General purpose bit flag */
|
||||
$cdrec .= "\x00\x00";
|
||||
/* Compression method */
|
||||
$cdrec .= "\x08\x00";
|
||||
/* Last mod time/date. */
|
||||
$cdrec .= $hexdtime;
|
||||
/* CRC 32 information. */
|
||||
$cdrec .= pack('V', $crc);
|
||||
/* Compressed filesize. */
|
||||
$cdrec .= pack('V', $c_len);
|
||||
/* Uncompressed filesize. */
|
||||
$cdrec .= pack('V', $unc_len);
|
||||
/* Length of filename. */
|
||||
$cdrec .= pack('v', strlen($name));
|
||||
/* Extra field length. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* File comment length. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* Disk number start. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* Internal file attributes. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* External file attributes -'archive' bit set. */
|
||||
$cdrec .= pack('V', 32);
|
||||
/* Relative offset of local header. */
|
||||
$cdrec .= pack('V', $old_offset);
|
||||
/* File name. */
|
||||
$cdrec .= $name;
|
||||
/* Optional extra field, file comment goes here. */
|
||||
|
||||
/* Save to central directory array. */
|
||||
$ctrldir[] = &$cdrec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ZIP file.
|
||||
*
|
||||
* Official ZIP file format: https://www.pkware.com/appnote.txt
|
||||
*
|
||||
* @param array &$contents An array of existing zipped files.
|
||||
* @param array &$ctrlDir An array of central directory information.
|
||||
* @param string $path The path to store the archive.
|
||||
*
|
||||
* @return boolean True if successful
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @todo Review and finish implementation
|
||||
*/
|
||||
private function _createZIPFile(&$contents, &$ctrlDir, $path)
|
||||
{
|
||||
$data = implode('', $contents);
|
||||
$dir = implode('', $ctrlDir);
|
||||
|
||||
$buffer = $data . $dir . $this->_ctrlDirEnd . /* Total # of entries "on this disk". */
|
||||
pack('v', count($ctrlDir)) . /* Total # of entries overall. */
|
||||
pack('v', count($ctrlDir)) . /* Size of central directory. */
|
||||
pack('V', strlen($dir)) . /* Offset to start of central dir. */
|
||||
pack('V', strlen($data)) . /* ZIP file comment length. */
|
||||
"\x00\x00";
|
||||
|
||||
if (Pagebuilderck\CKFile::write($path, $buffer) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user