| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'WPGRADE_SHORTCODES_PATH' ) or define( 'WPGRADE_SHORTCODES_PATH', plugin_dir_path( __FILE__ ) ); |
| 4 |
defined( 'WPGRADE_SHORTCODES_URL' ) or define( 'WPGRADE_SHORTCODES_URL', plugin_dir_url( dirname( __FILE__ ) . '/shortcodes.php' ) ); |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
die( '-1' ); |
| 8 |
} |
| 9 |
|
| 10 |
require_once 'util.php'; |
| 11 |
|
| 12 |
class WpGradeShortcode { |
| 13 |
|
| 14 |
public $plug_dir; |
| 15 |
protected $shortcode; |
| 16 |
protected $settings; |
| 17 |
protected $params; |
| 18 |
protected $self_closed; |
| 19 |
protected $one_line; |
| 20 |
protected $code; |
| 21 |
protected $direct; |
| 22 |
protected $icon; |
| 23 |
protected $shortcodes; |
| 24 |
protected $name; |
| 25 |
protected $backend_assets; |
| 26 |
protected $frontend_assets; |
| 27 |
protected $load_frontend_scripts; |
| 28 |
//we use this to get the prefix for the meta data from the theme - usually it's short theme name |
| 29 |
protected $meta_prefix; |
| 30 |
|
| 31 |
public function __construct() { |
| 32 |
|
| 33 |
$this->plug_dir = plugins_url(); |
| 34 |
$this->self_closed = false; |
| 35 |
$this->one_line = false; |
| 36 |
$this->shortcodes = array(); |
| 37 |
|
| 38 |
$this->autoload(); |
| 39 |
|
| 40 |
// init assets list // useless |
| 41 |
$this->assets = array( |
| 42 |
'js' => array(), |
| 43 |
'css' => array() |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
public function autoload() { |
| 48 |
|
| 49 |
$shortcodes = get_option( 'wpgrade_shortcodes_list' ); |
| 50 |
|
| 51 |
if ( empty( $shortcodes ) ) { |
| 52 |
$shortcodes = array( |
| 53 |
'Arrow', |
| 54 |
'Button', |
| 55 |
'Columns', |
| 56 |
'Heading', |
| 57 |
'Icon', |
| 58 |
'InfoBox', |
| 59 |
'OpenTableReservations', |
| 60 |
'ProgressBar', |
| 61 |
'Quote', |
| 62 |
'RestaurantMenu', |
| 63 |
'Separator', |
| 64 |
'Slider', |
| 65 |
'Tabs', |
| 66 |
'TeamMember', |
| 67 |
'PixFields' |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
foreach ( $shortcodes as $file ) { |
| 72 |
|
| 73 |
$file_name = 'WpGradeShortcode_' . $file . '.php'; |
| 74 |
$file_path = WPGRADE_SHORTCODES_PATH . '/shortcodes/' . $file_name; |
| 75 |
|
| 76 |
if ( ! file_exists( $file_path ) ) { |
| 77 |
continue; |
| 78 |
} |
| 79 |
|
| 80 |
include_once( $file_path ); |
| 81 |
$shortcode_class = 'WpGradeShortcode_' . $file; |
| 82 |
$shortcode = new $shortcode_class(); |
| 83 |
|
| 84 |
// create a list of params needed for js to create the admin panel |
| 85 |
$this->shortcodes[ $shortcode_class ]["name"] = $shortcode->name; |
| 86 |
$this->shortcodes[ $shortcode_class ]["code"] = $shortcode->code; |
| 87 |
$this->shortcodes[ $shortcode_class ]["self_closed"] = $shortcode->self_closed; |
| 88 |
$this->shortcodes[ $shortcode_class ]["direct"] = $shortcode->direct; |
| 89 |
$this->shortcodes[ $shortcode_class ]["one_line"] = $shortcode->one_line; |
| 90 |
$this->shortcodes[ $shortcode_class ]["icon"] = $shortcode->icon; |
| 91 |
if ( $shortcode->direct == false ) { |
| 92 |
$this->shortcodes[ $shortcode_class ]["params"] = $shortcode->params; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
public function get_shortcodes() { |
| 98 |
return $this->shortcodes; |
| 99 |
} |
| 100 |
|
| 101 |
public function get_code() { |
| 102 |
return $this->code; |
| 103 |
} |
| 104 |
|
| 105 |
public function load_backend_assets( $buttons ) { |
| 106 |
|
| 107 |
if ( ! empty( $this->backend_assets ) ) { |
| 108 |
$types = $this->backend_assets; |
| 109 |
|
| 110 |
foreach ( $types as $type => $assets ) { |
| 111 |
foreach ( $assets as $key => $asset ) { |
| 112 |
$path = WPGRADE_SHORTCODES_URL . $asset['path']; |
| 113 |
if ( $type == 'js' ) { |
| 114 |
wp_enqueue_script( $asset['name'], $path, $asset['deps'] ); |
| 115 |
} elseif ( $type == 'css' ) { |
| 116 |
wp_enqueue_style( $asset['name'], $path, $asset['deps'] ); |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
// do not modify buttons here ... we just add our scripts |
| 123 |
return $buttons; |
| 124 |
} |
| 125 |
|
| 126 |
public function load_frontend_assets() { |
| 127 |
|
| 128 |
if ( ! empty( $this->frontend_assets ) && $this->load_frontend_scripts == true ) { |
| 129 |
$types = $this->frontend_assets; |
| 130 |
|
| 131 |
foreach ( $types as $type => $assets ) { |
| 132 |
foreach ( $assets as $key => $asset ) { |
| 133 |
$path = WPGRADE_SHORTCODES_URL . $asset['path']; |
| 134 |
if ( $type == 'js' ) { |
| 135 |
wp_enqueue_script( $asset['name'], $path, $asset['deps'] ); |
| 136 |
} elseif ( $type == 'css' ) { |
| 137 |
wp_enqueue_style( $asset['name'], $path, $asset['deps'] ); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
public function get_clean_content( $content ) { |
| 145 |
$content = preg_replace( '#<br class="pxg_removable" />#', '', $content ); // remove our temp brs |
| 146 |
|
| 147 |
return do_shortcode( $content ); |
| 148 |
} |
| 149 |
|
| 150 |
public function render_param( $param ) { |
| 151 |
|
| 152 |
$file_name = $param['type'] . '.php'; |
| 153 |
$file_path = WPGRADE_SHORTCODES_PATH . 'params/' . $file_name; |
| 154 |
|
| 155 |
if ( ! file_exists( $file_path ) ) { |
| 156 |
echo '<span class="error">Inexistent param</span>'; |
| 157 |
} |
| 158 |
ob_start(); |
| 159 |
|
| 160 |
include( $file_path ); |
| 161 |
|
| 162 |
echo ob_get_clean(); |
| 163 |
} |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
global $wpgrade_shortcodes; |
| 168 |
$wpgrade_shortcodes = new WpGradeShortcode(); |