*/ class Aec_Shortcodes { /** * The AEC client instance name. * * @since 1.0.0 * @access private * @var string $client_instance The AEC client instance name. */ private $client_instance; /** * Initialize the class and set its properties. * * @param string $client_instance The AEC client instance name. * @since 1.0.0 */ public function __construct( $client_instance ) { $this->client_instance = $client_instance; } /** * Combine user attributes with known attributes and fill in defaults when needed. Also checks URL query string. * * @param $pairs array Entire list of supported attributes and their defaults. * @param $atts array User defined attributes in shortcode tag. * @return array */ private function parse_atts( $pairs, $atts ) { $atts = (array)$atts; $out = array(); foreach( $pairs as $name => $default ) { if( array_key_exists( $name, $atts ) ) { $out[$name] = $atts[$name]; } else if( isset( $_GET[$name] ) ) { $out[$name] = sanitize_text_field($_GET[$name]); } else { $out[$name] = $default; } } if( !empty( $atts ) ) { foreach( $atts as $name => $unknow_att ) { if( !array_key_exists( $name, $out ) ) { $out[$name] = $unknow_att; } } } return $out; } /** * Get webapp components data parameters from shortcode attributes. * * @param $atts array User defined attributes in shortcode tag. * @return string */ private function get_data_from_attributes( $atts ) { $atts = (array)$atts; $data = 'data-instance="' . $this->client_instance . '"'; foreach( $atts as $key => $value ) { $data .= ' data-param-' . str_replace( '_', '-', $key ) . '="' . do_shortcode( str_replace( [ '{', '}' ], [ '[', ']' ], $value ) ) . '"'; } return $data; } /** * Get course details URL * * Returns course details page URL based on polylang language and * 1. Setting option * 2. In shortcode property * 3. Extranet URL * * @param $attrs array User defined attributes in shortcode tag. * @return array * @since 1.1.4 */ private function set_course_detail_page_url( $atts ) { $atts = (array)$atts; $url = get_option( 'aec_course_detail_page_url' ); $is_pll_active = function_exists( 'pll_get_post' ); $is_wpml_active = has_filter( 'wpml_permalink' ); if( !$url ) { $url = $atts['course-detail-page-url']; } if( !$url ) { return $atts; } $post_id = url_to_postid( $url ); if( $is_pll_active && $post_id ) { $atts['course-detail-page-url'] = get_permalink( pll_get_post( $post_id ) ); } else if( $is_wpml_active && defined( 'ICL_LANGUAGE_CODE' ) ) { $atts['course-detail-page-url'] = apply_filters( 'wpml_permalink', $url, ICL_LANGUAGE_CODE, true ); } return $atts; } /** * Webapp AEC account creation form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_account_creation( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC events list. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_events_list( $atts ) { $atts = $this->parse_atts( [ 'detail_link' => '', ], $atts ); $atts['event-url'] = $atts['detail_link']; return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '" class="listing">
'; } /** * Webapp AEC next events. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_next_events( $atts ) { $atts = $this->parse_atts( [ 'detail_link' => '', 'quantity-column' => 3, ], $atts ); $atts['event-url'] = $atts['detail_link']; return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC event detail. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_event_detail( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC events list grid. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_events_list_grid( $atts ) { $atts = $this->parse_atts( [ 'detail_link' => '', 'quantity-column' => 3, ], $atts ); $atts['event-url'] = $atts['detail_link']; return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC events list wide. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_events_list_wide( $atts ) { $atts = $this->parse_atts( [ 'detail_link' => '', ], $atts ); $atts['event-url'] = $atts['detail_link']; return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC classes. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_classes( $atts ) { $atts = $this->set_course_detail_page_url( $atts ); return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC course detail. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_class_detail( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC contact map. * * @param $atts * @return string * @since 1.0.0 */ public function webapp_contact_map( $atts = [] ) { $atts = $this->parse_atts( [ 'display-details' => 'true', 'etablishment_id' => 0, 'height' => 500 ], $atts ); $atts['etablishment-branch-id'] = $atts['etablishment_id']; $atts['height'] .= 'px'; return "
get_data_from_attributes( $atts )} data-param-lang='" . AEC()->get_locale() . "'>
"; } /** * Webapp AEC google maps. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_google_map( $atts ) { if( empty( $atts ) ) return ''; $atts = $this->parse_atts( [ 'etablishment-branch-id' => 0, 'height' => 380 ], $atts ); $atts['height'] .= 'px'; return "
get_data_from_attributes( $atts )} data-param-lang='" . AEC()->get_locale() . "'>
"; } /** * Webapp AEC private tuition form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_private_tuition( $atts ) { $atts = $this->set_course_detail_page_url( $atts ); return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC class selection. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_class_selection( $atts ) { $atts = $this->set_course_detail_page_url( $atts ); return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC products list. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_products_list( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC donation form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_donation_form( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student login form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_student_login( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student password recover form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.11 */ public function webapp_student_password_recover( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student password update form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.1.6 */ public function webapp_student_password_update( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student password reset form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.11 */ public function webapp_student_password_reset( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student registration form. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_student_register( $atts ) { return '
get_data_from_attributes( $atts ) . ' data-param-form_action="create_student" data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student account. * * @return string * @since 1.0.0 */ public function webapp_student_account() { return '
'; } /** * Webapp AEC student account dashboard. * * @return string * @since 1.0.0 */ public function webapp_student_account_dashboard() { return '
'; } /** * Webapp AEC student controls. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_student_controls( $atts ) { $atts = $this->parse_atts( [ 'is-wordpress-site' => '', 'login-link' => '', 'register-link' => '', 'account-link' => '', 'logout-link' => '', 'my-cart-link' => '', ], $atts ); return "
get_data_from_attributes( $atts )} data-param-lang='" . AEC()->get_locale() . "'>
"; } /** * Webapp AEC class list with filters. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_classes_list_with_filters( $atts ) { $atts = $this->set_course_detail_page_url( $atts ); $atts = $this->parse_atts( [ 'etablishment-branch-id' => '', 'period-id' => '', 'classification-id' => '', 'subject-id' => '', 'class-type-id' => '', 'main-level' => '', 'levels-to-filter-by' => '', 'show-filter-choices' => true, 'class-types-to-filter-by' => '', ], $atts ); return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '" >
'; } /** * Webapp AEC classes catalog. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_classes_catalog( $atts ) { $atts = $this->set_course_detail_page_url( $atts ); $atts = $this->parse_atts( [ 'etablishment-branch-id' => '', 'period-id' => '', 'classification-id' => '', 'subject-id' => '', 'class-type-id' => '', 'level-id' => '', 'sidebar' => '', 'show-filter-choices' => '', ], $atts ); return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC courses search bar. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.0 */ public function webapp_classes_search_box( $atts ) { if( isset( $atts['url-configuration'] ) ) { $atts['url-configuration'] = htmlentities( trim( $atts['url-configuration'] ) ); } return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } /** * Webapp AEC student account. * * @return string * @since 1.0.4 */ public function webapp_shopping_cart() { return '
'; } /** * Webapp AEC examination list. * * @param $atts array User defined attributes in shortcode tag. * @return string * @since 1.0.4 */ public function webapp_examination_list( $atts ) { $atts = $this->parse_atts( [ 'examination-type-ids' => '', 'show-category-title' => '', ], $atts ); return '
get_data_from_attributes( $atts ) . ' data-param-lang="' . AEC()->get_locale() . '">
'; } }