magic /wp-content/themes/nonus/theme/shortcodes/buttons/ctButtonShortcode.class.php

Language PHP Lines 104
MD5 Hash 9bb281f004c505494b0b126ea5c5d583
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
<?php
/**
 * Button shortcode
 */
class ctButtonShortcode extends ctShortcode {

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

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

	/**
	 * Shortcode type
	 * @return string
	 */
	public function getShortcodeType() {
		return self::TYPE_SHORTCODE_ENCLOSING;
	}


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

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

		$id = $id ? ' id="' . $id . '"' : '';
		$color = $color ? ' btn-' . $color : '';
		$class = $class ? ' ' . $class : '';
		$link = $link ? ' href="' . $link . '"' : '';
		$size = $size=='medium' ? '' : ('btn-' . $size);

		$iconHtml = $icon ? '<i class="' . $icon . ' icon-' . $iconplace . '"></i> ' : '';
		$leftIconHtml = '';
		$rightIconHtml = '';
		if($iconplace == 'left'){
			$leftIconHtml = $iconHtml;
		}else{
			$rightIconHtml = $iconHtml;
		}

		if ($width) {
			if (is_numeric($width)) {
				$width = $width . 'px';
			}
			$width = ' style="width:' . $width . ';"';
		} else {
			$width = '';
		}

		$tag = 'a';
		if ($button == 'yes') {
			$button = '';
		} else {
			$button = ' btn-link';
		}
		if ($button!='yes' && $nofollow == 'true') {
			$follow_tag = ' rel="nofollow"';
		} else {
			$follow_tag = '';
		}

		$content = '<' . $tag . $id . $link . $width . ' class="' . apply_filters('theme_css_class', 'btn') . ' ' . $size . $color . $button . $class . '"' . $follow_tag . '>' . $leftIconHtml . trim($content) . $rightIconHtml . '</' . $tag . '>';
		return $content;
	}

	/**
	 * Returns config
	 * @return null
	 */
	public function getAttributes() {

		return array(
			'id' => array('default' => false, 'type' => false),
			'class' => array('default' => false, 'type' => false),
			'size' => array('label' => __('size', 'ct_theme'), 'default' => 'medium', 'type' => 'select', 'choices' => array('mini' => __('mini', 'ct_theme'), 'small' => __('small', 'ct_theme'), 'medium' => __('medium', 'ct_theme'), 'large' => __('large', 'ct_theme'), 'block' => __('block', 'ct_theme')), 'help' => __("Button size",'ct_theme')),
			'link' => array('label' => __('link', 'ct_theme'),'help' => __("ex. http://www.google.com",'ct_theme')),
			'width' => array('label' => __('width', 'ct_theme'),'type' => "input"),
			'color' => array('label' => __('color', 'ct_theme'),'default' => 'default', 'type' => "select", 'choices' => array('default' => __('Default','ct_theme'), 'inactive' => __('inactive', 'ct_theme'), 'inverse' => __('inverse', 'ct_theme'), 'info' => __('info', 'ct_theme'), 'success' => __('success', 'ct_theme'), 'warning' => __('warning', 'ct_theme'), 'danger' => __('danger', 'ct_theme'))),
			'icon' => array('label' => __('icon', 'ct_theme'),'type' => "icon", 'default' => '','link'=>CT_THEME_ASSETS.'/shortcode/awesome/index.html'),
			'iconplace' => array('label' => __('icon place', 'ct_theme'), 'default' => 'left', 'type' => 'select', 'choices' => array('left' => __('left', 'ct_theme'), 'right' => __('right', 'ct_theme'))),
			'button' => array('label' => __('is button', 'ct_theme'), 'default' => 'yes', 'type' => 'select', 'choices' => array('yes' => __('yes', 'ct_theme'), 'no' => __('no', 'ct_theme')), 'help' => __("Draw button or link",'ct_theme')),
			'content' => array('label' => __('label', 'ct_theme'), 'default' => '', 'type' => 'textarea'),
			'nofollow' => array('label' => __('nofollow', 'ct_theme'),'type' => "checkbox", 'default' => 'true'),
		);
	}
}

new ctButtonShortcode();
Back to Top