ID ) ? $post->ID : (int) $id; } return $post_id; } /** * Helper method for retrieving settings values. * * @since 2.0.0 * * @global int $id The current post ID. * @global object $post The current post object. * @param string $key The setting key to retrieve. * @param string $default A default value to use. * @return string Key value on success, empty string on failure. */ public function get_setting( $key, $default = false ) { // Get config $settings = get_post_meta( $this->get_id(), 'modula-album-settings', true ); // Check config key exists if ( isset( $settings[ $key ] ) ) { $value = $settings[ $key ]; } else { $value = $default ? $default : ''; } return apply_filters( 'modula_albums_admin_field_value', $value, $key, $settings ); } public function render( $metabox, $post = false ) { switch ( $metabox ) { case 'gallery': $this->_render_gallery_metabox(); break; case 'settings': $this->_render_settings_metabox(); break; case 'shortcode': $this->_render_shortcode_metabox( $post ); break; default: do_action( "modula_metabox_fields_{$metabox}" ); break; } } /** * Create HTML for gallery metabox */ private function _render_gallery_metabox() { $galleries = get_post_meta( $this->get_id(), 'modula-album-galleries', true ); $helper_guidelines = $this->get_setting( 'helpergrid' ); $max_upload_size = wp_max_upload_size(); if ( ! $max_upload_size ) { $max_upload_size = 0; } echo '
'; echo '
'; echo '
'; echo '
'; echo __( 'Galleries in the album', 'modula-albums' ); echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; // Helper Guildelines Toggle echo '
'; do_action( 'modula_albums_before_helper_grid' ); echo '
'; echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '' . esc_html__( 'Disable Helper Grid', 'modula-albums' ) . ''; echo '
'; do_action( 'modula_albums_after_helper_grid' ); echo '
'; echo '
'; } /** * Create HTML for settings metabox */ private function _render_settings_metabox() { $tabs = Modula_Album_Fields_Helper::get_tabs(); // Sort tabs based on priority. uasort( $tabs, array( 'Modula_Helper', 'sort_data_by_priority' ) ); $tabs_html = ''; $tabs_content_html = ''; $first = true; // Generate HTML for each tab. foreach ( $tabs as $tab_id => $tab ) { $tab['id'] = $tab_id; $tabs_html .= $this->_render_tab( $tab, $first ); $fields = Modula_Album_Fields_Helper::get_fields( $tab_id ); // Sort fields based on priority. uasort( $fields, array( 'Modula_Helper', 'sort_data_by_priority' ) ); $current_tab_content = '
'; // Check if our tab have title & description if ( isset( $tab['title'] ) || isset( $tab['description'] ) ) { $current_tab_content .= '
'; $current_tab_content .= '
'; if ( isset( $tab['title'] ) && '' != $tab['title'] ) { $current_tab_content .= '

' . esc_html( $tab['title'] ) . '

'; } if ( isset( $tab['description'] ) && '' != $tab['description'] ) { $current_tab_content .= '
[?]'; $current_tab_content .= '
' . wp_kses_post( $tab['description'] ) . '
'; $current_tab_content .= '
'; } $current_tab_content .= '
'; $current_tab_content .= '
'; $current_tab_content .= apply_filters('modula_admin_documentation_link', '' . esc_html__( 'Documentation', 'modula-albums' ) . ''); $current_tab_content .= ' - or - '; $current_tab_content .= apply_filters('modula_admin_contact_link', '' . esc_html__( 'Get in touch', 'modula-albums' ) . ''); $current_tab_content .= '
'; $current_tab_content .= '
'; } // Generate all fields for current tab $current_tab_content .= '
'; $current_tab_content .= ''; foreach ( $fields as $field_id => $field ) { $field['id'] = $field_id; $current_tab_content .= $this->_render_row( $field ); } $current_tab_content .= '
'; // Filter to add extra content to a specific tab $current_tab_content .= apply_filters( 'modula_' . $tab_id . '_tab_content', '' ); $current_tab_content .= '
'; $current_tab_content .= '
'; $tabs_content_html .= $current_tab_content; if ( $first ) { $first = false; } } $html = '
%s
%s
'; printf( $html, $tabs_html, $tabs_content_html ); } /** * Create HTML for shortcode metabox */ private function _render_shortcode_metabox( $post ) { do_action( 'modula_albums_admin_before_shortcode_metabox', $post ); $shortcode = '[modula-album id="' . $post->ID . '"]'; echo '
'; echo ''; echo ''; echo '

' . sprintf( esc_html__( 'You can use this to display your newly created album inside a %s post or a page %s', 'modula-albums'), '', '' ) . '

'; echo '
'; do_action( 'modula_albums_admin_after_shortcode_metabox', $post ); } /** * Create HTML for a tab */ private function _render_tab( $tab, $first = false ) { $icon = ''; $badge = ''; if ( isset( $tab['icon'] ) ) { $icon = ''; } if ( isset( $tab['badge'] ) ) { $badge = '' . esc_html( $tab['badge'] ) . ''; } return '
' . $icon . wp_kses_post( $tab['label'] ) . $badge . '
'; } /** * Create HTML for a row */ private function _render_row( $field ) { $child = ''; if(isset($field['is_child']) && $field['is_child'] && is_bool($field['is_child'])){ $child = 'child_setting'; } if(isset($field['is_child']) && $field['is_child'] && is_string($field['is_child'])){ $child = $field['is_child'].'_child_setting'; } $format = '%s%s'; if ( 'textarea' == $field['type'] || 'custom_code' == $field['type'] ) { $format = '%s
%s
'; } $format = apply_filters( "modula_field_type_{$field['type']}_format", $format, $field ); $default = ''; // Check if our field have a default value if ( isset( $field['default'] ) ) { $default = $field['default']; } // Generate tooltip $tooltip = ''; if ( isset( $field['description'] ) && '' != $field['description'] ) { $tooltip .= '
[?]'; $tooltip .= '
' . wp_kses_post( $field['description'] ) . '
'; $tooltip .= '
'; } // Get the current value of the field $value = $this->get_setting( $field['id'], $default ); return sprintf( $format, wp_kses_post( $field['name'] ), $tooltip, $this->_render_field( $field, $value ) ); } /** * Create HTML for a field */ private function _render_field( $field, $value = '' ) { $html = ''; switch ( $field['type'] ) { case 'text': $html = ''; break; case 'image-size': $html = '
'; $html .= ''; $html .= 'x'; $html .= ''; $html .= 'px'; $html .= '
'; break; case 'select' : $html = ''; break; case 'dimensions-select' : $sizes = Modula_Album_Fields_Helper::get_image_sizes(); $html = ''; if ( '' != $infos ) { $html .= '
' . $infos . '
'; } break; case 'ui-slider': $min = isset( $field['min'] ) ? $field['min'] : 0; $max = isset( $field['max'] ) ? $field['max'] : 100; $step = isset( $field['step'] ) ? $field['step'] : 1; if ( '' === $value ) { if ( isset( $field['default'] ) ) { $value = $field['default']; }else{ $value = $min; } } $attributes = 'data-min="' . esc_attr( $min ) . '" data-max="' . esc_attr( $max ) . '" data-step="' . esc_attr( $step ) . '"'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; break; case 'color' : $html .= '
'; $html .= ''; $html .= '
'; break; case "toggle": $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '
'; $html .= '
'; break; case "custom_code": $html = '
'; $html .= ''; $html .= '
'; break; case "hover-effect": $hovers = Modula_Albums_Hover_Effects::get_hover_effects(); $html .= ''; $html .= '

' . esc_html__( 'Select an hover effect', 'modula-albums' ) . '

'; // Creates effects preview $html .= ''; // Hook to change how hover effects field is rendered $html = apply_filters( "modula_render_hover_effect_field_type", $html, $field ); break; case "cursor_upload": $style = array( 'upload' => '', 'replace' => 'display:none;', 'delete' => 'display:none;', ); if ( 0 != absint( $value ) ) { $style['upload'] = 'display:none;'; $style['replace'] = ''; $style['delete'] = ''; } $html = ''; $html .= '
'; if ( $value ) { $image = wp_get_attachment_image_src( $value ); if ( $image ) { $html .= ''; } } $html .= '
'; $html .= ''; $html .= ''; $html .= ''; break; case 'textarea-placeholder' : $html = '
'; $html .= ''; $html .= '
'; $html .= '
'; foreach ( $field['values'] as $key => $value ) { $html .= ""; $html .= esc_html__( $value, 'modula-albums' ); $html .= ''; } $html .= '
'; break; case 'placeholder' : $html = ''; $html .= '
'; foreach ( $field['values'] as $key => $value ) { $html .= ""; $html .= esc_html__( $value, 'modula-albums' ); $html .= ''; } $html .= '
'; break; default: /* Filter for render custom field types */ $html = apply_filters( "modula_render_{$field['type']}_field_type", $html, $field, $value ); break; } return $html; } }