| @@ -1,0 +1,306 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Extension Abstract | |
| 4 | + * | |
| 5 | + * @package NotificationX\Extensions | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace NotificationX\Types; | |
| 9 | + | |
| 10 | +use NotificationX\Core\Rules; | |
| 11 | +use NotificationX\Extensions\GlobalFields; | |
| 12 | +use NotificationX\GetInstance; | |
| 13 | +use NotificationX\Modules; | |
| 14 | +use NotificationX\NotificationX; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * Extension Abstract for all Extension. | |
| 18 | + * @method static ELearning get_instance($args = null) | |
| 19 | + */ | |
| 20 | +class ELearning extends Types { | |
| 21 | + /** | |
| 22 | + * Instance of Admin | |
| 23 | + * | |
| 24 | + * @var Admin | |
| 25 | + */ | |
| 26 | + use GetInstance; | |
| 27 | + | |
| 28 | + public $priority = 10; | |
| 29 | + public $themes = []; | |
| 30 | + public $module = [ | |
| 31 | + 'modules_tutor', | |
| 32 | + 'modules_learndash', | |
| 33 | + ]; | |
| 34 | + public $default_source = 'tutor'; | |
| 35 | + public $default_theme = 'elearning_theme-one'; | |
| 36 | + public $link_type = 'course_page'; | |
| 37 | + | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Initially Invoked when initialized. | |
| 41 | + */ | |
| 42 | + public function __construct(){ | |
| 43 | + parent::__construct(); | |
| 44 | + $this->id = 'elearning'; | |
| 45 | + add_filter("nx_filtered_entry_{$this->id}", array($this, 'conversion_data'), 10, 2); | |
| 46 | + } | |
| 47 | + | |
| 48 | + public function init() | |
| 49 | + { | |
| 50 | + parent::init(); | |
| 51 | + $this->title = __('eLearning', 'notificationx'); | |
| 52 | + $this->themes = [ | |
| 53 | + 'theme-one' => [ | |
| 54 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-1.jpg', | |
| 55 | + 'image_shape' => 'circle', | |
| 56 | + 'template' => [ | |
| 57 | + 'first_param' => 'tag_name', | |
| 58 | + 'custom_first_param' => __('Someone' , 'notificationx'), | |
| 59 | + 'second_param' => __('just enrolled', 'notificationx'), | |
| 60 | + 'third_param' => 'tag_course_title', | |
| 61 | + 'custom_third_param' => __('Anonymous Course' , 'notificationx'), | |
| 62 | + 'fourth_param' => 'tag_time', | |
| 63 | + 'custom_fourth_param' => __( 'Some time ago', 'notificationx' ), | |
| 64 | + ], | |
| 65 | + ], | |
| 66 | + 'theme-two' => [ | |
| 67 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-2.jpg', | |
| 68 | + 'image_shape' => 'circle', | |
| 69 | + 'template' => [ | |
| 70 | + 'first_param' => 'tag_name', | |
| 71 | + 'custom_first_param' => __('Someone' , 'notificationx'), | |
| 72 | + 'second_param' => __('recently enrolled' , 'notificationx'), | |
| 73 | + 'third_param' => 'tag_course_title', | |
| 74 | + 'custom_third_param' => __('Anonymous Course' , 'notificationx'), | |
| 75 | + 'fourth_param' => 'tag_time', | |
| 76 | + 'custom_fourth_param' => __( 'Some time ago', 'notificationx' ), | |
| 77 | + ], | |
| 78 | + ], | |
| 79 | + 'theme-three' => [ | |
| 80 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-3.jpg', | |
| 81 | + 'image_shape' => 'square', | |
| 82 | + 'template' => [ | |
| 83 | + 'first_param' => 'tag_name', | |
| 84 | + 'custom_first_param' => __('Someone' , 'notificationx'), | |
| 85 | + 'second_param' => __('recently enrolled' , 'notificationx'), | |
| 86 | + 'third_param' => 'tag_course_title', | |
| 87 | + 'custom_third_param' => __('Anonymous Course' , 'notificationx'), | |
| 88 | + 'fourth_param' => 'tag_time', | |
| 89 | + 'custom_fourth_param' => __( 'Some time ago', 'notificationx' ), | |
| 90 | + ], | |
| 91 | + ], | |
| 92 | + 'theme-four' => array( | |
| 93 | + 'is_pro' => true, | |
| 94 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-4.png', | |
| 95 | + 'image_shape' => 'circle', | |
| 96 | + ), | |
| 97 | + 'theme-five' => array( | |
| 98 | + 'is_pro' => true, | |
| 99 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-5.png', | |
| 100 | + 'image_shape' => 'circle', | |
| 101 | + ), | |
| 102 | + 'conv-theme-six' => array( | |
| 103 | + 'is_pro' => true, | |
| 104 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-6.png', | |
| 105 | + 'image_shape' => 'circle', | |
| 106 | + ), | |
| 107 | + 'conv-theme-seven' => array( | |
| 108 | + 'is_pro' => true, | |
| 109 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-7.png', | |
| 110 | + 'image_shape' => 'rounded', | |
| 111 | + ), | |
| 112 | + 'conv-theme-eight' => array( | |
| 113 | + 'is_pro' => true, | |
| 114 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-8.png', | |
| 115 | + 'image_shape' => 'circle', | |
| 116 | + ), | |
| 117 | + 'conv-theme-nine' => array( | |
| 118 | + 'is_pro' => true, | |
| 119 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/elearning-theme-9.png', | |
| 120 | + 'image_shape' => 'circle', | |
| 121 | + ), | |
| 122 | + 'maps_theme' => array( | |
| 123 | + 'is_pro' => true, | |
| 124 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/elearning/maps-theme.png', | |
| 125 | + 'image_shape' => 'square', | |
| 126 | + 'show_notification_image' => 'maps_image', | |
| 127 | + ), | |
| 128 | + ]; | |
| 129 | + $this->res_themes = [ | |
| 130 | + 'res-theme-one' => array( | |
| 131 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-1.png', | |
| 132 | + '_template' => 'elearning_template_new', | |
| 133 | + 'is_pro' => true, | |
| 134 | + ), | |
| 135 | + 'res-theme-two' => array( | |
| 136 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-2.png', | |
| 137 | + '_template' => 'elearning_template_new', | |
| 138 | + 'is_pro' => true, | |
| 139 | + ), | |
| 140 | + 'res-theme-three' => array( | |
| 141 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-3.png', | |
| 142 | + '_template' => 'elearning_template_new', | |
| 143 | + 'is_pro' => true, | |
| 144 | + ), | |
| 145 | + 'res-theme-four' => array( | |
| 146 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-4.png', | |
| 147 | + '_template' => 'elearning_template_new', | |
| 148 | + 'is_pro' => true, | |
| 149 | + ), | |
| 150 | + 'elearning-res-theme-five' => array( | |
| 151 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-5.png', | |
| 152 | + '_template' => 'elearning_template_new', | |
| 153 | + 'is_pro' => true, | |
| 154 | + ), | |
| 155 | + 'elearning-res-theme-six' => array( | |
| 156 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-6.png', | |
| 157 | + '_template' => 'maps_template_new', | |
| 158 | + 'is_pro' => true, | |
| 159 | + ), | |
| 160 | + 'elearning-res-theme-seven' => array( | |
| 161 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-7.png', | |
| 162 | + '_template' => 'elearning_template_sales_count', | |
| 163 | + 'is_pro' => true, | |
| 164 | + ), | |
| 165 | + 'elearning-res-theme-eight' => array( | |
| 166 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-8.png', | |
| 167 | + '_template' => 'elearning_template_sales_count', | |
| 168 | + 'is_pro' => true, | |
| 169 | + ), | |
| 170 | + 'res-theme-nine' => array( | |
| 171 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-9.png', | |
| 172 | + '_template' => 'elearning_template_sales_count', | |
| 173 | + 'is_pro' => true, | |
| 174 | + ), | |
| 175 | + 'elearning-res-theme-ten' => array( | |
| 176 | + 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_elearning/elearning-res-theme-10.png', | |
| 177 | + '_template' => 'maps_template_new', | |
| 178 | + 'is_pro' => true, | |
| 179 | + ), | |
| 180 | + ]; | |
| 181 | + $this->templates = [ | |
| 182 | + 'elearning_template_new' => [ | |
| 183 | + 'first_param' => GlobalFields::get_instance()->common_name_fields(), | |
| 184 | + 'third_param' => [ | |
| 185 | + 'tag_course_title' => __('Course Title', 'notificationx'), | |
| 186 | + ], | |
| 187 | + 'fourth_param' => [ | |
| 188 | + 'tag_time' => __('Definite Time', 'notificationx'), | |
| 189 | + ], | |
| 190 | + '_themes' => [ | |
| 191 | + 'elearning_theme-one', | |
| 192 | + 'elearning_theme-two', | |
| 193 | + 'elearning_theme-three', | |
| 194 | + 'elearning_theme-four', | |
| 195 | + 'elearning_theme-five', | |
| 196 | + ] | |
| 197 | + ], | |
| 198 | + 'elearning_template_sales_count' => [ | |
| 199 | + 'first_param' => GlobalFields::get_instance()->common_name_fields(), | |
| 200 | + 'third_param' => [ | |
| 201 | + 'tag_course_title' => __('Course Title', 'notificationx'), | |
| 202 | + ], | |
| 203 | + 'fourth_param' => [ | |
| 204 | + // 'tag_time' => __('Definite Time', 'notificationx'), | |
| 205 | + ], | |
| 206 | + '_themes' => [ | |
| 207 | + 'elearning_conv-theme-seven', | |
| 208 | + 'elearning_conv-theme-eight', | |
| 209 | + 'elearning_conv-theme-nine', | |
| 210 | + ] | |
| 211 | + ], | |
| 212 | + ]; | |
| 213 | + } | |
| 214 | + | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Hooked to nx_before_metabox_load action. | |
| 218 | + * | |
| 219 | + * @return void | |
| 220 | + */ | |
| 221 | + public function init_fields() { | |
| 222 | + parent::init_fields(); | |
| 223 | + add_filter('nx_link_types', [$this, 'link_types']); | |
| 224 | + add_filter('nx_content_fields', [$this, 'content_fields']); | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * Needed content fields | |
| 229 | + * @return array | |
| 230 | + */ | |
| 231 | + public function content_fields($fields) { | |
| 232 | + $content_fields = &$fields['content']['fields']; | |
| 233 | + $content_fields['ld_product_control'] = array( | |
| 234 | + 'name' => 'ld_product_control', | |
| 235 | + 'label' => __('Show Notification Of', 'notificationx'), | |
| 236 | + 'type' => 'select', | |
| 237 | + 'priority' => 200, | |
| 238 | + 'default' => 'none', | |
| 239 | + 'options' => GlobalFields::get_instance()->normalize_fields(array( | |
| 240 | + 'none' => __('All', 'notificationx'), | |
| 241 | + 'ld_course' => __('By Course', 'notificationx'), | |
| 242 | + )), | |
| 243 | + 'rules' => Rules::is('type', $this->id), | |
| 244 | + ); | |
| 245 | + | |
| 246 | + $content_fields['ld_course_list'] = array( | |
| 247 | + 'name' => 'ld_course_list', | |
| 248 | + 'label' => __('Select Course', 'notificationx'), | |
| 249 | + 'type' => 'select-async', | |
| 250 | + 'multiple' => true, | |
| 251 | + 'priority' => 201, | |
| 252 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context. | |
| 253 | + 'options' => apply_filters('nx_elearning_course_list', [ | |
| 254 | + [ | |
| 255 | + 'label' => "Type for more result...", | |
| 256 | + 'value' => null, | |
| 257 | + 'disabled' => true, | |
| 258 | + ], | |
| 259 | + ]), | |
| 260 | + 'rules' => Rules::logicalRule([ | |
| 261 | + Rules::is('type', $this->id), | |
| 262 | + Rules::is('ld_product_control', 'ld_course'), | |
| 263 | + ]), | |
| 264 | + 'ajax' => [ | |
| 265 | + 'api' => "/notificationx/v1/get-data", | |
| 266 | + 'data' => [ | |
| 267 | + 'type' => "@type", | |
| 268 | + 'source' => "@source", | |
| 269 | + 'field' => "ld_course_list", | |
| 270 | + ], | |
| 271 | + ], | |
| 272 | + ); | |
| 273 | + | |
| 274 | + return $fields; | |
| 275 | + } | |
| 276 | + | |
| 277 | + | |
| 278 | + /** | |
| 279 | + * Adds option to Link Type field in Content tab. | |
| 280 | + * | |
| 281 | + * @param array $options | |
| 282 | + * @return array | |
| 283 | + */ | |
| 284 | + public function link_types($options) { | |
| 285 | + $_options = GlobalFields::get_instance()->normalize_fields([ | |
| 286 | + 'course_page' => __('Course Page', 'notificationx'), | |
| 287 | + ], 'type', $this->id); | |
| 288 | + | |
| 289 | + return array_merge($options, $_options); | |
| 290 | + } | |
| 291 | + | |
| 292 | + public function conversion_data($saved_data, $settings) { | |
| 293 | + if ( ! empty( $saved_data['course_title'] ) ) { | |
| 294 | + $saved_data['course_title'] = wp_strip_all_tags( html_entity_decode( $saved_data['course_title'] ) ); | |
| 295 | + } | |
| 296 | + return $saved_data; | |
| 297 | + } | |
| 298 | + | |
| 299 | + public function preview_entry($entry, $settings){ | |
| 300 | + $entry = array_merge($entry, [ | |
| 301 | + "title" => "PHP Beginners – Become a PHP Master", | |
| 302 | + | |
| 303 | + ]); | |
| 304 | + return $entry; | |
| 305 | + } | |
| 306 | +} | |