Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/jet-engine   php

Repository URL to install this package:

/ components / blocks-views / block-types / dynamic-meta.php

<?php
/**
 * Elementor views manager
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

if ( ! class_exists( 'Jet_Engine_Blocks_Views_Type_Dynamic_Meta' ) ) {

	/**
	 * Define Jet_Engine_Blocks_Views_Type_Dynamic_Meta class
	 */
	class Jet_Engine_Blocks_Views_Type_Dynamic_Meta extends Jet_Engine_Blocks_Views_Type_Base {

		/**
		 * Returns block name
		 *
		 * @return [type] [description]
		 */
		public function get_name() {
			return 'dynamic-meta';
		}

		/**
		 * Returns CSS selector for nested element
		 *
		 * @param  string|array $el
		 * @return string
		 */
		public function css_selector( $el = null ) {
			if ( ! is_array( $el ) ) {
				return sprintf( '{{WRAPPER}} .jet-listing-dynamic-meta%s', $el );
			} else {

				$res = array();

				foreach ( $el as $selector ) {
					$res[] = sprintf( '{{WRAPPER}} .jet-listing-dynamic-meta%s', $selector );
				}

				return implode( ', ', $res );
			}
		}

		public function prepare_attributes( $attributes = array() ) {

			$attributes['meta_items'] = array();

			if ( ! isset( $attributes['date_enabled'] ) || true === $attributes['date_enabled'] ) {

				$attributes['meta_items'][] = array(
					'type'          => 'date',
					'selected_icon' => $this->get_attr( 'date_selected_icon', $attributes ),
					'prefix'        => $this->get_attr( 'date_prefix', $attributes ),
					'suffix'        => $this->get_attr( 'date_suffix', $attributes ),
				);

			}

			if ( ! isset( $attributes['author_enabled'] ) || true === $attributes['author_enabled'] ) {

				$attributes['meta_items'][] = array(
					'type'          => 'author',
					'selected_icon' => $this->get_attr( 'author_selected_icon', $attributes ),
					'prefix'        => $this->get_attr( 'author_prefix', $attributes ),
					'suffix'        => $this->get_attr( 'author_suffix', $attributes ),
				);

			}

			if ( ! isset( $attributes['comments_enabled'] ) || true === $attributes['comments_enabled'] ) {

				$attributes['meta_items'][] = array(
					'type'          => 'comments',
					'selected_icon' => $this->get_attr( 'comments_selected_icon', $attributes ),
					'prefix'        => $this->get_attr( 'comments_prefix', $attributes ),
					'suffix'        => $this->get_attr( 'comments_suffix', $attributes ),
				);

			}

			$unset = array(
				'date_enabled',
				'date_selected_icon',
				'date_prefix',
				'date_suffix',
				'author_enabled',
				'author_selected_icon',
				'author_prefix',
				'author_suffix',
				'comments_enabled',
				'comments_selected_icon',
				'comments_prefix',
				'comments_suffix',
			);


			foreach ( $unset as $key ) {
				if ( isset( $attributes[ $key ] ) ) {
					unset( $attributes[ $key ] );
				}
			}

			return $attributes;
		}

		/**
		 * Return attributes array
		 *
		 * @return array
		 */
		public function get_attributes() {
			return array(
				'date_enabled' => array(
					'type' => 'boolean',
					'default' => true,
				),
				'date_selected_icon' => array(
					'type' => 'number',
				),
				'date_selected_icon_url' => array(
					'type' => 'string',
					'default' => '',
				),
				'date_prefix' => array(
					'type' => 'string',
					'default' => '',
				),
				'date_suffix' => array(
					'type' => 'string',
					'default' => '',
				),
				'date_format' => array(
					'type' => 'string',
					'default' => 'F-j-Y',
				),
				'date_link' => array(
					'type' => 'string',
					'default' => 'archive',
				),
				'author_enabled' => array(
					'type' => 'boolean',
					'default' => true,
				),
				'author_selected_icon' => array(
					'type' => 'number',
				),
				'author_selected_icon_url' => array(
					'type' => 'string',
					'default' => '',
				),
				'author_prefix' => array(
					'type' => 'string',
					'default' => '',
				),
				'author_suffix' => array(
					'type' => 'string',
					'default' => '',
				),
				'author_link' => array(
					'type' => 'string',
					'default' => 'archive',
				),
				'comments_enabled' => array(
					'type' => 'boolean',
					'default' => true,
				),
				'comments_selected_icon' => array(
					'type' => 'number',
				),
				'comments_selected_icon_url' => array(
					'type' => 'string',
					'default' => '',
				),
				'comments_prefix' => array(
					'type' => 'string',
					'default' => '',
				),
				'comments_suffix' => array(
					'type' => 'string',
					'default' => '',
				),
				'comments_link' => array(
					'type' => 'string',
					'default' => 'single',
				),
				'zero_comments_format' => array(
					'type' => 'string',
					'default' => '0',
				),
				'one_comment_format' => array(
					'type' => 'string',
					'default' => '1',
				),
				'more_comments_format' => array(
					'type' => 'string',
					'default' => '%',
				),
				'layout' => array(
					'type' => 'string',
					'default' => 'inline',
				),
			);
		}

		/**
		 * Add style block options
		 *
		 * @return boolean
		 */
		public function add_style_manager_options() {

			$this->controls_manager->start_section(
				'style_controls',
				array(
					'id'           => 'section_general_style',
					'initial_open' => true,
					'title'        => esc_html__( 'General', 'jet-engine' )
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'         => 'meta_alignment',
					'label'      => __( 'Alignment', 'jet-engine' ),
					'type'       => 'choose',
					'attributes' => array(
						'default' => array(
							'value' => 'left',
						),
					),
					'options' => array(
						'left'   => array(
							'label' => esc_html__( 'Left', 'jet-engine' ),
							'icon'  => 'dashicons-editor-alignleft',
						),
						'center' => array(
							'label' => esc_html__( 'Center', 'jet-engine' ),
							'icon'  => 'dashicons-editor-aligncenter',
						),
						'right'  => array(
							'label' => esc_html__( 'Right', 'jet-engine' ),
							'icon'  => 'dashicons-editor-alignright',
						),
					),
					'css_selector' => array(
						$this->css_selector() => 'text-align: {{VALUE}};',
					),
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'           => 'item_typography',
					'label'        => __( 'Typography', 'jet-engine' ),
					'type'         => 'typography',
					'separator'    => 'before',
					'css_selector' => array(
						$this->css_selector( array( '__item', '__item-val') ) => 'font-family: {{FAMILY}}; font-weight: {{WEIGHT}}; text-transform: {{TRANSFORM}}; font-style: {{STYLE}}; text-decoration: {{DECORATION}}; line-height: {{LINEHEIGHT}}{{LH_UNIT}}; letter-spacing: {{LETTERSPACING}}{{LS_UNIT}}; font-size: {{SIZE}}{{S_UNIT}};',
					),
				)
			);

			$this->controls_manager->start_tabs(
				'style_controls',
				array(
					'id'        => 'tabs_form_submit_style',
					'separator' => 'after',
				)
			);

			$this->controls_manager->start_tab(
				'style_controls',
				array(
					'id'    => 'dynamic_item_normal',
					'title' => esc_html__( 'Normal', 'jet-engine' ),
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'           => 'item_bg_color',
					'label'        => esc_html__( 'Background Color', 'jet-engine' ),
					'type'         => 'color-picker',
					'css_selector' => array(
						$this->css_selector( '__item' ) => 'background-color: {{VALUE}}',
					),
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'           => 'item_color',
					'label'        => esc_html__( 'Text Color', 'jet-engine' ),
					'type'         => 'color-picker',
					'separator'    => 'before',
					'css_selector' => array(
						$this->css_selector( array( '__item', '__item-val') ) => 'color: {{VALUE}}',
					),
				)
			);

			$this->controls_manager->end_tab();

			$this->controls_manager->start_tab(
				'style_controls',
				array(
					'id'    => 'dynamic_item_hover',
					'title' => esc_html__( 'Hover', 'jet-engine' ),
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'           => 'item_bg_color_hover',
					'label'        => esc_html__( 'Background Color', 'jet-engine' ),
					'type'         => 'color-picker',
					'css_selector' => array(
						$this->css_selector( '__item:hover' ) => 'background-color: {{VALUE}}',
					),
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'           => 'item_color_hover',
					'label'        => esc_html__( 'Text Color', 'jet-engine' ),
					'type'         => 'color-picker',
					'separator'    => 'before',
					'css_selector' => array(
						$this->css_selector( array( '__item:hover', '__item-val:hover') ) => 'color: {{VALUE}}',
					),
				)
			);

			$this->controls_manager->add_control(
				array(
					'id'           => 'item_hover_border_color',
					'label'        => esc_html__( 'Border Color', 'jet-engine' ),
					'type'         => 'color-picker',
					'separator'    => 'before',
					'css_selector' => array(
Loading ...