first
This commit is contained in:
@ -0,0 +1,162 @@
|
||||
<?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) {
|
||||
Shortcode::shortcodeModeToNoop();
|
||||
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Shortcode::shortcodeModeToNormal();
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator;
|
||||
|
||||
|
||||
use Nextend\Framework\Pattern\MVCHelperTrait;
|
||||
|
||||
abstract class AbstractGeneratorGroupConfiguration {
|
||||
|
||||
/** @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);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\Common;
|
||||
|
||||
use Nextend\SmartSlider3\Generator\AbstractGeneratorLoader;
|
||||
|
||||
class GeneratorCommonLoader extends AbstractGeneratorLoader {
|
||||
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?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();
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress;
|
||||
|
||||
use Nextend\SmartSlider3\Generator\AbstractGeneratorLoader;
|
||||
|
||||
class GeneratorWordPressLoader extends AbstractGeneratorLoader {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsCategories extends Select {
|
||||
|
||||
protected $isMultiple = true;
|
||||
|
||||
protected $size = 10;
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
$args = array(
|
||||
'type' => 'post',
|
||||
'child_of' => 0,
|
||||
'parent' => '',
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => 0,
|
||||
'hierarchical' => 1,
|
||||
'exclude' => '',
|
||||
'include' => '',
|
||||
'number' => '',
|
||||
'taxonomy' => 'category',
|
||||
'pad_counts' => false
|
||||
|
||||
);
|
||||
$categories = get_categories($args);
|
||||
$new = array();
|
||||
foreach ($categories as $a) {
|
||||
$new[$a->category_parent][] = $a;
|
||||
}
|
||||
$list = array();
|
||||
$options = $this->createTree($list, $new, 0);
|
||||
|
||||
$this->options['0'] = n2_('All');
|
||||
if (count($options)) {
|
||||
foreach ($options as $option) {
|
||||
$this->options[$option->cat_ID] = ' - ' . $option->treename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsCustomFields extends Select {
|
||||
|
||||
protected $postType = '';
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
$this->options['0'] = n2_('Nothing');
|
||||
|
||||
$metaKeys = $this->generate_meta_keys();
|
||||
foreach ($metaKeys as $metaKey) {
|
||||
$this->options[$metaKey] = $metaKey;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_meta_keys() {
|
||||
global $wpdb;
|
||||
$query = "SELECT DISTINCT($wpdb->postmeta.meta_key) FROM $wpdb->posts
|
||||
LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id
|
||||
WHERE $wpdb->posts.post_type = '%s' ORDER BY $wpdb->postmeta.meta_key ASC";
|
||||
$meta_keys = $wpdb->get_col($wpdb->prepare($query, $this->postType));
|
||||
|
||||
return $meta_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $postType
|
||||
*/
|
||||
public function setPostType($postType) {
|
||||
$this->postType = $postType;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsMetaKeys extends Select {
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
$this->options['0'] = n2_('Nothing');
|
||||
|
||||
$metaKeys = $this->generate_meta_keys();
|
||||
foreach ($metaKeys as $metaKey) {
|
||||
$this->options[$metaKey] = $metaKey;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_meta_keys() {
|
||||
global $wpdb;
|
||||
$query = "SELECT DISTINCT($wpdb->postmeta.meta_key) FROM $wpdb->posts
|
||||
LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ORDER BY $wpdb->postmeta.meta_key ASC";
|
||||
$meta_keys = $wpdb->get_results($query, ARRAY_A);
|
||||
$return = array();
|
||||
foreach ($meta_keys as $num => $array) {
|
||||
if (!empty($array['meta_key'])) {
|
||||
$return[] = $array['meta_key'];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsOptions extends Select {
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
$options = wp_load_alloptions();
|
||||
|
||||
$this->options['0'] = n2_('Nothing');
|
||||
foreach ($options as $option => $value) {
|
||||
$this->options[$option] = $option;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsPostTypes extends Select {
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
|
||||
$this->options['0'] = n2_('All');
|
||||
|
||||
$postTypes = get_post_types();
|
||||
foreach ($postTypes as $postType) {
|
||||
$this->options[$postType] = $postType;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsTags extends Select {
|
||||
|
||||
protected $isMultiple = true;
|
||||
|
||||
protected $size = 10;
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
$this->options['0'] = n2_('All');
|
||||
|
||||
$terms = get_terms('post_tag');
|
||||
|
||||
if (count($terms)) {
|
||||
foreach ($terms as $term) {
|
||||
$this->options[$term->term_id] = '- ' . $term->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Elements;
|
||||
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
|
||||
|
||||
class PostsTaxonomies extends Select {
|
||||
|
||||
protected $isMultiple = true;
|
||||
|
||||
protected $size = 10;
|
||||
|
||||
protected $postType = '';
|
||||
|
||||
protected $postSeparator = '_x_';
|
||||
|
||||
protected $skip = false;
|
||||
|
||||
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
|
||||
parent::__construct($insertAt, $name, $label, $default, $parameters);
|
||||
|
||||
$this->options['0'] = n2_('All');
|
||||
|
||||
$taxonomyNames = get_object_taxonomies($this->postType);
|
||||
|
||||
if ($this->skip) {
|
||||
$skip = array(
|
||||
'category',
|
||||
'post_tag'
|
||||
);
|
||||
} else {
|
||||
$skip = array();
|
||||
}
|
||||
|
||||
foreach ($taxonomyNames as $taxonomyName) {
|
||||
if (!in_array($taxonomyName, $skip)) {
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => $taxonomyName
|
||||
));
|
||||
if (count($terms)) {
|
||||
$taxonomy = get_taxonomy($taxonomyName);
|
||||
$options = array();
|
||||
foreach ($terms as $term) {
|
||||
$options[$taxonomy->name . $this->postSeparator . $term->term_id] = '- ' . $term->name;
|
||||
}
|
||||
$this->optgroup[$taxonomy->label] = $options;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $postType
|
||||
*/
|
||||
public function setPostType($postType) {
|
||||
$this->postType = $postType;
|
||||
}
|
||||
|
||||
public function setPostSeparator($postSeparator) {
|
||||
$this->postSeparator = $postSeparator;
|
||||
}
|
||||
|
||||
public function setSkip($skip) {
|
||||
$this->skip = $skip;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts;
|
||||
|
||||
use Nextend\SmartSlider3\Generator\AbstractGeneratorGroup;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Sources\PostsAllCustomPosts;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Sources\PostsCustomPosts;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Sources\PostsPosts;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Sources\PostsPostsByIDs;
|
||||
|
||||
class GeneratorGroupPosts extends AbstractGeneratorGroup {
|
||||
|
||||
protected $name = 'posts';
|
||||
|
||||
public function getLabel() {
|
||||
return n2_('Posts');
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return sprintf(n2_('Creates slides from %1$s.'), 'WordPress posts');
|
||||
}
|
||||
|
||||
protected function loadSources() {
|
||||
|
||||
new PostsPosts($this, 'posts', n2_('Posts by filter'));
|
||||
|
||||
new PostsPostsByIDs($this, 'postsbyids', n2_('Posts by IDs'));
|
||||
}
|
||||
|
||||
public static $ElementorCount = 0;
|
||||
public static $ElementorWidgetType = '';
|
||||
|
||||
public static function getElementorTextEditors($array) {
|
||||
$datas = array();
|
||||
if (!is_array($array)) {
|
||||
$array = (array)$array;
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$datas = array_merge($datas, self::getElementorTextEditors($value));
|
||||
} else {
|
||||
if (isset($array['widgetType'])) {
|
||||
self::$ElementorWidgetType = $array['widgetType'];
|
||||
}
|
||||
if ($key == 'editor' && self::$ElementorWidgetType == 'text-editor') {
|
||||
self::$ElementorCount++;
|
||||
$datas[$key . self::$ElementorCount] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
public static function resetElementorHelpers() {
|
||||
self::$ElementorCount = 0;
|
||||
self::$ElementorWidgetType = '';
|
||||
}
|
||||
|
||||
public static function extractPostMeta($post_meta, $pre = '') {
|
||||
$record = array();
|
||||
if (count($post_meta) && is_array($post_meta) && !empty($post_meta)) {
|
||||
$excluded_metas = array(
|
||||
'hc-editor-mode',
|
||||
'techline-sidebar'
|
||||
);
|
||||
|
||||
foreach ($excluded_metas as $excluded_meta) {
|
||||
if (isset($post_meta[$excluded_meta])) {
|
||||
unset($post_meta[$excluded_meta]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($post_meta as $key => $value) {
|
||||
if (count($value) && is_array($value) && !empty($value)) {
|
||||
foreach ($value as $v) {
|
||||
if (!empty($v) && !is_array($v) && !is_object($v)) {
|
||||
$key = str_replace(array(
|
||||
'_',
|
||||
'-'
|
||||
), array(
|
||||
'',
|
||||
''
|
||||
), $key);
|
||||
$key = $pre . $key;
|
||||
if (array_key_exists($key, $record)) {
|
||||
$key = 'meta' . $key;
|
||||
}
|
||||
if (is_serialized($v)) {
|
||||
$unserialize_values = unserialize($v);
|
||||
$unserialize_count = 1;
|
||||
if (!empty($unserialize_values) && is_array($unserialize_values)) {
|
||||
foreach ($unserialize_values as $unserialize_value) {
|
||||
if (!empty($unserialize_value) && is_string($unserialize_value)) {
|
||||
$record['us_' . $key . $unserialize_count] = $unserialize_value;
|
||||
$unserialize_count++;
|
||||
} else if (is_array($unserialize_value)) {
|
||||
foreach ($unserialize_value as $u_v) {
|
||||
if (is_string($u_v)) {
|
||||
$record['us_' . $key . $unserialize_count] = $u_v;
|
||||
$unserialize_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$record[$key] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($record['elementordata'])) {
|
||||
$elementordatas = json_decode($record['elementordata']);
|
||||
foreach ($elementordatas as $elementordata) {
|
||||
foreach (self::getElementorTextEditors($elementordata) as $elementorKey => $elementorVal) {
|
||||
$record[$elementorKey] = $elementorVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
self::resetElementorHelpers();
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public static function getACFData($postID, $pre = '') {
|
||||
$record = array();
|
||||
if (class_exists('acf')) {
|
||||
$fields = get_fields($postID);
|
||||
if (is_array($fields) && !empty($fields) && count($fields)) {
|
||||
foreach ($fields as $k => $v) {
|
||||
$type = self::getACFType($k, $postID);
|
||||
$k = str_replace('-', '', $k);
|
||||
$k = $pre . $k;
|
||||
|
||||
while (isset($record[$k])) {
|
||||
$k = 'acf_' . $k;
|
||||
}
|
||||
if (!is_array($v) && !is_object($v)) {
|
||||
if ($type['type'] == "image" && is_numeric($type["value"])) {
|
||||
$thumbnail_meta = wp_get_attachment_metadata($type["value"]);
|
||||
$src = wp_get_attachment_image_src($v, $thumbnail_meta['file']);
|
||||
$v = $src[0];
|
||||
}
|
||||
$record[$k] = $v;
|
||||
} else if (!is_object($v)) {
|
||||
if (isset($v['url'])) {
|
||||
$record[$k] = $v['url'];
|
||||
} else if (is_array($v)) {
|
||||
foreach ($v as $v_v => $k_k) {
|
||||
if (is_array($k_k) && isset($k_k['url'])) {
|
||||
$record[$k . $v_v] = $k_k['url'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($type['type'] == "image" && (is_numeric($type["value"]) || is_array($type['value']))) {
|
||||
if (is_array($type['value'])) {
|
||||
$sizes = self::getImageSizes($type["value"]["id"], $type["value"]["sizes"], $k);
|
||||
} else {
|
||||
$thumbnail_meta = wp_get_attachment_metadata($type["value"]);
|
||||
$sizes = self::getImageSizes($type["value"], $thumbnail_meta['sizes'], $k);
|
||||
}
|
||||
$record = array_merge($record, $sizes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public static function getACFType($key, $post_id) {
|
||||
$type = get_field_object($key, $post_id);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
public static function getImageSizes($thumbnail_id, $sizes, $prefix = false) {
|
||||
$data = array();
|
||||
if (!$prefix) {
|
||||
$prefix = "";
|
||||
} else {
|
||||
$prefix = $prefix . "_";
|
||||
}
|
||||
foreach ($sizes as $size => $image) {
|
||||
$imageSrc = wp_get_attachment_image_src($thumbnail_id, $size);
|
||||
$data[$prefix . 'image_' . self::clearSizeName($size)] = $imageSrc[0];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function clearSizeName($size) {
|
||||
return preg_replace("/-/", "_", $size);
|
||||
}
|
||||
|
||||
public static function removeShortcodes($variable) {
|
||||
return preg_replace('#\[[^\]]+\]#', '', $variable);
|
||||
}
|
||||
|
||||
public static function getCategoryData($postID) {
|
||||
$record = array();
|
||||
$category = get_the_category($postID);
|
||||
if (isset($category[0])) {
|
||||
$record['category_name'] = $category[0]->name;
|
||||
$record['category_link'] = get_category_link($category[0]->cat_ID);
|
||||
$record['category_slug'] = $category[0]->slug;
|
||||
} else {
|
||||
$record['category_name'] = '';
|
||||
$record['category_link'] = '';
|
||||
$record['category_slug'] = '';
|
||||
}
|
||||
$j = 0;
|
||||
if (is_array($category) && count($category) > 1) {
|
||||
foreach ($category as $cat) {
|
||||
$record['category_name_' . $j] = $cat->name;
|
||||
$record['category_link_' . $j] = get_category_link($cat->cat_ID);
|
||||
$record['category_slug_' . $j] = $cat->slug;
|
||||
$j++;
|
||||
}
|
||||
} else {
|
||||
$record['category_name_0'] = $record['category_name'];
|
||||
$record['category_link_0'] = $record['category_link'];
|
||||
$record['category_slug_0'] = $record['category_slug'];
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Sources;
|
||||
|
||||
use Nextend\Framework\Form\Container\ContainerTable;
|
||||
use Nextend\Framework\Form\Element\MixedField\GeneratorOrder;
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
use Nextend\Framework\Form\Element\Select\Filter;
|
||||
use Nextend\Framework\Form\Element\Text;
|
||||
use Nextend\Framework\Form\Element\Textarea;
|
||||
use Nextend\Framework\Parser\Common;
|
||||
use Nextend\SmartSlider3\Generator\AbstractGenerator;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsAllTaxonomies;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsMetaKeys;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsPostTypes;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\GeneratorGroupPosts;
|
@ -0,0 +1,571 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Sources;
|
||||
|
||||
use Nextend\Framework\Form\Container\ContainerTable;
|
||||
use Nextend\Framework\Form\Element\MixedField\GeneratorOrder;
|
||||
use Nextend\Framework\Form\Element\OnOff;
|
||||
use Nextend\Framework\Form\Element\Radio;
|
||||
use Nextend\Framework\Form\Element\Select;
|
||||
use Nextend\Framework\Form\Element\Text;
|
||||
use Nextend\Framework\Form\Element\Textarea;
|
||||
use Nextend\Framework\Parser\Common;
|
||||
use Nextend\SmartSlider3\Generator\AbstractGenerator;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsCustomFields;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsOptions;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsTaxonomies;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\GeneratorGroupPosts;
|
||||
|
||||
class PostsCustomPosts extends AbstractGenerator {
|
||||
|
||||
protected $layout = 'article';
|
||||
|
||||
protected $postType;
|
||||
|
||||
public function __construct($group, $name, $post_type, $label) {
|
||||
$this->postType = $post_type;
|
||||
parent::__construct($group, $name, $label);
|
||||
}
|
||||
|
||||
public function getPostType() {
|
||||
return $this->postType;
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return sprintf(n2_('Creates slides from the following post type: %1$s.'), $this->postType);
|
||||
}
|
||||
|
||||
private function checkKeywords($variable) {
|
||||
switch ($variable) {
|
||||
case 'current_date':
|
||||
$variable = current_time('mysql');
|
||||
break;
|
||||
case 'current_date_timestamp':
|
||||
$variable = current_time('timestamp');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return $variable;
|
||||
}
|
||||
|
||||
|
||||
public function renderFields($container) {
|
||||
$filterGroup = new ContainerTable($container, 'filter-group', n2_('Filter'));
|
||||
$filter = $filterGroup->createRow('filter');
|
||||
new PostsTaxonomies($filter, 'taxonomies', n2_('Taxonomies'), 0, array(
|
||||
'postType' => $this->postType,
|
||||
'postSeparator' => '|*|'
|
||||
));
|
||||
|
||||
new Select($filter, 'taxonomies_relation', n2_('Relation'), 'OR', array(
|
||||
'options' => array(
|
||||
'OR' => 'OR',
|
||||
'AND' => 'AND'
|
||||
)
|
||||
));
|
||||
|
||||
$ids = $filterGroup->createRow('ids');
|
||||
new Textarea($ids, 'ids', n2_('Post IDs to display'), '', array(
|
||||
'width' => 150,
|
||||
'height' => 150,
|
||||
'tipLabel' => n2_('Post IDs to display'),
|
||||
'tipDescription' => sprintf(n2_('You can make your generator display only the posts with the set ID. No other post will be fetched, even if they match the set filters. %1$s Write one ID per line.'), '<br>')
|
||||
));
|
||||
|
||||
new Textarea($ids, 'exclude_ids', n2_('Exclude posts'), '', array(
|
||||
'width' => 150,
|
||||
'height' => 150,
|
||||
'tipLabel' => n2_('Exclude posts'),
|
||||
'tipDescription' => sprintf(n2_('The selected post IDs won\'t appear in the generator, even if they they match the set filters. %1$s Write one ID per line.'), '<br>')
|
||||
));
|
||||
|
||||
$status = $filterGroup->createRow('status');
|
||||
$statuses = get_post_stati();
|
||||
$statuses += array(
|
||||
'any' => 'any',
|
||||
'unset' => 'unset',
|
||||
);
|
||||
new Select($status, 'poststatus', n2_('Post status'), 'publish', array(
|
||||
'options' => $statuses
|
||||
));
|
||||
|
||||
$postMetaGroup = $filterGroup->createRowGroup('postmetaGroup', n2_('Post meta comparison'));
|
||||
$postMeta = $postMetaGroup->createRow('postmeta');
|
||||
new PostsCustomFields($postMeta, 'postmetakey', n2_('Field name'), 0, array(
|
||||
'postType' => $this->postType,
|
||||
'tipLabel' => n2_('Field name'),
|
||||
'tipDescription' => n2_('Only show posts, where the given meta key is equal to the given meta value.'),
|
||||
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1900-wordpress-custom-posts-generator#post-meta-comparison'
|
||||
));
|
||||
|
||||
new Select($postMeta, 'postmetacompare', n2_('Compare method'), '=', array(
|
||||
'options' => array(
|
||||
'=' => '=',
|
||||
'!=' => '!=',
|
||||
'>' => '>',
|
||||
'>=' => '>=',
|
||||
'<' => '<',
|
||||
'<=' => '<=',
|
||||
'LIKE' => 'LIKE',
|
||||
'NOT LIKE' => 'NOT LIKE',
|
||||
'IN' => 'IN',
|
||||
'NOT IN' => 'NOT IN',
|
||||
'BETWEEN' => 'BETWEEN',
|
||||
'NOT BETWEEN' => 'NOT BETWEEN',
|
||||
'REGEXP' => 'REGEXP',
|
||||
'NOT REGEXP' => 'NOT REGEXP',
|
||||
'RLIKE' => 'RLIKE',
|
||||
'EXISTS' => 'EXISTS',
|
||||
'NOT EXISTS' => 'NOT EXISTS'
|
||||
)
|
||||
));
|
||||
|
||||
new Text($postMeta, 'postmetavalue', n2_('Field value'));
|
||||
|
||||
new Select($postMeta, 'postmetatype', n2_('Field type'), 'CHAR', array(
|
||||
'options' => array(
|
||||
'CHAR' => 'CHAR',
|
||||
'NUMERIC' => 'NUMERIC',
|
||||
'DATE' => 'DATE',
|
||||
'DATETIME' => 'DATETIME',
|
||||
'TIME' => 'TIME',
|
||||
'BINARY' => 'BINARY',
|
||||
'DECIMAL' => 'DECIMAL',
|
||||
'SIGNED' => 'SIGNED',
|
||||
'UNSIGNED' => 'UNSIGNED'
|
||||
)
|
||||
));
|
||||
|
||||
$postMetaMore = $filterGroup->createRow('postmeta-more');
|
||||
new Textarea($postMetaMore, 'postmetakeymore', n2_('Meta comparison'), '', array(
|
||||
'tipLabel' => n2_('Meta comparison'),
|
||||
'tipDescription' => sprintf(n2_('You can create other comparisons based on the previous "Post Meta Comparison" options. Use the following format: name||compare||value||type%1$s%1$s Example:%1$spublished||=||yes||CHAR%1$s%1$sWrite one comparison per line.'), '<br>'),
|
||||
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1900-wordpress-custom-posts-generator#post-meta-comparison',
|
||||
'width' => 300,
|
||||
'height' => 100
|
||||
));
|
||||
|
||||
|
||||
$option = $filterGroup->createRow('option');
|
||||
new PostsOptions($option, 'postoption', n2_('Post option'), '0', array(
|
||||
'tipLabel' => n2_('Post option'),
|
||||
'tipDescription' => n2_('Posts can have options, like a post can be "sticky" or not. You can choose to only display posts, which are selected to be IN or NOT IN this option.')
|
||||
));
|
||||
|
||||
new Select($option, 'postoptionin', n2_('Post relationship with selected option'), '0', array(
|
||||
'options' => array(
|
||||
0 => 'IN',
|
||||
1 => 'NOT IN'
|
||||
)
|
||||
));
|
||||
|
||||
$dateGroup = $filterGroup->createRowGroup('dateGroup', n2_('Date configuration'));
|
||||
$date = $filterGroup->createRow('date');
|
||||
new OnOff($date, 'identifydatetime', n2_('Identify datetime'), 0, array(
|
||||
'tipLabel' => n2_('Identify datetime'),
|
||||
'tipDescription' => n2_('Our system tries to identify the date and time in your variables.')
|
||||
));
|
||||
new Text($date, 'datetimeformat', n2_('Datetime format'), 'm-d-Y H:i:s', array(
|
||||
'tipLabel' => n2_('Datetime format'),
|
||||
'tipDescription' => sprintf(n2_('You can use any %1$sPHP date format%2$s.'), '<a href="http://php.net/manual/en/function.date.php">', '</a>')
|
||||
));
|
||||
new Textarea($date, 'translatedate', n2_('Translate dates'), "from||to\nMonday||Monday\njan||jan", array(
|
||||
'tipLabel' => n2_('Translate dates'),
|
||||
'tipDescription' => sprintf(n2_('Write one per line in the following format: from||to %1$s E.g.: Monday||Montag'), '<br>'),
|
||||
'width' => 300,
|
||||
'height' => 200
|
||||
));
|
||||
|
||||
$replaceGroup = $filterGroup->createRowGroup('replaceGroup', n2_('Replace variables'));
|
||||
$variables = $filterGroup->createRow('variables');
|
||||
new Text($variables, 'timestampvariables', n2_('Timestamp variables'), '', array(
|
||||
'tipLabel' => n2_('Replace timestamp variables'),
|
||||
'tipDescription' => sprintf(n2_('The "Datetime format" will be used to create dates from the given timestamp containing variables. %1$s Separate them with comma.'), '<br>')
|
||||
));
|
||||
|
||||
new Text($variables, 'filevariables', n2_('File variables'), '', array(
|
||||
'tipLabel' => n2_('Replace file variables'),
|
||||
'tipDescription' => sprintf(n2_('If you have IDs of files, you can replace those variables with the urls of the files instead. %1$s Separate them with comma.'), '<br>')
|
||||
));
|
||||
|
||||
new Text($variables, 'uniquevariable', n2_('Remove duplicate results'), '', array(
|
||||
'tipLabel' => n2_('Remove duplicate results'),
|
||||
'tipDescription' => n2_('You can remove results based on one variable\'s uniqueness. For example if you want the images to be unique, you could write the "image" variable into this field (without quotemarks).')
|
||||
));
|
||||
|
||||
$orderGroup = new ContainerTable($container, 'order-group', n2_('Order'));
|
||||
$order = $orderGroup->createRow('order');
|
||||
new GeneratorOrder($order, 'postsorder', 'post_date|*|desc', array(
|
||||
'options' => array(
|
||||
'none' => n2_('None'),
|
||||
'post_date' => n2_('Post date'),
|
||||
'ID' => 'ID',
|
||||
'title' => n2_('Title'),
|
||||
'post_modified' => n2_('Modification date'),
|
||||
'rand' => n2_('Random'),
|
||||
'post__in' => n2_('Given IDs'),
|
||||
'menu_order' => n2_('Menu order')
|
||||
)
|
||||
));
|
||||
|
||||
$metaOrder = $orderGroup->createRow('meta-order');
|
||||
new PostsCustomFields($metaOrder, 'meta_order_key', n2_('Custom field name'), 0, array(
|
||||
'tipLabel' => n2_('Custom field name'),
|
||||
'tipDescription' => n2_('If it\'s set, this will be used instead of the \'Field\' value.'),
|
||||
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1900-wordpress-custom-posts-generator#custom-field-name',
|
||||
'postType' => $this->postType
|
||||
));
|
||||
|
||||
new Radio($metaOrder, 'meta_orderby', n2_('Order'), 'meta_value_num', array(
|
||||
'options' => array(
|
||||
'meta_value_num' => n2_('Numeric'),
|
||||
'meta_value' => n2_('Alphabetic')
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
protected function _getData($count, $startIndex) {
|
||||
global $post, $wp_query;
|
||||
$tmpPost = $post;
|
||||
|
||||
$identifyDateTime = $this->data->get('identifydatetime', 0);
|
||||
|
||||
if (has_filter('the_content', 'siteorigin_panels_filter_content')) {
|
||||
$siteorigin_panels_filter_content = true;
|
||||
remove_filter('the_content', 'siteorigin_panels_filter_content');
|
||||
} else {
|
||||
$siteorigin_panels_filter_content = false;
|
||||
}
|
||||
|
||||
$taxonomies = array_diff(explode('||', $this->data->get('taxonomies', '')), array(
|
||||
'',
|
||||
0
|
||||
));
|
||||
|
||||
if (count($taxonomies)) {
|
||||
$tax_array = array();
|
||||
foreach ($taxonomies as $tax) {
|
||||
$parts = explode('|*|', $tax);
|
||||
if (!is_array(@$tax_array[$parts[0]]) || !in_array($parts[1], $tax_array[$parts[0]])) {
|
||||
$tax_array[$parts[0]][] = $parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
$tax_query = array();
|
||||
foreach ($tax_array as $taxonomy => $terms) {
|
||||
$tax_query[] = array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'terms' => $terms,
|
||||
'field' => 'id'
|
||||
);
|
||||
}
|
||||
$tax_query['relation'] = $this->data->get('taxonomies_relation', 'OR');
|
||||
} else {
|
||||
$tax_query = '';
|
||||
}
|
||||
|
||||
list($orderBy, $order) = Common::parse($this->data->get('postsorder', 'post_date|*|desc'));
|
||||
|
||||
$compare = array();
|
||||
$compare_value = $this->data->get('postmetacompare', '');
|
||||
if (!empty($compare_value)) {
|
||||
$compare = array('compare' => $compare_value);
|
||||
}
|
||||
|
||||
$postMetaKey = $this->data->get('postmetakey', '0');
|
||||
if (!empty($postMetaKey)) {
|
||||
$postMetaValue = $this->data->get('postmetavalue', '');
|
||||
$postMetaValue = $this->checkKeywords($postMetaValue);
|
||||
$getPostMeta = array(
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => $postMetaKey,
|
||||
'type' => $this->data->get('postmetatype', 'CHAR')
|
||||
) + $compare
|
||||
)
|
||||
);
|
||||
|
||||
if ($compare_value != 'EXISTS' && $compare_value != 'NOT EXISTS') {
|
||||
$getPostMeta['meta_query'][0]['value'] = $postMetaValue;
|
||||
}
|
||||
} else {
|
||||
$getPostMeta = array();
|
||||
}
|
||||
$metaMore = $this->data->get('postmetakeymore', '');
|
||||
if (!empty($metaMore) && $metaMore != 'field_name||compare_method||field_value') {
|
||||
$metaMoreValues = explode(PHP_EOL, $metaMore);
|
||||
foreach ($metaMoreValues as $metaMoreValue) {
|
||||
$metaMoreValue = trim($metaMoreValue);
|
||||
if ($metaMoreValue != 'field_name||compare_method||field_value') {
|
||||
$metaMoreArray = explode('||', $metaMoreValue);
|
||||
if (count($metaMoreArray) >= 2) {
|
||||
$compare = array('compare' => $metaMoreArray[1]);
|
||||
|
||||
$key_query = array(
|
||||
'key' => $metaMoreArray[0]
|
||||
);
|
||||
|
||||
if (!empty($metaMoreArray[2])) {
|
||||
$key_query += array(
|
||||
'value' => $this->checkKeywords($metaMoreArray[2])
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($metaMoreArray[3])) {
|
||||
$key_query += array(
|
||||
'type' => $metaMoreArray[3]
|
||||
);
|
||||
}
|
||||
|
||||
$getPostMeta['meta_query'][] = $key_query + $compare;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post_status = explode(",", $this->data->get('poststatus', 'publish'));
|
||||
|
||||
$meta_order_key = $this->data->get('meta_order_key');
|
||||
$meta_key = '';
|
||||
if (!empty($meta_order_key)) {
|
||||
$orderBy = $this->data->get('meta_orderby', 'meta_value_num');
|
||||
$meta_key = $meta_order_key;
|
||||
}
|
||||
|
||||
$getPosts = array(
|
||||
'include' => '',
|
||||
'exclude' => '',
|
||||
'meta_key' => $meta_key,
|
||||
'meta_value' => '',
|
||||
'post_type' => $this->postType,
|
||||
'post_mime_type' => '',
|
||||
'post_parent' => '',
|
||||
'post_status' => $post_status,
|
||||
'suppress_filters' => false,
|
||||
'offset' => $startIndex,
|
||||
'posts_per_page' => $count,
|
||||
'tax_query' => $tax_query
|
||||
);
|
||||
|
||||
if ($orderBy != 'none') {
|
||||
$getPosts += array(
|
||||
'orderby' => $orderBy,
|
||||
'order' => $order,
|
||||
'ignore_custom_sort' => true
|
||||
);
|
||||
}
|
||||
|
||||
$getPosts = array_merge($getPosts, $getPostMeta);
|
||||
|
||||
$ids = array_diff($this->getIDs(), array(0));
|
||||
|
||||
if (count($ids) > 0) {
|
||||
$getPosts += array(
|
||||
'post__in' => $ids
|
||||
);
|
||||
}
|
||||
|
||||
$exclude_ids = array_diff($this->getIDs('exclude_ids'), array(0));
|
||||
|
||||
if (count($exclude_ids) > 0) {
|
||||
$getPosts += array(
|
||||
'post__not_in' => $exclude_ids
|
||||
);
|
||||
}
|
||||
|
||||
$post_option = $this->data->get('postoption', 0);
|
||||
if (!empty($post_option)) {
|
||||
$post_option_in = $this->data->get('postoptionin', 0);
|
||||
switch ($post_option_in) {
|
||||
case 0:
|
||||
$getPosts += array(
|
||||
'post__in' => get_option($post_option)
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
$getPosts += array(
|
||||
'post__not_in' => get_option($post_option)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$posts = get_posts($getPosts);
|
||||
|
||||
$data = array();
|
||||
|
||||
$timestampVariables = array_map('trim', explode(',', $this->data->get('timestampvariables', '')));
|
||||
$fileVariables = array_map('trim', explode(',', $this->data->get('filevariables', '')));
|
||||
$datetimeformat = $this->data->get('datetimeformat', 'm-d-Y H:i:s');
|
||||
|
||||
for ($i = 0; $i < count($posts); $i++) {
|
||||
$record = array();
|
||||
|
||||
$post = $posts[$i];
|
||||
setup_postdata($post);
|
||||
$wp_query->post = $post;
|
||||
|
||||
$record['id'] = $post->ID;
|
||||
|
||||
$record['url'] = get_permalink();
|
||||
$record['title'] = apply_filters('the_title', get_the_title(), $post->ID);
|
||||
$record['content'] = get_the_content();
|
||||
$record['description'] = GeneratorGroupPosts::removeShortcodes($record['content']);
|
||||
$record['author_name'] = $record['author'] = get_the_author();
|
||||
$userID = get_the_author_meta('ID');
|
||||
$record['author_url'] = get_author_posts_url($userID);
|
||||
$record['author_avatar'] = get_avatar_url($userID);
|
||||
|
||||
if ($identifyDateTime) {
|
||||
$record['date'] = get_the_date('Y-m-d H:i:s');
|
||||
$record['modified'] = get_the_modified_date('Y-m-d H:i:s');
|
||||
} else {
|
||||
$record['date'] = get_the_date();
|
||||
$record['modified'] = get_the_modified_date();
|
||||
}
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id($post->ID);
|
||||
$record['featured_image'] = wp_get_attachment_image_url($thumbnail_id, 'full');
|
||||
if (!$record['featured_image']) {
|
||||
$record['featured_image'] = '';
|
||||
} else {
|
||||
$thumbnail_meta = get_post_meta($thumbnail_id, '_wp_attachment_metadata', true);
|
||||
if (isset($thumbnail_meta['sizes'])) {
|
||||
$sizes = GeneratorGroupPosts::getImageSizes($thumbnail_id, $thumbnail_meta['sizes']);
|
||||
$record = array_merge($record, $sizes);
|
||||
}
|
||||
$record['alt'] = '';
|
||||
$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
|
||||
if (isset($alt)) {
|
||||
$record['alt'] = $alt;
|
||||
}
|
||||
}
|
||||
|
||||
$record['thumbnail'] = $record['image'] = $record['featured_image'];
|
||||
$record['url_label'] = 'View';
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::extractPostMeta(get_post_meta($post->ID)));
|
||||
|
||||
$taxonomies = get_post_taxonomies($post->ID);
|
||||
$args = array(
|
||||
'orderby' => 'parent',
|
||||
'order' => 'ASC',
|
||||
'fields' => 'all'
|
||||
);
|
||||
|
||||
foreach ($taxonomies as $taxonomy) {
|
||||
$post_terms = wp_get_object_terms($post->ID, $taxonomy, $args);
|
||||
$taxonomy = str_replace('-', '', $taxonomy);
|
||||
|
||||
for ($j = 0; $j < count($post_terms); $j++) {
|
||||
$record[$taxonomy . '_' . ($j + 1)] = $post_terms[$j]->name;
|
||||
$record[$taxonomy . '_' . ($j + 1) . '_ID'] = $post_terms[$j]->term_id;
|
||||
$record[$taxonomy . '_' . ($j + 1) . '_description'] = $post_terms[$j]->description;
|
||||
}
|
||||
}
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::getACFData($post->ID));
|
||||
|
||||
if (isset($record['primarytermcategory'])) {
|
||||
$primary = get_category($record['primarytermcategory']);
|
||||
$record['primary_category_name'] = $primary->name;
|
||||
$record['primary_category_link'] = get_category_link($primary->cat_ID);
|
||||
}
|
||||
$record['excerpt'] = get_the_excerpt();
|
||||
|
||||
if (!empty($timestampVariables)) {
|
||||
foreach ($timestampVariables as $timestampVariable) {
|
||||
if (isset($record[$timestampVariable])) {
|
||||
$record[$timestampVariable] = date($datetimeformat, intval($record[$timestampVariable]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fileVariables)) {
|
||||
foreach ($fileVariables as $fileVariable) {
|
||||
if (isset($record[$fileVariable])) {
|
||||
$record[$fileVariable] = wp_get_attachment_url($record[$fileVariable]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$record = apply_filters('smartslider3_posts_customposts_data', $record);
|
||||
|
||||
$data[$i] = &$record;
|
||||
unset($record);
|
||||
}
|
||||
|
||||
$unique_variable = $this->data->get('uniquevariable', '');
|
||||
if (!empty($unique_variable)) {
|
||||
$count = count($data);
|
||||
$unique_helper = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (!in_array($data[$i][$unique_variable], $unique_helper)) {
|
||||
$unique_helper[] = $data[$i][$unique_variable];
|
||||
} else {
|
||||
unset($data[$i]);
|
||||
}
|
||||
}
|
||||
$data = array_values($data);
|
||||
}
|
||||
|
||||
if ($siteorigin_panels_filter_content) {
|
||||
add_filter('the_content', 'siteorigin_panels_filter_content');
|
||||
}
|
||||
|
||||
$wp_query->post = $tmpPost;
|
||||
wp_reset_postdata();
|
||||
|
||||
if ($identifyDateTime) {
|
||||
$translate_dates = $this->data->get('translatedate', '');
|
||||
$translateValue = explode(PHP_EOL, $translate_dates);
|
||||
$translate = array();
|
||||
if (!empty($translateValue)) {
|
||||
foreach ($translateValue as $tv) {
|
||||
$translateArray = explode('||', $tv);
|
||||
if (!empty($translateArray) && count($translateArray) == 2) {
|
||||
$translate[$translateArray[0]] = $translateArray[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
foreach ($data[$i] as $key => $value) {
|
||||
if ($this->isDate($value)) {
|
||||
$data[$i][$key] = $this->translate($this->formatDate($value, $datetimeformat), $translate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function isDate($value) {
|
||||
if (!$value) {
|
||||
return false;
|
||||
} else {
|
||||
$date = date_parse($value);
|
||||
if ($date['error_count'] == 0 && $date['warning_count'] == 0) {
|
||||
return checkdate($date['month'], $date['day'], $date['year']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatDate($date, $format) {
|
||||
return date($format, strtotime($date));
|
||||
}
|
||||
|
||||
protected function translate($from, $translate) {
|
||||
if (!empty($translate) && !empty($from)) {
|
||||
foreach ($translate as $key => $value) {
|
||||
$from = str_replace($key, trim($value), $from);
|
||||
}
|
||||
}
|
||||
|
||||
return $from;
|
||||
}
|
||||
}
|
@ -0,0 +1,402 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Sources;
|
||||
|
||||
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\Textarea;
|
||||
use Nextend\Framework\Parser\Common;
|
||||
use Nextend\Framework\Translation\Translation;
|
||||
use Nextend\SmartSlider3\Generator\AbstractGenerator;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsCategories;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsTags;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\Elements\PostsTaxonomies;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\GeneratorGroupPosts;
|
||||
|
||||
class PostsPosts extends AbstractGenerator {
|
||||
|
||||
protected $layout = 'article';
|
||||
|
||||
protected $postType = 'post';
|
||||
|
||||
public function getDescription() {
|
||||
return n2_('Creates slides from your posts in the selected categories.');
|
||||
}
|
||||
|
||||
public function renderFields($container) {
|
||||
$filterGroup = new ContainerTable($container, 'filter-group', n2_('Filter'));
|
||||
$filter = $filterGroup->createRow('filter');
|
||||
|
||||
new PostsCategories($filter, 'postscategory', n2_('Categories'), 0);
|
||||
new PostsTags($filter, 'posttags', n2_('Tags'), 0);
|
||||
new PostsTaxonomies($filter, 'postcustomtaxonomy', n2_('Taxonomies'), 0, array(
|
||||
'postType' => 'post',
|
||||
'skip' => true
|
||||
));
|
||||
|
||||
$posts = $filterGroup->createRow('posts');
|
||||
new Filter($posts, 'poststicky', n2_('Sticky'), 0);
|
||||
new OnOff($posts, 'postshortcode', n2_('Remove shortcodes'), 1, array(
|
||||
'relatedFieldsOn' => array(
|
||||
'generatorpostshortcodevariables'
|
||||
),
|
||||
'tipLabel' => n2_('Remove shortcodes'),
|
||||
'tipDescription' => n2_('You can remove shortcodes from variables to avoid 3rd party content rendering in your slider.')
|
||||
));
|
||||
new Text($posts, 'postshortcodevariables', n2_('Remove from variables'), 'description, content, excerpt', array(
|
||||
'tipLabel' => n2_('Remove from variables'),
|
||||
'tipDescription' => n2_('Write the name of the variables you want to remove the shortcodes from. Separate new variables with a comma and space. E.g. description, content')
|
||||
));
|
||||
|
||||
$date = $filterGroup->createRow('date');
|
||||
new Textarea($date, 'customdates', n2_('Custom date variables'), "variable||PHP date format\nmodified||Ymd\ndate||F j, Y, g:i a\nstarted||F\nended||D", array(
|
||||
'tipLabel' => n2_('Custom date variables'),
|
||||
'tipDescription' => sprintf(n2_('You can create custom date variables from your existing date variables. Write each variable to a new line and use the following format: variable||format. %3$s The "variable" should be an existing variable. Based on this existing variable, we create a new one with the "_datetime" suffix. (E.g. date_datetime.) %3$s The "format" can be any %1$sPHP date format%2$s.'), '<a href="http://php.net/manual/en/function.date.php" target="_blank">', '</a>', '<br>'),
|
||||
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1891-wordpress---posts-generator',
|
||||
'width' => 300,
|
||||
'height' => 100
|
||||
));
|
||||
|
||||
new Textarea($date, 'translatecustomdates', n2_('Translate custom dates'), "from||to\nMonday||Monday\njan||jan", array(
|
||||
'tipLabel' => n2_('Translate custom dates'),
|
||||
'tipDescription' => sprintf(n2_('You can translate the content of the newly created variables. %1$s Use the following format: from||to. Eg.: Monday||Montag'), '<br>'),
|
||||
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1891-wordpress---posts-generator',
|
||||
'width' => 300,
|
||||
'height' => 100
|
||||
));
|
||||
|
||||
new Select($date, 'datefunction', n2_('Date function'), 'date_i18n', array(
|
||||
'tipLabel' => n2_('Date function'),
|
||||
'tipDescription' => n2_('This function will be used to format these custom date variables. Usually the date_i18n works, but if your date will be off a little bit, then try out the other one.'),
|
||||
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1891-wordpress---posts-generator',
|
||||
'options' => array(
|
||||
'date_i18n' => 'date_i18n',
|
||||
'date' => 'date'
|
||||
)
|
||||
));
|
||||
|
||||
$orderGroup = new ContainerTable($container, 'order-group', n2_('Order'));
|
||||
$order = $orderGroup->createRow('order');
|
||||
new GeneratorOrder($order, 'postscategoryorder', 'post_date|*|desc', array(
|
||||
'options' => array(
|
||||
'none' => n2_('None'),
|
||||
'post_date' => n2_('Post date'),
|
||||
'ID' => 'ID',
|
||||
'title' => n2_('Title'),
|
||||
'post_modified' => n2_('Modification date'),
|
||||
'rand' => n2_('Random'),
|
||||
'comment_count' => n2_('Comment count'),
|
||||
'menu_order' => n2_('Menu order')
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
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 linesToArray($lines) {
|
||||
$value = preg_split('/$\R?^/m', $lines);
|
||||
$data = array();
|
||||
if (!empty($value)) {
|
||||
foreach ($value as $v) {
|
||||
$array = explode('||', $v);
|
||||
if (!empty($array) && count($array) == 2) {
|
||||
$data[$array[0]] = trim($array[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function isTimeStamp($timestamp) {
|
||||
return ((string)(int)$timestamp === $timestamp) && ($timestamp <= PHP_INT_MAX) && ($timestamp >= ~PHP_INT_MAX);
|
||||
}
|
||||
|
||||
public function getPostType() {
|
||||
return $this->postType;
|
||||
}
|
||||
|
||||
public function filterName($name) {
|
||||
return $name . Translation::getCurrentLocale();
|
||||
}
|
||||
|
||||
function get_string_between($str, $startDelimiter, $endDelimiter) {
|
||||
$contents = array();
|
||||
$startDelimiterLength = strlen($startDelimiter);
|
||||
$endDelimiterLength = strlen($endDelimiter);
|
||||
$startFrom = $contentStart = $contentEnd = 0;
|
||||
while (false !== ($contentStart = strpos($str, $startDelimiter, $startFrom))) {
|
||||
$contentStart += $startDelimiterLength;
|
||||
$contentEnd = strpos($str, $endDelimiter, $contentStart);
|
||||
if (false === $contentEnd) {
|
||||
break;
|
||||
}
|
||||
$contents[] = substr($str, $contentStart, $contentEnd - $contentStart);
|
||||
$startFrom = $contentEnd + $endDelimiterLength;
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
protected function _getData($count, $startIndex) {
|
||||
global $post, $wp_query;
|
||||
$tmpPost = $post;
|
||||
|
||||
list($orderBy, $order) = Common::parse($this->data->get('postscategoryorder', 'post_date|*|desc'));
|
||||
|
||||
$allTags = $this->data->get('posttags', '');
|
||||
$tax_query = '';
|
||||
if (!empty($allTags)) {
|
||||
$tags = explode('||', $allTags);
|
||||
if (!in_array('0', $tags)) {
|
||||
$tax_query = array(
|
||||
array(
|
||||
'taxonomy' => 'post_tag',
|
||||
'terms' => $tags,
|
||||
'field' => 'id'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$allTerms = $this->data->get('postcustomtaxonomy', '');
|
||||
if (!empty($allTerms)) {
|
||||
$terms = explode('||', $allTerms);
|
||||
if (!in_array('0', $terms)) {
|
||||
$termarray = array();
|
||||
foreach ($terms as $key => $value) {
|
||||
$term = explode("_x_", $value);
|
||||
if (array_key_exists($term[0], $termarray)) {
|
||||
$termarray[$term[0]][] = $term[1];
|
||||
} else {
|
||||
$termarray[$term[0]] = array();
|
||||
$termarray[$term[0]][] = $term[1];
|
||||
}
|
||||
}
|
||||
|
||||
$term_helper = array();
|
||||
foreach ($termarray as $taxonomy => $termids) {
|
||||
$term_helper[] = array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'terms' => $termids,
|
||||
'field' => 'id'
|
||||
);
|
||||
}
|
||||
if (!empty($tax_query)) {
|
||||
array_unshift($tax_query, array('relation' => 'AND'));
|
||||
} else {
|
||||
$tax_query = array('relation' => 'AND');
|
||||
}
|
||||
$tax_query = array_merge($tax_query, $term_helper);
|
||||
}
|
||||
}
|
||||
|
||||
$postsFilter = array(
|
||||
'include' => '',
|
||||
'exclude' => '',
|
||||
'meta_key' => '',
|
||||
'meta_value' => '',
|
||||
'post_type' => 'post',
|
||||
'post_mime_type' => '',
|
||||
'post_parent' => '',
|
||||
'post_status' => 'publish',
|
||||
'suppress_filters' => false,
|
||||
'offset' => $startIndex,
|
||||
'posts_per_page' => $count,
|
||||
'tax_query' => $tax_query
|
||||
);
|
||||
|
||||
if ($orderBy != 'none') {
|
||||
$postsFilter += array(
|
||||
'orderby' => $orderBy,
|
||||
'order' => $order,
|
||||
'ignore_custom_sort' => true
|
||||
);
|
||||
}
|
||||
|
||||
$categories = (array)Common::parse($this->data->get('postscategory'));
|
||||
if (!in_array(0, $categories)) {
|
||||
$postsFilter['category'] = implode(',', $categories);
|
||||
}
|
||||
|
||||
$poststicky = $this->data->get('poststicky');
|
||||
switch ($poststicky) {
|
||||
case 1:
|
||||
$postsFilter += array(
|
||||
'post__in' => get_option('sticky_posts')
|
||||
);
|
||||
break;
|
||||
case -1:
|
||||
$postsFilter += array(
|
||||
'post__not_in' => get_option('sticky_posts')
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_filter('the_content', 'siteorigin_panels_filter_content')) {
|
||||
$siteorigin_panels_filter_content = true;
|
||||
remove_filter('the_content', 'siteorigin_panels_filter_content');
|
||||
} else {
|
||||
$siteorigin_panels_filter_content = false;
|
||||
}
|
||||
|
||||
$posts = get_posts($postsFilter);
|
||||
|
||||
$custom_dates = $this->linesToArray($this->data->get('customdates', ''));
|
||||
$translate = $this->linesToArray($this->data->get('translatecustomdates', ''));
|
||||
$date_function = $this->data->get('datefunction', 'date_i18n');
|
||||
|
||||
if ($this->data->get('postshortcode', 1)) {
|
||||
$remove_shortcode = array_map('trim', explode(',', $this->data->get('postshortcodevariables', 'description, content, excerpt')));
|
||||
} else {
|
||||
$remove_shortcode = null;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
for ($i = 0; $i < count($posts); $i++) {
|
||||
$record = array();
|
||||
|
||||
$post = $posts[$i];
|
||||
setup_postdata($post);
|
||||
$wp_query->post = $post;
|
||||
|
||||
$record['id'] = $post->ID;
|
||||
$record['url'] = get_permalink();
|
||||
$record['title'] = apply_filters('the_title', get_the_title(), $post->ID);
|
||||
$record['content'] = get_the_content();
|
||||
$record['description'] = $record['content'];
|
||||
if (class_exists('ET_Builder_Plugin')) {
|
||||
if (strpos($record['description'], 'et_pb_slide background_image') !== false) {
|
||||
$et_slides = $this->get_string_between($record['description'], 'et_pb_slide background_image="', '"');
|
||||
for ($j = 0; $j < count($et_slides); $j++) {
|
||||
$record['et_slide' . $j] = $et_slides[$j];
|
||||
}
|
||||
}
|
||||
if (strpos($record['description'], 'background_url') !== false) {
|
||||
$et_backgrounds = $this->get_string_between($record['description'], 'background_url="', '"');
|
||||
for ($j = 0; $j < count($et_backgrounds); $j++) {
|
||||
$record['et_background' . $j] = $et_backgrounds[$j];
|
||||
}
|
||||
}
|
||||
if (strpos($record['description'], 'logo_image_url') !== false) {
|
||||
$et_logoImages = $this->get_string_between($record['description'], 'logo_image_url="', '"');
|
||||
for ($j = 0; $j < count($et_logoImages); $j++) {
|
||||
$record['et_logoImage' . $j] = $et_logoImages[$j];
|
||||
}
|
||||
}
|
||||
if (strpos($record['description'], 'slider-content') !== false) {
|
||||
$et_contents = $this->get_string_between($record['description'], 'slider-content">', '</p>');
|
||||
for ($j = 0; $j < count($et_contents); $j++) {
|
||||
$record['et_content' . $j] = $et_contents[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$record['slug'] = $post->post_name;
|
||||
$record['author_name'] = $record['author'] = get_the_author();
|
||||
$userID = get_the_author_meta('ID');
|
||||
$record['author_url'] = get_author_posts_url($userID);
|
||||
$record['author_avatar'] = get_avatar_url($userID);
|
||||
$record['date'] = get_the_date('Y-m-d H:i:s');
|
||||
$record['modified'] = get_the_modified_date('Y-m-d H:i:s');
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::getCategoryData($post->ID));
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id($post->ID);
|
||||
$record['featured_image'] = wp_get_attachment_image_url($thumbnail_id, 'full');
|
||||
if (!$record['featured_image']) {
|
||||
$record['featured_image'] = '';
|
||||
} else {
|
||||
$thumbnail_meta = get_post_meta($thumbnail_id, '_wp_attachment_metadata', true);
|
||||
if (isset($thumbnail_meta['sizes'])) {
|
||||
$sizes = GeneratorGroupPosts::getImageSizes($thumbnail_id, $thumbnail_meta['sizes']);
|
||||
$record = array_merge($record, $sizes);
|
||||
}
|
||||
$record['alt'] = '';
|
||||
$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
|
||||
if (isset($alt)) {
|
||||
$record['alt'] = $alt;
|
||||
}
|
||||
}
|
||||
|
||||
$record['thumbnail'] = $record['image'] = $record['featured_image'];
|
||||
$record['url_label'] = 'View post';
|
||||
|
||||
$tags = wp_get_post_tags($post->ID);
|
||||
for ($j = 0; $j < count($tags); $j++) {
|
||||
$record['tag_' . ($j + 1)] = $tags[$j]->name;
|
||||
}
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::getACFData($post->ID));
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::extractPostMeta(get_post_meta($post->ID)));
|
||||
|
||||
if (isset($record['primarytermcategory'])) {
|
||||
$primary = get_category($record['primarytermcategory']);
|
||||
$record['primary_category_name'] = $primary->name;
|
||||
$record['primary_category_link'] = get_category_link($primary->cat_ID);
|
||||
}
|
||||
$record['excerpt'] = get_the_excerpt();
|
||||
$record['comment_count'] = $post->comment_count;
|
||||
$record['guid'] = $post->guid;
|
||||
|
||||
if (!empty($custom_dates)) {
|
||||
foreach ($custom_dates as $custom_date_key => $custom_date_format) {
|
||||
if (array_key_exists($custom_date_key, $record)) {
|
||||
if ($this->isTimeStamp($record[$custom_date_key])) {
|
||||
$date = $record[$custom_date_key];
|
||||
} else {
|
||||
$date = strtotime($record[$custom_date_key]);
|
||||
}
|
||||
|
||||
if ($date_function == 'date_i18n') {
|
||||
$record[$custom_date_key . '_datetime'] = $this->translate(date_i18n($custom_date_format, $date), $translate);
|
||||
} else {
|
||||
$record[$custom_date_key . '_datetime'] = $this->translate(date($custom_date_format, $date), $translate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We used 'Y-m-d H:i:s' date format, so we can get the hour, minute and second for custom date variables.
|
||||
* but we need to set the date and modified variables back to the WordPress default date_format.
|
||||
*/
|
||||
$record['date'] = get_the_date();
|
||||
$record['modified'] = get_the_modified_date();
|
||||
|
||||
if (!empty($remove_shortcode)) {
|
||||
foreach ($remove_shortcode as $variable) {
|
||||
if (isset($record[$variable])) {
|
||||
$record[$variable] = GeneratorGroupPosts::removeShortcodes($record[$variable]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$record = apply_filters('smartslider3_posts_posts_data', $record);
|
||||
|
||||
$data[$i] = &$record;
|
||||
unset($record);
|
||||
}
|
||||
|
||||
if ($siteorigin_panels_filter_content) {
|
||||
add_filter('the_content', 'siteorigin_panels_filter_content');
|
||||
}
|
||||
|
||||
$wp_query->post = $tmpPost;
|
||||
wp_reset_postdata();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\SmartSlider3\Generator\WordPress\Posts\Sources;
|
||||
|
||||
use Nextend\Framework\Form\Container\ContainerTable;
|
||||
use Nextend\Framework\Form\Element\Textarea;
|
||||
use Nextend\SmartSlider3\Generator\AbstractGenerator;
|
||||
use Nextend\SmartSlider3\Generator\WordPress\Posts\GeneratorGroupPosts;
|
||||
|
||||
class PostsPostsByIDs extends AbstractGenerator {
|
||||
|
||||
protected $layout = 'article';
|
||||
|
||||
public function getDescription() {
|
||||
return n2_('Creates slides from the posts with the set IDs.');
|
||||
}
|
||||
|
||||
public function renderFields($container) {
|
||||
$filterGroup = new ContainerTable($container, 'filter-group', n2_('Filter'));
|
||||
$filter = $filterGroup->createRow('filter');
|
||||
new Textarea($filter, 'ids', n2_('Post or Page IDs'), '', array(
|
||||
'width' => 280,
|
||||
'height' => 160,
|
||||
'tipLabel' => n2_('Post or Page IDs'),
|
||||
'tipDescription' => sprintf(n2_('You can write the ID of the page you want to show in your generator. %1$s Write one ID per line.'), '<br>')
|
||||
));
|
||||
}
|
||||
|
||||
protected function _getData($count, $startIndex) {
|
||||
global $post, $wp_query;
|
||||
$tmpPost = $post;
|
||||
|
||||
if (has_filter('the_content', 'siteorigin_panels_filter_content')) {
|
||||
$siteorigin_panels_filter_content = true;
|
||||
remove_filter('the_content', 'siteorigin_panels_filter_content');
|
||||
} else {
|
||||
$siteorigin_panels_filter_content = false;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$data = array();
|
||||
|
||||
foreach ($this->getIDs() as $id) {
|
||||
$record = array();
|
||||
$post = get_post($id);
|
||||
if (!$post) continue;
|
||||
setup_postdata($post);
|
||||
$wp_query->post = $post;
|
||||
|
||||
$record['id'] = $post->ID;
|
||||
$record['url'] = get_permalink();
|
||||
$record['title'] = apply_filters('the_title', get_the_title(), $post->ID);
|
||||
$record['description'] = $record['content'] = GeneratorGroupPosts::removeShortcodes(get_the_content());
|
||||
$record['author_name'] = $record['author'] = get_the_author();
|
||||
$userID = get_the_author_meta('ID');
|
||||
$record['author_url'] = get_author_posts_url($userID);
|
||||
$record['author_avatar'] = get_avatar_url($userID);
|
||||
$record['date'] = get_the_date();
|
||||
$record['modified'] = get_the_modified_date();
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::getCategoryData($post->ID));
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id($post->ID);
|
||||
$record['featured_image'] = wp_get_attachment_image_url($thumbnail_id, 'full');
|
||||
if (!$record['featured_image']) {
|
||||
$record['featured_image'] = '';
|
||||
} else {
|
||||
$thumbnail_meta = get_post_meta($thumbnail_id, '_wp_attachment_metadata', true);
|
||||
if (isset($thumbnail_meta['sizes'])) {
|
||||
$sizes = GeneratorGroupPosts::getImageSizes($thumbnail_id, $thumbnail_meta['sizes']);
|
||||
$record = array_merge($record, $sizes);
|
||||
}
|
||||
$record['alt'] = '';
|
||||
$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
|
||||
if (isset($alt)) {
|
||||
$record['alt'] = $alt;
|
||||
}
|
||||
}
|
||||
|
||||
$record['thumbnail'] = $record['image'] = $record['featured_image'];
|
||||
$record['url_label'] = 'View post';
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::getACFData($post->ID));
|
||||
|
||||
$record = array_merge($record, GeneratorGroupPosts::extractPostMeta(get_post_meta($post->ID)));
|
||||
|
||||
if (isset($record['primarytermcategory'])) {
|
||||
$primary = get_category($record['primarytermcategory']);
|
||||
$record['primary_category_name'] = $primary->name;
|
||||
$record['primary_category_link'] = get_category_link($primary->cat_ID);
|
||||
}
|
||||
$record['excerpt'] = get_the_excerpt();
|
||||
|
||||
$record = apply_filters('smartslider3_posts_postsbyids_data', $record);
|
||||
|
||||
$data[$i] = &$record;
|
||||
unset($record);
|
||||
$i++;
|
||||
}
|
||||
if ($siteorigin_panels_filter_content) {
|
||||
add_filter('the_content', 'siteorigin_panels_filter_content');
|
||||
}
|
||||
|
||||
$wp_query->post = $tmpPost;
|
||||
wp_reset_postdata();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user