first commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user