Your IP : 216.73.216.11


Current Path : /home/digilove/public_html/41423/
Upload File :
Current File : //home/digilove/public_html/41423/Generator.tar

AbstractGenerator.php000064400000007772152356646610010722 0ustar00<?php

namespace Nextend\SmartSlider3\Generator;

use Nextend\Framework\Data\Data;
use Nextend\Framework\Form\Container\ContainerTable;
use Nextend\Framework\Form\ContainerInterface;
use Nextend\Framework\Form\Element\Message\Warning;
use Nextend\SmartSlider3\Platform\WordPress\Shortcode\Shortcode;

abstract class AbstractGenerator {

    protected $name = '';

    protected $label = '';

    protected $layout = '';

    /** @var  AbstractGeneratorGroup */
    protected $group;

    /** @var Data */
    protected $data;

    /**
     *
     * @param AbstractGeneratorGroup $group
     * @param string                 $name
     * @param string                 $label
     */
    public function __construct($group, $name, $label) {
        $this->group = $group;
        $this->name  = $name;
        $this->label = $label;

        $this->group->addSource($name, $this);
    }

    /**
     *
     * @param ContainerInterface $container
     */
    public function renderFields($container) {

        if ($this->group->isDeprecated()) {
            $table = new ContainerTable($container, 'deprecation', n2_('Deprecation'));

            $row = $table->createRow('deprecation-row');
            new Warning($row, 'deprecation-warning', n2_('This generator will get deprecated soon, so you shouldn\'t use it anymore!'));
        }
    }

    public function setData($data) {
        $this->data = $data;
    }

    public final function getData($slides, $startIndex, $group) {

        $this->resetState();

        $data       = array();
        $linearData = $this->_getData($slides * $group, $startIndex - 1);
        if ($linearData != null) {
            $keys = array();
            for ($i = 0; $i < count($linearData); $i++) {
                $keys = array_merge($keys, array_keys($linearData[$i]));
            }

            $columns = array_fill_keys($keys, '');

            for ($i = 0; $i < count($linearData); $i++) {
                $firstIndex = intval($i / $group);
                if (!isset($data[$firstIndex])) {
                    $data[$firstIndex] = array();
                }
                $data[$firstIndex][$i % $group] = array_merge($columns, $linearData[$i]);
            }

            if (count($data) && count($data[count($data) - 1]) != $group) {
                if (count($data) - 1 == 0 && count($data[count($data) - 1]) > 0) {
                    while (count($data[0]) < $group) {
                        $data[0][] = $columns;
                    }
                } else {
                    array_pop($data);
                }
            }
        }

        return $data;
    }

    protected function resetState() {

    }

    protected abstract function _getData($count, $startIndex);

    function makeClickableLinks($s) {
        return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
    }

    protected function getIDs($field = 'ids') {
        return array_map('intval', explode("\n", str_replace(array(
            "\r\n",
            "\n\r",
            "\r"
        ), "\n", $this->data->get($field))));
    }

    public function filterName($name) {
        return $name;
    }

    public function hash($key) {
        return md5($key);
    }

    public static function cacheKey($params) {
        return '';
    }

    /**
     * @return string
     */
    public function getLabel() {
        return $this->label;
    }

    /**
     * @return string
     */
    public function getDescription() {
        return n2_('No description.');
    }

    /**
     * @return string
     */
    public function getLayout() {
        return $this->layout;
    }

    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /**
     * @return AbstractGeneratorGroup
     */
    public function getGroup() {
        return $this->group;
    }

}AbstractGeneratorGroup.php000064400000005363152356646610011731 0ustar00<?php

namespace Nextend\SmartSlider3\Generator;

use Nextend\Framework\Pattern\GetAssetsPathTrait;
use Nextend\Framework\Url\Url;

abstract class AbstractGeneratorGroup {

    use GetAssetsPathTrait;

    protected $name = '';

    /** @var AbstractGeneratorGroupConfiguration */
    protected $configuration;

    protected $needConfiguration = false;

    protected $url = '';

    /** @var AbstractGenerator[] */
    protected $sources = array();

    protected $isLoaded = false;

    protected $isDeprecated = false;

    public function __construct() {

        GeneratorFactory::addGenerator($this);
    }

    /**
     * @return AbstractGeneratorGroup $this
     */
    public function load() {
        if (!$this->isLoaded) {
            if ($this->isInstalled()) {
                $this->loadSources();
            }
            $this->isLoaded = true;
        }

        return $this;
    }

    protected abstract function loadSources();

    public function addSource($name, $source) {
        $this->sources[$name] = $source;
    }

    /**
     * @param $name
     *
     * @return false|AbstractGenerator
     */
    public function getSource($name) {
        if (!isset($this->sources[$name])) {
            return false;
        }

        return $this->sources[$name];
    }

    /**
     * @return AbstractGenerator[]
     */
    public function getSources() {
        return $this->sources;
    }

    public function hasConfiguration() {

        return !!$this->configuration;
    }

    /**
     * @return AbstractGeneratorGroupConfiguration
     */
    public function getConfiguration() {

        return $this->configuration;
    }

    /**
     * @return string
     *
     */
    public abstract function getLabel();

    /**
     * @return string
     */
    public function getDescription() {
        return n2_('No description.');
    }

    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getError() {
        return n2_('Generator not found');
    }

    /**
     * @return string
     */
    public function getDocsLink() {
        return 'https://smartslider.helpscoutdocs.com/article/1999-dynamic-slides';
    }

    public function isInstalled() {
        return true;
    }

    /**
     * @return string
     */
    public function getUrl() {
        return $this->url;
    }

    public function getImageUrl() {

        return Url::pathToUri(self::getAssetsPath() . '/dynamic.png');
    }

    /**
     * @return bool
     */
    public function isDeprecated() {
        return $this->isDeprecated;
    }

}AbstractGeneratorGroupConfiguration.php000064400000005040152356646610014451 0ustar00<?php


namespace Nextend\SmartSlider3\Generator;


use Nextend\Framework\Pattern\MVCHelperTrait;

abstract class AbstractGeneratorGroupConfiguration {

    const CSRF_LENGTH = 32;

    /** @var AbstractGeneratorGroup */
    protected $generatorGroup;

    /**
     * AbstractGeneratorGroupConfiguration constructor.
     *
     * @param AbstractGeneratorGroup $generatorGroup
     */
    public function __construct($generatorGroup) {

        $this->generatorGroup = $generatorGroup;
    }

    /**
     * @return bool
     */
    public abstract function wellConfigured();

    /**
     * @return array
     */
    public abstract function getData();

    /**
     * @param      $data
     * @param bool $store
     */
    public abstract function addData($data, $store = true);

    /**
     * @param MVCHelperTrait $MVCHelper
     */
    public abstract function render($MVCHelper);

    /**
     * @param MVCHelperTrait $MVCHelper
     */
    public abstract function startAuth($MVCHelper);

    /**
     * @param MVCHelperTrait $MVCHelper
     */
    public abstract function finishAuth($MVCHelper);

    protected function generateRandomState() {

        if (function_exists('random_bytes')) {
            return $this->bytesToString(random_bytes(self::CSRF_LENGTH));
        }

        if (function_exists('mcrypt_create_iv')) {
            /** @noinspection PhpDeprecationInspection */
            $binaryString = mcrypt_create_iv(self::CSRF_LENGTH, MCRYPT_DEV_URANDOM);

            if ($binaryString !== false) {
                return $this->bytesToString($binaryString);
            }
        }

        if (function_exists('openssl_random_pseudo_bytes')) {
            $wasCryptographicallyStrong = false;

            $binaryString = openssl_random_pseudo_bytes(self::CSRF_LENGTH, $wasCryptographicallyStrong);

            if ($binaryString !== false && $wasCryptographicallyStrong === true) {
                return $this->bytesToString($binaryString);
            }
        }

        return $this->randomStr(self::CSRF_LENGTH);
    }

    private function bytesToString($binaryString) {
        return substr(bin2hex($binaryString), 0, self::CSRF_LENGTH);
    }

    private function randomStr($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
        $str = '';
        $max = strlen($keyspace) - 1;
        for ($i = 0; $i < $length; ++$i) {
            $str .= $keyspace[random_int(0, $max)];
        }

        return $str;
    }
}AbstractGeneratorLoader.php000064400000001420152356646610012031 0ustar00<?php

namespace Nextend\SmartSlider3\Generator;

use Nextend\Framework\Filesystem\Filesystem;
use ReflectionClass;
use ReflectionException;

abstract class AbstractGeneratorLoader {

    public function __construct() {

        try {
            $reflectionClass = new ReflectionClass($this);
            $namespace       = $reflectionClass->getNamespaceName();

            $dir = dirname($reflectionClass->getFileName());

            foreach (Filesystem::folders($dir) as $name) {
                $className = '\\' . $namespace . '\\' . $name . '\\GeneratorGroup' . $name;

                if (class_exists($className)) {
                    new $className;
                }
            }
        } catch (ReflectionException $e) {

        }
    }
}Generator.php000064400000013140152356646610007220 0ustar00<?php

namespace Nextend\SmartSlider3\Generator;

use Nextend\Framework\Data\Data;
use Nextend\Framework\Notification\Notification;
use Nextend\SmartSlider3\Application\Model\ModelGenerator;
use Nextend\SmartSlider3\Slider\Cache\CacheGenerator;
use Nextend\SmartSlider3\Slider\Slide;
use Nextend\SmartSlider3\Slider\Slider;

class Generator {

    private static $localCache = array();

    /**
     * @var Slide
     */
    private $slide;

    private $generatorModel;

    public $currentGenerator;

    private $slider;

    /** @var  AbstractGenerator */
    private $dataSource;

    /**
     * @param Slide                              $slide
     * @param Slider                             $slider
     * @param                                    $extend
     */
    public function __construct($slide, $slider, $extend) {

        $this->slide  = $slide;
        $this->slider = $slider;

        $this->generatorModel             = new ModelGenerator($slider);
        $this->currentGenerator           = $this->generatorModel->get($this->slide->generator_id);
        $this->currentGenerator['params'] = new Data($this->currentGenerator['params'], true);

        if (isset($extend[$this->slide->generator_id])) {
            $extend = new Data($extend[$this->slide->generator_id]);
            $slide->parameters->set('record-slides', $extend->get('record-slides', 1));
            $extend->un_set('record-slides');
            $this->currentGenerator['params']->loadArray($extend->toArray());
        }
    }

    public function getSlides() {
        $slides = array();
        $data   = $this->getData();
        for ($i = 0; $i < count($data); $i++) {
            $newSlide = clone $this->slide;
            $newSlide->setVariables($data[$i]);
            if ($i > 0) {
                $newSlide->unique = $i;
            }
            $slides[] = $newSlide;
        }
        if (count($slides) == 0) {
            $slides = null;
        }

        return $slides;
    }

    public function getSlidesAdmin() {
        $slides = array();
        $data   = $this->getData();
        for ($i = 0; $i < count($data); $i++) {
            $newSlide = clone $this->slide;
            $newSlide->setVariables($data[$i]);
            if ($i > 0) {
                $newSlide->unique = $i;
            }
            $slides[] = $newSlide;
        }
        if (count($slides) == 0) {
            $slides[] = $this->slide;
        }

        return $slides;
    }

    public function fillSample() {
        $data = $this->getData();
        if (count($data) > 0) {
            $this->slide->setVariables($data[0]);
        }
    }

    /**
     * @return bool|false|AbstractGenerator
     */
    public function getSource() {
        $generatorGroup = $this->generatorModel->getGeneratorGroup($this->currentGenerator['group']);
        if (!$generatorGroup) {
            Notification::notice(n2_('Generator group not found') . ': ' . $this->currentGenerator['group']);

            return false;
        }
        $source = $generatorGroup->getSource($this->currentGenerator['type']);
        if (!$source) {
            Notification::notice(n2_('Generator type not found') . ': ' . $this->currentGenerator['type']);

            return false;
        }

        return $source;
    }

    private function getData() {
        if (!isset(self::$localCache[$this->slide->generator_id])) {


            $this->slider->manifestData['generator'][] = array(
                $this->currentGenerator['group'],
                $this->currentGenerator['type'],
                $this->currentGenerator['params']->toArray()
            );

            $generatorGroup = $this->generatorModel->getGeneratorGroup($this->currentGenerator['group']);
            if (!$generatorGroup) {
                return array();
            }

            $this->dataSource = $generatorGroup->getSource($this->currentGenerator['type']);
            if ($this->dataSource) {
                $this->dataSource->setData($this->currentGenerator['params']);

                $cache = new CacheGenerator($this->slider, $this);
                $name  = $this->dataSource->filterName('generator' . $this->currentGenerator['id']);

                self::$localCache[$this->slide->generator_id] = $cache->makeCache($name, $this->dataSource->hash(json_encode($this->currentGenerator) . max($this->slide->parameters->get('record-slides'), 1)), array(
                    $this,
                    'getNotCachedData'
                ));
            } else {
                self::$localCache[$this->slide->generator_id] = array();
                Notification::error(sprintf(n2_('%1$s generator missing the following source: %2$s'), $generatorGroup->getLabel(), $this->currentGenerator['type']));
            }
        }

        return self::$localCache[$this->slide->generator_id];
    }

    public function getNotCachedData() {
        return $this->dataSource->getData(max($this->slide->parameters->get('record-slides'), 1), max($this->currentGenerator['params']->get('record-start'), 1), $this->getSlideGroup());
    }

    public function setNextCacheRefresh($time) {
        $this->slide->setNextCacheRefresh($time);
    }

    public function getSlideCount() {
        return max($this->slide->parameters->get('record-slides'), 1);
    }

    public function getSlideGroup() {
        return max($this->currentGenerator['params']->get('record-group'), 1);
    }

    public function getSlideStat() {
        return count($this->getData()) . '/' . $this->getSlideCount();
    }
}GeneratorFactory.php000064400000002127152356646610010553 0ustar00<?php

namespace Nextend\SmartSlider3\Generator;

use Nextend\Framework\Pattern\PluggableTrait;
use Nextend\Framework\Pattern\SingletonTrait;

class GeneratorFactory {

    use PluggableTrait, SingletonTrait;

    /** @var AbstractGeneratorGroup[] */
    private static $generators = array();

    protected function init() {

        $this->makePluggable('SliderGenerator');
    }

    /**
     * @param AbstractGeneratorGroup $generator
     */
    public static function addGenerator($generator) {
        self::$generators[$generator->getName()] = $generator;
    }

    public static function getGenerators() {
        foreach (self::$generators as $generator) {
            $generator->load();
        }

        return self::$generators;
    }

    /**
     * @param $name
     *
     * @return AbstractGeneratorGroup|false
     */
    public static function getGenerator($name) {
        if (!isset(self::$generators[$name])) {
            return false;
        }

        return self::$generators[$name]->load();
    }
}

GeneratorFactory::getInstance();Joomla/GeneratorJoomlaLoader.php000064400000000276152356646610012740 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla;

use Nextend\SmartSlider3\Generator\AbstractGeneratorLoader;

class GeneratorJoomlaLoader extends AbstractGeneratorLoader {

}Joomla/JoomlaContent/GeneratorGroupJoomlaContent.php000064400000001473152356646610016735 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla\JoomlaContent;

use Nextend\SmartSlider3\Generator\AbstractGeneratorGroup;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Sources\JoomlaContentArticle;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Sources\JoomlaContentCategory;

class GeneratorGroupJoomlaContent extends AbstractGeneratorGroup {

    protected $name = 'joomlacontent';

    public function getLabel() {
        return n2_('Joomla articles');
    }

    public function getDescription() {
        return n2_('Creates slides from your Joomla articles or categories.');
    }

    protected function loadSources() {
        new JoomlaContentArticle($this, 'article', n2_('Article'));
        new JoomlaContentCategory($this, 'category', n2_('Category'));
    }

}Joomla/JoomlaContent/Elements/JoomlaContentAccessLevels.php000064400000001721152356646610020116 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements;

use Joomla\CMS\Factory;
use Nextend\Framework\Form\Element\Select;


class JoomlaContentAccessLevels extends Select {

    public function __construct($insertAt, $name = '', $label = '', $default = '', $parameters = array()) {
        parent::__construct($insertAt, $name, $label, $default, $parameters);

        $db = Factory::getDBO();

        $query = 'SELECT
                    m.id, 
                    m.title AS name, 
                    m.title, 
                    m.ordering
                FROM #__viewlevels m
                ORDER BY m.ordering';


        $db->setQuery($query);
        $menuItems = $db->loadObjectList();

        $this->options['0'] = n2_('All');

        if (count($menuItems)) {
            foreach ($menuItems as $option) {
                $this->options[$option->id] = $option->name;
            }
        }
    }

}
Joomla/JoomlaContent/Elements/JoomlaContentCategories.php000064400000003243152356646610017630 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Nextend\Framework\Form\Element\Select;


class JoomlaContentCategories extends Select {

    public function __construct($insertAt, $name = '', $label = '', $default = '', $parameters = array()) {
        parent::__construct($insertAt, $name, $label, $default, $parameters);

        $db = Factory::getDBO();

        $query = 'SELECT
                    id, 
                    title AS name, 
                    title, 
                    parent_id AS parent, 
                    parent_id
                FROM #__categories
                WHERE published = 1 AND extension = "com_content"
                ORDER BY lft';


        $db->setQuery($query);
        $menuItems = $db->loadObjectList();
        $children  = array();
        if ($menuItems) {
            foreach ($menuItems as $v) {
                $pt   = $v->parent_id;
                $list = isset($children[$pt]) ? $children[$pt] : array();
                array_push($list, $v);
                $children[$pt] = $list;
            }
        }

        $this->options[0] = n2_('All');

        jimport('joomla.html.html.menu');
        $options = HTMLHelper::_('menu.treerecurse', 1, '', array(), $children, 9999, 0, 0);
        if (count($options)) {
            foreach ($options as $option) {
                $this->options[$option->id] = $option->treename;
            }
        }
        if ($this->getValue() == '') {
            reset($this->options);
            $this->setValue(key($this->options));
        }

    }

}
Joomla/JoomlaContent/Elements/JoomlaContentTags.php000064400000001530152356646610016436 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements;

use Joomla\CMS\Factory;
use Nextend\Framework\Form\Element\Select;


class JoomlaContentTags extends Select {

    public function __construct($insertAt, $name = '', $label = '', $default = '', $parameters = array()) {
        parent::__construct($insertAt, $name, $label, $default, $parameters);

        $db = Factory::getDBO();

        $query = 'SELECT id, title FROM #__tags WHERE published = 1 ORDER BY id';

        $db->setQuery($query);
        $menuItems = $db->loadObjectList();

        $this->options['0'] = n2_('All');

        if (count($menuItems)) {
            array_shift($menuItems);
            foreach ($menuItems as $option) {
                $this->options[$option->id] = $option->title;
            }
        }
    }

}
Joomla/JoomlaContent/Sources/JoomlaContentArticle.php000064400000051614152356646610017002 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Sources;

use Joomla\Component\Content\Site\Helper\RouteHelper;
use DateTime;
use DateTimeZone;
use ContentHelperRoute;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Nextend\Framework\Database\Database;
use Nextend\Framework\Form\Container\ContainerTable;
use Nextend\Framework\Form\Element\MixedField\GeneratorOrder;
use Nextend\Framework\Form\Element\OnOff;
use Nextend\Framework\Form\Element\Select;
use Nextend\Framework\Form\Element\Select\Filter;
use Nextend\Framework\Form\Element\Text;
use Nextend\Framework\Form\Element\Text\Number;
use Nextend\Framework\Form\Element\Textarea;
use Nextend\Framework\Parser\Common;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
use Nextend\Framework\Url\Url;
use Nextend\SmartSlider3\Generator\AbstractGenerator;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements\JoomlaContentAccessLevels;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements\JoomlaContentCategories;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements\JoomlaContentTags;
use Nextend\SmartSlider3\Platform\Joomla\ImageFallback;
use Nextend\SmartSlider3\Platform\Joomla\JoomlaShim;
use Nextend\SmartSlider3\Slider\Slider;
use stdClass;


JoomlaShim::loadComContentRoute();


class JoomlaContentArticle extends AbstractGenerator {

    protected $layout = 'article';

    public function getDescription() {
        return n2_('Creates slides from your Joomla articles in the selected categories.');
    }

    public function renderFields($container) {
        parent::renderFields($container);

        $filterGroup = new ContainerTable($container, 'filter', n2_('Filter'));

        $source = $filterGroup->createRow('source-row');
        new JoomlaContentCategories($source, 'sourcecategories', n2_('Category'), 0, array(
            'isMultiple' => true
        ));
        new JoomlaContentTags($source, 'sourcetags', n2_('Tags'), 0, array(
            'isMultiple' => true
        ));
        new JoomlaContentAccessLevels($source, 'sourceaccesslevels', n2_('Access level'), 0, array(
            'isMultiple' => true
        ));

        $limit = $filterGroup->createRow('limit-row');

        new Filter($limit, 'sourcefeatured', n2_('Featured'), 0);
        new Number($limit, 'sourceuserid', n2_('User ID'), '', array(
            'tipLabel'       => n2_('Created by'),
            'tipDescription' => n2_('The ID number of the article\'s author. Only one number is accepted.'),
        ));
        new Text($limit, 'sourcearticleids', n2_('Included article IDs'), '', array(
            'tipLabel'       => n2_('Included article IDs'),
            'tipDescription' => n2_('Write down article ID numbers separated by commas, to include them in the result. For example: 1,12,25'),
        ));
        new Text($limit, 'sourcearticleidsexcluded', n2_('Excluded article IDs'), '', array(
            'tipLabel'       => n2_('Excluded article IDs'),
            'tipDescription' => n2_('Write down article ID numbers separated by commas, to exclude them from the result. For example: 2,14,27'),
        ));
        new Text($limit, 'sourcelanguage', n2_('Language'), '*', array(
            'tipLabel'       => n2_('Language'),
            'tipDescription' => n2_('The language code of your articles. Multiple language codes should be separated by commas, for example: en-GB,hu-HU,es-ES'),
            'tipLink'        => 'https://smartslider.helpscoutdocs.com/article/1879-language-filters'
        ));

        $variables = $filterGroup->createRow('variables-row');

        new OnOff($variables, 'sourcefields', n2_('Fields'), 0, array(
            'tipLabel'       => n2_('Extra variables'),
            'tipDescription' => n2_('Turn on these options to generate more variables for the slides.'),
            'tipLink'        => 'https://smartslider.helpscoutdocs.com/article/1864-joomla-articles-generator#fields'
        ));
        new OnOff($variables, 'sourcetagvariables', n2_('Tags'), 0, array(
            'tipLabel'       => n2_('Extra variables'),
            'tipDescription' => n2_('Turn on these options to generate more variables for the slides.'),
            'tipLink'        => 'https://smartslider.helpscoutdocs.com/article/1864-joomla-articles-generator#tags-19'
        ));
        new Select($variables, 'removeshortcodes', n2_('Remove shortcodes'), '0', array(
            'isMultiple'     => true,
            'size'           => 5,
            'options'        => array(
                '0' => n2_('All'),
                '1' => '{shortcode}example{/shortcode}',
                '2' => '{shortcode}',
                '3' => '[shortcode]example[/shortcode]',
                '4' => '[shortcode]'
            ),
            'tipLabel'       => n2_('Remove shortcodes'),
            'tipDescription' => n2_('Remove shortcodes from article description with the following patterns.')
        ));

        $date = $filterGroup->createRow('date-row');
        new Text($date, 'sourcedateformat', n2_('Date format'), 'm-d-Y');
        new Text($date, 'sourcetimeformat', n2_('Time format'), 'G:i');
        new Textarea($date, 'sourcetranslatedate', n2_('Translate date and time'), 'January->January||February->February||March->March', array(
            'width'  => 300,
            'height' => 100

        ));

        $orderGroup = new ContainerTable($container, 'order-group', n2_('Order'));
        $order      = $orderGroup->createRow('order-row');
        new GeneratorOrder($order, 'joomlaorder', 'con.created|*|desc', array(
            'options' => array(
                ''                 => n2_('None'),
                'con.title'        => n2_('Title'),
                'cat_title'        => n2_('Category'),
                'created_by_alias' => n2_('User name'),
                'con.featured'     => n2_('Featured'),
                'con.ordering'     => n2_('Ordering'),
                'con.hits'         => n2_('Hits'),
                'con.created'      => n2_('Creation time'),
                'con.modified'     => n2_('Modification time'),
                'con.publish_up'   => n2_('Publish time'),
                'cf.ordering'      => n2_('Featured article ordering')
            )
        ));
    }

    public function datify($date, $format) {
        if (empty($date) || $date == '0000-00-00 00:00:00') {
            return '';
        } else {
            $config   = Factory::getConfig();
            $timezone = new DateTimeZone($config->get('offset'));
            $offset   = $timezone->getOffset(new DateTime);

            $result = date($format, strtotime($date) + $offset);

            return $result;
        }
    }

    private function translate($from, $translate) {
        if (!empty($translate) && !empty($from)) {
            foreach ($translate as $key => $value) {
                $from = str_replace($key, $value, $from);
            }
        }

        return $from;
    }

    private function removeShortcodes($content) {
        $selection = $this->data->get('removeshortcodes', 1);
        if ($selection !== '') {
            $shortcodes = explode('||', $selection);

            if (in_array(0, $shortcodes) || in_array(1, $shortcodes)) {
                $content = preg_replace('/{[^{}]*?}[^{}]*?{\/.*?}/', '', $content);
            }
            if (in_array(0, $shortcodes) || in_array(2, $shortcodes)) {
                $content = preg_replace('/{.*?}/', '', $content);
            }
            if (in_array(0, $shortcodes) || in_array(3, $shortcodes)) {
                $content = preg_replace('/\[[^\[\]]*?][^\[\]]*?\[\/.*?]/', '', $content);
            }
            if (in_array(0, $shortcodes) || in_array(4, $shortcodes)) {
                $content = preg_replace('/\[.*?]/', '', $content);
            }
        }

        return $content;
    }

    protected function _getData($count, $startIndex) {
        $categories = array_map('intval', explode('||', $this->data->get('sourcecategories', '')));
        $tags       = array_map('intval', explode('||', $this->data->get('sourcetags', '0')));

        $query = 'SELECT ';
        $query .= 'con.id, ';
        $query .= 'con.title, ';
        $query .= 'con.alias, ';
        $query .= 'con.introtext, ';
        $query .= 'con.fulltext, ';
        $query .= 'con.created, ';
        $query .= 'con.catid, ';
        $query .= 'cat.title AS cat_title, ';
        $query .= 'cat.alias AS cat_alias, ';
        $query .= 'con.created_by, con.state, con.metadata, ';
        $query .= 'con.created_by_alias AS con_created_by_alias, ';
        $query .= 'usr.name AS created_by_alias, ';
        $query .= 'con.images, ';
        $query .= 'con.publish_up, ';
        $query .= 'con.publish_down, ';
        $query .= 'con.urls, ';
        $query .= 'con.attribs ';

        $query .= 'FROM #__content AS con ';

        $query .= 'LEFT JOIN #__users AS usr ON usr.id = con.created_by ';

        $query .= 'LEFT JOIN #__categories AS cat ON cat.id = con.catid ';

        $query .= 'LEFT JOIN #__content_frontpage AS cf ON cf.content_id = con.id ';

        $jNow  = Factory::getDate();
        $now   = $jNow->toSql();
        $where = array(
            'con.state = 1 ',
            "(con.publish_up IS NULL OR con.publish_up = '0000-00-00 00:00:00' OR con.publish_up < '" . $now . "') AND (con.publish_down IS NULL OR con.publish_down = '0000-00-00 00:00:00' OR con.publish_down > '" . $now . "') "
        );

        if (!in_array(0, $categories)) {
            $where[] = 'con.catid IN (' . implode(',', $categories) . ') ';
        }

        if (!in_array(0, $tags)) {
            $where[] = 'con.id IN (SELECT content_item_id FROM #__contentitem_tag_map WHERE type_alias = \'com_content.article\' AND tag_id IN (' . implode(',', $tags) . ')) ';
        }

        $sourceUserID = intval($this->data->get('sourceuserid', ''));
        if ($sourceUserID) {
            $where[] = 'con.created_by = ' . $sourceUserID . ' ';
        }

        switch ($this->data->get('sourcefeatured', 0)) {
            case 1:
                $where[] = 'con.featured = 1 ';
                break;
            case -1:
                $where[] = 'con.featured = 0 ';
                break;
        }
        $language = explode(",", $this->data->get('sourcelanguage', '*'));
        if (!empty($language[0]) && $language[0] != '*') {
            $where[] = 'con.language IN (' . implode(",", Database::quote($language)) . ') ';
        }

        $articleIds = $this->data->get('sourcearticleids', '');
        if (!empty($articleIds)) {
            $where[] = 'con.id IN (' . preg_replace("/[^0-9,]/", "", $articleIds) . ') ';
        }

        $articleIdsExcluded = $this->data->get('sourcearticleidsexcluded', '');
        if (!empty($articleIdsExcluded)) {
            $where[] = 'con.id NOT IN (' . preg_replace("/[^0-9,]/", "", $articleIdsExcluded) . ') ';
        }

        $accessLevels = explode('||', $this->data->get('sourceaccesslevels', '*'));
        if (!in_array(0, $accessLevels)) {
            $where[] = 'con.access IN (' . implode(",", $accessLevels) . ')';
        }

        if (count($where) > 0) {
            $query .= 'WHERE ' . implode(' AND ', $where) . ' ';
        }

        $order = Common::parse($this->data->get('joomlaorder', 'con.created|*|desc'));
        if ($order[0]) {
            $query .= 'ORDER BY ' . $order[0] . ' ' . $order[1] . ' ';
        }

        $query .= 'LIMIT ' . $startIndex . ', ' . $count;

        $result = Database::queryAll($query);

        if (empty($result)) {
            return null;
        }

        $sourceTranslate = $this->data->get('sourcetranslatedate', '');
        $translateValue  = explode('||', $sourceTranslate);
        $translate       = array();
        if ($sourceTranslate != 'January->January||February->February||March->March' && !empty($translateValue)) {
            foreach ($translateValue as $tv) {
                $translateArray = explode('->', $tv);
                if (!empty($translateArray) && count($translateArray) == 2) {
                    $translate[$translateArray[0]] = $translateArray[1];
                }
            }
        }

        PluginHelper::importPlugin('content');
        $uri = Url::getBaseUri();

        $data    = array();
        $idArray = array();
        for ($i = 0; $i < count($result); $i++) {
            $idArray[$i] = $result[$i]['id'];
            $r           = array(
                'title' => $result[$i]['title']
            );

            $article       = new stdClass();
            $article->text = $this->removeShortcodes(Slider::removeShortcode($result[$i]['introtext']));
            $_p            = array();

            JoomlaShim::triggerOnContentPrepare(array(
                'com_smartslider3',
                &$article,
                &$_p,
                0
            ));
            if (!empty($article->text)) {
                $r['description'] = $article->text;
            }

            $article->text = $result[$i]['fulltext'];
            $_p            = array();
            JoomlaShim::triggerOnContentPrepare(array(
                'com_smartslider3',
                &$article,
                &$_p,
                0
            ));
            if (!empty($article->text)) {
                $result[$i]['fulltext'] = $article->text;
                if (!isset($r['description'])) {
                    $r['description'] = $result[$i]['fulltext'];
                } else {
                    $r['fulltext'] = $result[$i]['fulltext'];
                }
            }

            $images = (array)json_decode($result[$i]['images'], true);

            $r['image'] = $r['thumbnail'] = ImageFallback::fallback(array(
                @$images['image_intro'],
                @$images['image_fulltext']
            ), array(
                @$r['description']
            ));

            $r += array(
                'url'               => JoomlaShim::$isJoomla4 ? RouteHelper::getArticleRoute($result[$i]['id'] . ':' . $result[$i]['alias'], $result[$i]['catid'] . ':' . $result[$i]['cat_alias']) : ContentHelperRoute::getArticleRoute($result[$i]['id'] . ':' . $result[$i]['alias'], $result[$i]['catid'] . ':' . $result[$i]['cat_alias']),
                'url_label'         => n2_('View article'),
                'category_list_url' => 'index.php?option=com_content&view=category&id=' . $result[$i]['catid'],
                'category_blog_url' => 'index.php?option=com_content&view=category&layout=blog&id=' . $result[$i]['catid'],
                'fulltext_image'    => ImageFallback::fallback(array(@$images['image_fulltext'])),
                'category_title'    => $result[$i]['cat_title'],
                'created_by'        => $result[$i]['created_by_alias'],
                'con_created_by'    => $result[$i]['con_created_by_alias'],
                'id'                => $result[$i]['id'],
                'created_date'      => $this->translate($this->datify($result[$i]['created'], $this->data->get('sourcedateformat', 'm-d-Y')), $translate),
                'created_time'      => $this->translate($this->datify($result[$i]['created'], $this->data->get('sourcetimeformat', 'G:i')), $translate),
                'publish_up_date'   => $this->translate($this->datify($result[$i]['publish_up'], $this->data->get('sourcedateformat', 'm-d-Y')), $translate),
                'publish_up_time'   => $this->translate($this->datify($result[$i]['publish_up'], $this->data->get('sourcetimeformat', 'G:i')), $translate),
                'publish_down_date' => $this->translate($this->datify($result[$i]['publish_down'], $this->data->get('sourcedateformat', 'm-d-Y')), $translate),
                'publish_down_time' => $this->translate($this->datify($result[$i]['publish_down'], $this->data->get('sourcetimeformat', 'G:i')), $translate),
            );

            if (!empty($images)) {
                foreach ($images as $name => $value) {
                    if (!empty($value)) {
                        $image = ImageFallback::fallback(array($value));
                        if (!empty($image)) {
                            $r[$name] = $image;
                        } else {
                            $r[$name] = $value;
                        }
                    }
                }
            }

            $urls = json_decode($result[$i]['urls'], true);
            if (!empty($urls['urla'])) {
                $r['urla']     = $urls['urla'];
                $r['urlatext'] = $urls['urlatext'];
            }
            if (!empty($urls['urlb'])) {
                $r['urlb']     = $urls['urlb'];
                $r['urlbtext'] = $urls['urlbtext'];
            }
            if (!empty($urls['urlc'])) {
                $r['urlc']     = $urls['urlc'];
                $r['urlctext'] = $urls['urlctext'];
            }

            $metadata = json_decode($result[$i]['metadata']);
            foreach ($metadata as $metakey => $metavalue) {
                $r[$metakey] = $metavalue;
            }

            $attribs = (array)json_decode($result[$i]['attribs'], true);
            foreach ($attribs as $attrib => $value) {
                if (!empty($value) && is_string($value)) {
                    $r[$attrib] = $value;
                }
            }

            if (isset($r['helix_ultimate_image'])) {
                $r['spfeatured_image'] = $r['helix_ultimate_image'] = '$/' . $r['helix_ultimate_image'];
            }

            if (isset($r['helix_ultimate_gallery'])) {
                $gallery = (array)json_decode($r['helix_ultimate_gallery'], true);
                for ($j = 0; $j < count($gallery["helix_ultimate_gallery_images"]); $j++) {
                    $r['helix_ultimate_gallery_images_' . $j] = $r['spgallery_' . $j] = '$/' . $gallery["helix_ultimate_gallery_images"][$j];
                }

            }

            $data[] = $r;
        }

        if (!empty($idArray)) {
            if ($this->data->get('sourcetagvariables', 0)) {
                $query  = 'SELECT t.title, c.content_item_id  FROM #__tags AS t
				  LEFT JOIN #__contentitem_tag_map AS c ON t.id = c.tag_id
				  WHERE t.id IN (SELECT tag_id FROM #__contentitem_tag_map WHERE type_alias = \'com_content.article\' AND content_item_id IN (' . implode(',', $idArray) . '))';
                $result = Database::queryAll($query);

                if (!empty($result)) {
                    $tags     = array();
                    $articles = array();
                    foreach ($result as $r) {
                        $tags[$r['content_item_id']][] = $r['title'];
                        $articles[]                    = $r['content_item_id'];

                    }
                    for ($i = 0; $i < count($data); $i++) {
                        if (in_array($data[$i]['id'], $articles)) {
                            $j = 1;
                            foreach ($tags[$data[$i]['id']] as $tag) {
                                $data[$i]['tag' . $j] = $tag;
                                $j++;
                            }
                        }
                    }
                }
            }

            if ($this->data->get('sourcefields', 0)) {
                $query  = "SELECT fv.value, fv.item_id, f.name, f.type FROM #__fields_values AS fv LEFT JOIN #__fields AS f ON fv.field_id = f.id WHERE fv.item_id IN (" . implode(',', $idArray) . ")";
                $result = Database::queryAll($query);
                if (!empty($result)) {
                    $AllResult = array();
                    foreach ($result as $r) {
                        if ($r['type'] == 'media') {
                            $valueParts = json_decode($r['value']);
                            if (isset($valueParts->imagefile)) {
                                $r['value']                                         = ImageFallback::fallback(array($valueParts->imagefile));
                                $AllResult[$r['item_id']][$r['name'] . '_alt_text'] = $valueParts->alt_text;
                            } else {
                                $r['value'] = ResourceTranslator::urlToResource($uri . "/" . $r["value"]);
                            }
                        }

                        $AllResult[$r['item_id']][$r['name']] = $r['value'];
                    }

                    for ($i = 0; $i < count($data); $i++) {
                        if (isset($AllResult[$data[$i]['id']])) {
                            foreach ($AllResult[$data[$i]['id']] as $key => $value) {
                                $key            = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]*/', '', $key);
                                $data[$i][$key] = $value;
                            }
                        }
                    }
                }
            }
        }

        return $data;
    }

}Joomla/JoomlaContent/Sources/JoomlaContentCategory.php000064400000014036152356646610017171 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Sources;

use Joomla\CMS\Plugin\PluginHelper;
use Nextend\Framework\Database\Database;
use Nextend\Framework\Form\Container\ContainerTable;
use Nextend\Framework\Form\Element\MixedField\GeneratorOrder;
use Nextend\Framework\Form\Element\Text;
use Nextend\Framework\Parser\Common;
use Nextend\SmartSlider3\Generator\AbstractGenerator;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements\JoomlaContentCategories;
use Nextend\SmartSlider3\Generator\Joomla\JoomlaContent\Elements\JoomlaContentTags;
use Nextend\SmartSlider3\Platform\Joomla\ImageFallback;
use Nextend\SmartSlider3\Platform\Joomla\JoomlaShim;
use Nextend\SmartSlider3\Slider\Slider;
use stdClass;


class JoomlaContentCategory extends AbstractGenerator {

    protected $layout = 'article';

    public function getDescription() {
        return n2_('Creates slides from your Joomla categories. (Not the articles inside them.)');
    }

    public function renderFields($container) {
        parent::renderFields($container);

        $filterGroup = new ContainerTable($container, 'filter', n2_('Filter'));

        $source = $filterGroup->createRow('source-row');
        new JoomlaContentCategories($source, 'sourcecategory', n2_('Parent category'), 0);
        new JoomlaContentTags($source, 'sourcetags', n2_('Tags'), 0, array(
            'isMultiple' => true
        ));

        $languageRow = $filterGroup->createRow('language-row');
        new Text($languageRow, 'sourcelanguage', n2_('Language'), '*');

        $orderGroup = new ContainerTable($container, 'order-group', n2_('Order'));
        $order      = $orderGroup->createRow('order-row');
        new GeneratorOrder($order, 'joomlaorder', 'cat.created_time|*|desc', array(
            'options' => array(
                ''                  => n2_('None'),
                'cat.title'         => n2_('Title'),
                'cat.lft'           => n2_('Ordering'),
                'cat.created_time'  => n2_('Creation time'),
                'cat.modified_time' => n2_('Modification time'),
                'cat.hits'          => n2_('Hits')
            )
        ));
    }

    protected function _getData($count, $startIndex) {

        $category = $this->data->get('sourcecategory', '');
        $tags     = array_map('intval', explode('||', $this->data->get('sourcetags', '0')));

        $query = 'SELECT ';
        $query .= 'cat.id, ';
        $query .= 'cat.title, ';
        $query .= 'cat.alias, ';
        $query .= 'cat.description, ';
        $query .= 'cat.params, ';
        $query .= 'cat_parent.id AS parent_id, ';
        $query .= 'cat_parent.title AS parent_title ';

        $query .= 'FROM #__categories AS cat ';

        $query .= 'LEFT JOIN #__categories AS cat_parent ON cat_parent.id = cat.parent_id ';


        $where = array(
            'cat.published = 1 ',
            'cat.extension = \'com_content\' '
        );

        if ($category != 0) {
            $where[] = 'cat.parent_id = ' . $category . ' ';
        }

        if (!in_array(0, $tags)) {
            $where[] = 'cat.id IN (SELECT content_item_id FROM #__contentitem_tag_map WHERE type_alias = \'com_content.category\'  AND tag_id IN (' . implode(',', $tags) . ')) ';
        }

        $language = $this->data->get('sourcelanguage', '*');
        if ($language) {
            $where[] = 'cat.language = ' . Database::quote($language) . ' ';
        }

        if (count($where) > 0) {
            $query .= 'WHERE ' . implode(' AND ', $where) . ' ';
        }

        $order = Common::parse($this->data->get('joomlaorder', 'cat.created_time|*|desc'));
        if ($order[0]) {
            $query .= 'ORDER BY ' . $order[0] . ' ' . $order[1] . ' ';
        }

        $query .= 'LIMIT ' . $startIndex . ', ' . $count . ' ';

        $result = Database::queryAll($query);

        PluginHelper::importPlugin('content');

        $data = array();
        for ($i = 0; $i < count($result); $i++) {
            $r = array(
                'title' => $result[$i]['title']
            );

            $article       = new stdClass();
            $article->text = Slider::removeShortcode($result[$i]['description']);
            $_p            = array();
            JoomlaShim::triggerOnContentPrepare(array(
                'com_smartslider3',
                &$article,
                &$_p,
                0
            ));
            if (!empty($article->text)) {
                $r['description'] = $article->text;
            } else {
                $r['description'] = '';
            }
            $params = (array)json_decode($result[$i]['params'], true);

            $r['image'] = $r['thumbnail'] = ImageFallback::fallback(array(@$params['image']), array($r['description']));

            $r += array(
                'url'       => 'index.php?option=com_content&view=category&id=' . $result[$i]['id'],
                'url_label' => n2_('View category'),
                'url_blog'  => 'index.php?option=com_content&view=category&layout=blog&id=' . $result[$i]['id']
            );

            if ($result[$i]['parent_title'] != 'ROOT') {
                $r += array(
                    'parent_title'    => $result[$i]['parent_title'],
                    'parent_url'      => 'index.php?option=com_content&view=category&id=' . $result[$i]['parent_id'],
                    'parent_url_blog' => 'index.php?option=com_content&view=category&layout=blog&id=' . $result[$i]['parent_id']
                );
            } else {
                $r += array(
                    'parent_title'    => '',
                    'parent_url'      => '',
                    'parent_url_blog' => ''
                );
            }

            $r += array(
                'alias'     => $result[$i]['alias'],
                'id'        => $result[$i]['id'],
                'parent_id' => $result[$i]['parent_id']
            );

            $data[] = $r;
        }

        return $data;
    }

}
Common/GeneratorCommonLoader.php000064400000000276152356646610012756 0ustar00<?php

namespace Nextend\SmartSlider3\Generator\Common;

use Nextend\SmartSlider3\Generator\AbstractGeneratorLoader;

class GeneratorCommonLoader extends AbstractGeneratorLoader {

}