first commit

This commit is contained in:
Roman Pyrih
2023-07-24 08:30:51 +02:00
commit c2e100a763
7128 changed files with 1622619 additions and 0 deletions

View File

@@ -0,0 +1,159 @@
<?php
use \BrizyPlaceholders\ContentPlaceholder;
use BrizyPlaceholders\ContextInterface;
use \BrizyPlaceholders\PlaceholderInterface;
abstract class Brizy_Content_Placeholders_Abstract extends Brizy_Admin_Serializable implements PlaceholderInterface
{
const DISPLAY_INLINE = 'inline';
const DISPLAY_BLOCK = 'block';
/**
* @return string
*/
protected $label;
/**
* @return string
*/
protected $placeholder;
/**
* @var string
*/
protected $display = self::DISPLAY_INLINE;
protected $group = '';
/**
* It should return an unique identifier of the placeholder
*
* @return mixed
*/
public function getUid()
{
return md5(microtime());
}
public function support($placeholderName) {
return $this->getPlaceholder()==$placeholderName;
}
public function shouldFallbackValue($value, ContextInterface $context, ContentPlaceholder $placeholder)
{
return empty($value);
}
public function getFallbackValue(ContextInterface $context, ContentPlaceholder $placeholder)
{
$attributes = $placeholder->getAttributes();
return isset($attributes[PlaceholderInterface::FALLBACK_KEY]) ? $attributes[PlaceholderInterface::FALLBACK_KEY] : '';
}
/**
* @return mixed
*/
public function getLabel() {
return $this->label;
}
/**
* @param mixed $label
*
* @return Brizy_Content_Placeholders_Abstract
*/
public function setLabel( $label ) {
$this->label = $label;
return $this;
}
/**
* @return string
*/
public function getDisplay() {
return $this->display;
}
/**
* @param string $display
*
* @return Brizy_Content_Placeholders_Abstract
*/
public function setDisplay( $display ) {
$this->display = $display;
return $this;
}
/**
* @return string
*/
public function getGroup()
{
return $this->group;
}
/**
* @param string $group
* @return Brizy_Content_Placeholders_Abstract
*/
public function setGroup($group)
{
$this->group = $group;
return $this;
}
/**
* @return mixed
*/
public function getPlaceholder() {
return $this->placeholder;
}
/**
* @param mixed $placeholder
*
* @return Brizy_Content_Placeholders_Abstract
*/
public function setPlaceholder( $placeholder ) {
$this->placeholder = $placeholder;
return $this;
}
/**
* @return array
*/
public function convertToOptionValue() {
return array(
'label' => $this->getLabel(),
'placeholder' => $this->getPlaceholder(),
'display' => $this->getDisplay(),
);
}
public function jsonSerialize() {
return array(
'label' => $this->getLabel(),
'placeholder' => $this->getReplacePlaceholder(),
'display' => $this->getDisplay(),
);
}
/**
* @return string
*/
public function getReplacePlaceholder() {
$placeholder = $this->getPlaceholder();
if ( ! empty( $placeholder ) ) {
return "{{" . $placeholder . "}}";
}
return "";
}
}

View File

@@ -0,0 +1,13 @@
<?php
class Brizy_Content_Placeholders_ImageAltAttribute extends Brizy_Content_Placeholders_ImageAttribute {
/**
* @param $attachmentId
*
* @return string
*/
protected function getAttributeValue( $attachmentId ) {
return get_post_meta( $attachmentId, '_wp_attachment_image_alt', true );
}
}

View File

@@ -0,0 +1,101 @@
<?php
abstract class Brizy_Content_Placeholders_ImageAttribute extends Brizy_Content_Placeholders_Simple {
/**
* @return string|callable
*/
protected $value;
/**
* @param $attachmentId
*
* @return mixed
*/
abstract protected function getAttributeValue( $attachmentId );
/**
* Brizy_Editor_Content_GenericPlaceHolder constructor.
*
* @param string $label
* @param string $placeholder
* @param string|array $value
*/
public function __construct( $label, $placeholder ) {
parent::__construct( $label, $placeholder, function ( Brizy_Content_Context $context, \BrizyPlaceholders\ContentPlaceholder $contentPlaceholder ) {
$attributes = $contentPlaceholder->getAttributes();
$attachmentId = null;
if ( isset( $attributes['uid'] ) ) {
$attachmentId = $this->getAttachmentIdByByUid( $attributes['uid'], $context );
} elseif ( isset( $attributes['placeholder'] ) ) {
$attachmentId = $this->getAttachmentIdByPlaceholderName( $attributes['placeholder'], $context, $contentPlaceholder );
}
if ( $attachmentId ) {
return $this->getAttributeValue( $attachmentId );
}
return '';
} );
}
/**
* @param $placeholderName
* @param Brizy_Content_Context $context
* @param \BrizyPlaceholders\ContentPlaceholder $contentPlaceholder
*
* @return int|mixed|null|string
*/
protected function getAttachmentIdByPlaceholderName( $placeholderName, Brizy_Content_Context $context, \BrizyPlaceholders\ContentPlaceholder $contentPlaceholder ) {
$provider = $context->getProvider();
if ( ! $provider ) {
return 0;
}
$placeholder = $provider->getPlaceholderSupportingName( $placeholderName );
if ( ! $placeholder ) {
return 0;
}
if ( $placeholder instanceof BrizyPro_Content_Placeholders_Image ) {
$attachmentId = $placeholder->getAttachmentId( $context, $contentPlaceholder );
} else {
$attachmentId = $placeholder->getValue( $context, $contentPlaceholder );
}
return $attachmentId;
}
/**
* @param $uid
* @param Brizy_Content_Context $context
*
* @return null|string
*/
protected function getAttachmentIdByByUid( $uid, Brizy_Content_Context $context ) {
global $wpdb;
$pt = $wpdb->posts;
$mt = $wpdb->postmeta;
$attachmentId = $wpdb->get_var( $wpdb->prepare(
"SELECT
{$pt}.ID
FROM {$pt}
INNER JOIN {$mt} ON ( {$pt}.ID = {$mt}.post_id )
WHERE
( {$mt}.meta_key = 'brizy_attachment_uid'
AND {$mt}.meta_value = %s )
AND {$pt}.post_type = 'attachment'
ORDER BY {$pt}.post_date DESC",
$uid
) );
return $attachmentId;
}
}

View File

@@ -0,0 +1,17 @@
<?php
use \BrizyPlaceholders\ContentPlaceholder;
trait Brizy_Content_Placeholders_ImageAttributesAware {
/**
* It should return a string containigng image attributes
* Ex: alt="image alt attribute" title="Image title"
*
* @param Brizy_Content_Context $context
* @param ContentPlaceholder $contentPlaceholder
*
* @return
*/
abstract public function getAttachmentId( Brizy_Content_Context $context, ContentPlaceholder $contentPlaceholder );
}

View File

@@ -0,0 +1,15 @@
<?php
class Brizy_Content_Placeholders_ImageTitleAttribute extends Brizy_Content_Placeholders_ImageAttribute {
/**
* @param $attachmentId
*
* @return mixed|string
*/
protected function getAttributeValue( $attachmentId ) {
$post = get_post( $attachmentId );
return $post->post_title;
}
}

View File

@@ -0,0 +1,34 @@
<?php
use BrizyPlaceholders\ContentPlaceholder;
class Brizy_Content_Placeholders_Permalink extends Brizy_Content_Placeholders_Simple {
/**
* Brizy_Content_Placeholders_Simple constructor.
*
* @param $label
* @param $placeholder
* @param $value
* @param string $display
*/
public function __construct() {
parent::__construct( 'Permalink', 'brizy_dc_permalink', null );
}
/**
* @param ContentPlaceholder $contentPlaceholder
* @param Brizy_Content_Context $context
*
* @return mixed|string
*/
public function getValue(\BrizyPlaceholders\ContextInterface $context, ContentPlaceholder $contentPlaceholder) {
$attributes = $contentPlaceholder->getAttributes();
if ( isset( $attributes['post_id'] ) && (int) $attributes['post_id'] > 0 ) {
return get_permalink( (int) $attributes['post_id'] );
}
return '';
}
}

View File

@@ -0,0 +1,48 @@
<?php
use BrizyPlaceholders\ContentPlaceholder;
use BrizyPlaceholders\ContextInterface;
class Brizy_Content_Placeholders_Simple extends Brizy_Content_Placeholders_Abstract
{
/**
* @return string|callable
*/
protected $value;
/**
* Brizy_Content_Placeholders_Simple constructor.
*
* @param $label
* @param $placeholder
* @param $value
* @param string $display
*/
public function __construct($label, $placeholder, $value, $group = null, $display = Brizy_Content_Placeholders_Abstract::DISPLAY_INLINE)
{
$this->setLabel($label);
$this->setPlaceholder($placeholder);
$this->setDisplay($display);
$this->setGroup($group);
$this->value = $value;
}
/**
* @param ContextInterface $context
* @param ContentPlaceholder $placeholder
*
* @return mixed
*/
public function getValue(ContextInterface $context, ContentPlaceholder $placeholder)
{
$method = $this->value;
if (is_object($method) && ($method instanceof Closure)) {
return call_user_func($method, $context, $placeholder);
}
return $this->value;
}
}

View File

@@ -0,0 +1,67 @@
<?php
use BrizyPlaceholders\ContentPlaceholder;
class Brizy_Content_Placeholders_UniquePageUrl extends Brizy_Content_Placeholders_Simple {
/**
* Brizy_Content_Placeholders_Simple constructor.
*
* @param $label
* @param $placeholder
* @param $value
* @param string $display
*/
public function __construct( $label, $placeholder = 'brizy_dc_current_page_unique_url', $value = null, $display = Brizy_Content_Placeholders_Abstract::DISPLAY_INLINE ) {
$this->setLabel( $label );
$this->setPlaceholder( $placeholder );
$this->setDisplay( $display );
$this->value = null;
}
/**
* @param ContentPlaceholder $contentPlaceholder
* @param Brizy_Content_Context $context
*
* @return mixed|string
*/
public function getValue(\BrizyPlaceholders\ContextInterface $context, ContentPlaceholder $contentPlaceholder) {
global $wp;
$url = home_url( add_query_arg(array(), $wp->request) );
$closure = function () {
return false;
};
add_filter( 'pre_term_link', $closure );
$object = get_queried_object();
if(is_archive()) {
$url = add_query_arg($wp->query_vars, home_url() );
}
if ( $object instanceof WP_User ) {
$file = home_url( '/' );
$url = $file . '?author=' . $object->ID;
}
if ( $object instanceof WP_Post ) {
$url = $object->guid;
}
if ( $object instanceof WP_Term ) {
$url = get_term_link( $object );
}
remove_filter( 'pre_term_link', $closure );
return $url;
}
}