magic /wp-content/themes/nonus/theme/shortcodes/images/ctImageShortcode.class.php

Language PHP Lines 122
MD5 Hash df6ab38de65721ea8f8e4ea4b39e3972
Repository https://github.com/alniko009/magic.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
 * Image shortcode
 */
class ctImageShortcode extends ctShortcode {

	/**
	 * default image link base
	 */
	const DEFAULT_IMG_SRC = "http://dummyimage.com/";

	/**
	 * default image width
	 */
	const DEFAULT_IMG_WIDTH = 90;

	/**
	 * default image heightd
	 */
	const DEFAULT_IMG_HEIGHT = 90;

	/**
	 * Returns name
	 * @return string|void
	 */
	public function getName() {
		return 'Image';
	}

	/**
	 * Shortcode name
	 * @return string
	 */
	public function getShortcodeName() {
		return 'img';
	}

	/**
	 * Handles shortcode
	 * @param $atts
	 * @param null $content
	 * @return string
	 */

	public function handle($atts, $content = null) {
		extract(shortcode_atts($this->extractShortcodeAttributes($atts), $atts));

		$src = $src ? $src : $this->getDefaultImgSrc($width, $height);
		switch ($align) {
			case 'center':
				$style = 'display:block; margin:0 auto;';
				$divContainerStyle = "text-align:center";
				break;
			case 'left':
				$style = 'float: left';
				$divContainerStyle = "text-align:left";
				break;
			case 'right':
				$style = 'float: right';
				$divContainerStyle = "text-align:right";
				break;
			default:
				$style = '';
				$divContainerStyle = "";

		}


		$class = $class ? $class : '';

		if ($width) {
			$width = $width ? 'width=' . $width : '';
		}
		if ($height) {
			$height = $height ? 'height=' . $height : '';
		}


		$overlayHtml = '';


		$img = '<img class="' . $class . '" alt="' . $alt . '" src="' . $src . '" ' . $width . ' ' . $height . ' style="' . $style . '">' . $overlayHtml;


		//link
		if ($link && $overlay == 'no') {
			$img = '<a href="' . $link . '">' . $img . '</a>';
		}
		return do_shortcode($img);
	}

	/**
	 * Returns config
	 * @return null
	 */
	public function getAttributes() {
		return array(
			'src' => array('label' => __("image", 'ct_theme'), 'default' => '', 'type' => 'image', 'help' => __("Image source", 'ct_theme')),
			'alt' => array('label' => __('alt', 'ct_theme'), 'default' => '', 'type' => 'input', 'help' => __("Alternate text", 'ct_theme')),
			'width' => array('label' => __('width', 'ct_theme'), 'default' => self::DEFAULT_IMG_WIDTH, 'type' => 'input', 'help' => __("Image width", 'ct_theme')),
			'height' => array('label' => __('height', 'ct_theme'), 'default' => self::DEFAULT_IMG_HEIGHT, 'type' => 'input', 'help' => __("Image height", 'ct_theme')),
			'align' => array('label' => __('align', 'ct_theme'), 'default' => 'auto', 'type' => 'select', 'options' => array('default' => __('Default', 'ct_theme'), 'left' => __('Left', 'ct_theme'), 'center' => __('Center', 'ct_theme'), 'right' => __('Right', 'ct_theme')), 'help' => __("Image align", 'ct_theme')),
			'link' => array('label' => __('link', 'ct_theme'), 'help' => __("ex. http://www.google.com", 'ct_theme')),
			'class' => array('label' => __("class", 'ct_theme'), 'default' => '', 'type' => 'input', 'help' => __("Image class", 'ct_theme')),
		);
	}

	/**
	 * returns default image source
	 * @param $width
	 * @param $height
	 * @return string
	 */
	protected function getDefaultImgSrc($width, $height) {
		if($width && $height){
			return self::DEFAULT_IMG_SRC . $width . "x" . $height;
		}
		return '';
	}
}

new ctImageShortcode();
Back to Top