Skip to content

Commit

Permalink
* Changed taxonomy icon selector to new version where icon class can …
Browse files Browse the repository at this point in the history
…be pasted in - CHANGED
  • Loading branch information
stiofan committed Oct 11, 2023
1 parent 20d2de7 commit ffa9b3a
Show file tree
Hide file tree
Showing 17 changed files with 2,354 additions and 84 deletions.
26 changes: 8 additions & 18 deletions includes/admin/class-geodir-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,6 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?
// Select boxes
case 'font-awesome' :
// include the font-awesome data
include_once( dirname( __FILE__ ) . '/settings/data_fontawesome.php' );
$value['options'] = geodir_font_awesome_array();
$rating_color = geodir_get_option('rating_color','#ff9900');

Expand All @@ -1438,23 +1437,18 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?
$option_value = self::get_option( $value['id'], $value['default'] );
}

$options = array();

// print_r( $value['options'] );exit;

foreach ( $value['options'] as $key => $val ) {
$options[] = array(
'label' => esc_attr($key),
'value' => esc_attr($key),
'extra_attributes' => array(
'data-fa-icon' => esc_attr( $key )
)
);
// if Font Awesome pro is enabled then add a notice other variants can be used.
if ( defined( 'FAS_PRO' ) && FAS_PRO ) {
$value['custom_attributes'] = $value['custom_attributes'] + array(
'data-fa-icons' => true,
'data-bs-toggle' => "tooltip",
'data-bs-trigger' => "focus",
'title' => __( 'For pro icon variants (light, thin, duotone), paste the class here', 'geodirectory' ),
);
}


//@todo we should change this to a better icon picker

echo aui()->input(
array(
'type' => 'iconpicker',
Expand All @@ -1463,11 +1457,7 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?
'label_type' => $label_type,
'label_col' => '3',
'label_class'=> 'font-weight-bold fw-bold',
//'multiple' => 'multiselect' == $value['type'] ? true : false,
'class' => $value['class'],
//'required' => true,
//'select2' => false,//strpos($value['class'], 'geodir-select') !== false ? true : false,
// 'options' => $options,
'wrap_class' => isset($value['advanced']) && $value['advanced'] ? geodir_advanced_toggle_class() : '',
'label' => $value['title'] . $tooltip_html,
'placeholder' => $value['placeholder'],
Expand Down
76 changes: 49 additions & 27 deletions includes/admin/class-geodir-admin-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GeoDir_Admin_Taxonomies {
* @since 2.0.0
*/
private $taxonomy = '';

/**
* Taxonomy type.
*
Expand Down Expand Up @@ -55,24 +55,24 @@ public function __construct() {
if ( empty( $_REQUEST['taxonomy'] ) ) {
return;
}
$this->taxonomy = $_REQUEST['taxonomy'];

$this->taxonomy = esc_attr( $_REQUEST['taxonomy'] );

if ( !geodir_is_gd_taxonomy( $this->taxonomy ) ) {
return;
}

$this->type = geodir_taxonomy_type( $this->taxonomy );

if ( $this->type == 'category' ) {
// Add fields
add_action( $this->taxonomy . '_add_form_fields', array( $this, 'add_category_fields' ), 10, 1 );
add_action( $this->taxonomy . '_edit_form_fields', array( $this, 'edit_category_fields' ), 10, 2 );

// Save fields
add_action( 'create_term', array( $this, 'save_category_fields' ), 10, 3 );
add_action( 'edit_term', array( $this, 'save_category_fields' ), 10, 3 );

// Add columns
add_filter( 'manage_edit-' . $this->taxonomy . '_columns', array( $this, 'get_columns' ) );
add_filter( 'manage_edit-' . $this->taxonomy . '_sortable_columns', array( $this, 'get_sortable_columns' ), 10, 1 );
Expand All @@ -82,6 +82,7 @@ public function __construct() {
add_action( 'created_term', array( $this, 'update_term_icons'), 10, 3 );
add_action( 'edited_term', array( $this, 'update_term_icons'), 10, 3 );
}

}

/**
Expand Down Expand Up @@ -318,7 +319,7 @@ public function add_category_fields( $taxonomy ) {
<?php echo $this->render_cat_icon(); ?>
</div>
<?php do_action( 'geodir_add_category_after_cat_icon', $taxonomy ); ?>

<div class="form-field term-ct_cat_font_icon-wrap gd-term-form-field">
<label for="ct_cat_font_icon"><?php _e( 'Category Icon', 'geodirectory' ); ?></label>
<?php echo $this->render_cat_font_icon(); ?>
Expand All @@ -330,7 +331,7 @@ public function add_category_fields( $taxonomy ) {
<?php echo $this->render_cat_color(); ?>
</div>
<?php do_action( 'geodir_add_category_after_cat_color', $taxonomy ); ?>

<div class="form-field term-ct_cat_schema-wrap gd-term-form-field ">
<label for="ct_cat_schema"><?php _e( 'Schema Type', 'geodirectory' ); ?></label>
<?php echo $this->render_cat_schema(); ?>
Expand Down Expand Up @@ -470,11 +471,11 @@ public function render_cat_default_img( $default_img = array(), $id = 'ct_cat_de
if ( empty( $name ) ) {
$name = $id;
}

$img_id = !empty( $default_img['id'] ) ? $default_img['id'] : '';
$img_src = !empty( $default_img['src'] ) ? $default_img['src'] : '';
$show_img = !empty( $default_img['full'] ) ? $default_img['full'] : admin_url( 'images/media-button-image.gif' );

ob_start();
?>
<div class="gd-upload-img" data-field="<?php echo $name; ?>">
Expand Down Expand Up @@ -505,11 +506,11 @@ public function render_cat_icon( $cat_icon = array(), $id = 'ct_cat_icon', $name
if ( empty( $name ) ) {
$name = $id;
}

$img_id = !empty( $cat_icon['id'] ) ? $cat_icon['id'] : '';
$img_src = !empty( $cat_icon['src'] ) ? $cat_icon['src'] : '';
$show_img = !empty( $cat_icon['full'] ) ? $cat_icon['full'] : admin_url( 'images/media-button-image.gif' );

ob_start();
?>
<div class="gd-upload-img" data-field="<?php echo $name; ?>">
Expand Down Expand Up @@ -541,6 +542,26 @@ public function render_cat_font_icon( $cat_icon = '', $id = 'ct_cat_font_icon',
$name = $id;
}
ob_start();

if ( geodir_design_style() ) {
echo aui()->input(
array(
'type' => 'iconpicker',
'id' => $id,
'name' => $name,
'label_col' => '3',
'label_class'=> 'font-weight-bold fw-bold',
'wrap_class' => 'bsui',
'value' => $cat_icon,
'extra_attributes' => defined('FAS_PRO') && FAS_PRO ? array(
'data-fa-icons' => true,
'data-bs-toggle' => "tooltip",
'data-bs-trigger' => "focus",
'title' => __('For pro icon variants (light, thin, duotone), paste the class here','geodirectory'),
) : array(),
)
);
}else{
?>
<select
name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $id ); ?>"
Expand All @@ -559,6 +580,7 @@ class="regular-text geodir-select postform"
}
?>
</select>
<?php } ?>
<p class="description clear"><?php _e( 'Select a category icon', 'geodirectory' ); ?></p>
<?php
return ob_get_clean();
Expand Down Expand Up @@ -606,11 +628,11 @@ class="gd-color-picker"
*/
public function render_cat_schema( $cat_schema = '', $id = 'ct_cat_schema', $name = '' ) {
$schemas = self::get_schemas();

if ( empty( $name ) ) {
$name = $id;
}

ob_start();
?>
<select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $id ); ?>" class="postform geodir-select">
Expand Down Expand Up @@ -646,20 +668,20 @@ public function save_category_fields( $term_id, $tt_id = '', $taxonomy = '' ) {
// Category listing default image.
if ( isset( $_POST['ct_cat_default_img'] ) ) {
$cat_default_img = $_POST['ct_cat_default_img'];

if ( !empty( $cat_default_img['src'] ) ) {
$cat_default_img['src'] = geodir_file_relative_url( $cat_default_img['src'] );
} else {
$cat_default_img = array();
}

update_term_meta( $term_id, 'ct_cat_default_img', $cat_default_img );
}

// Category icon.
if ( isset( $_POST['ct_cat_icon'] ) ) {
$cat_icon = $_POST['ct_cat_icon'];

if ( !empty( $cat_icon['src'] ) ) {
$cat_icon['src'] = geodir_file_relative_url( $cat_icon['src'] );
} elseif(!empty($_POST['ct_cat_font_icon'])) {
Expand All @@ -680,12 +702,12 @@ public function save_category_fields( $term_id, $tt_id = '', $taxonomy = '' ) {
if ( isset( $_POST['ct_cat_color'] ) ) {
update_term_meta( $term_id, 'ct_cat_color', sanitize_hex_color( $_POST['ct_cat_color'] ) );
}

// Category schema.
if ( isset( $_POST['ct_cat_schema'] ) ) {
update_term_meta( $term_id, 'ct_cat_schema', sanitize_text_field( $_POST['ct_cat_schema'] ) );
}

do_action( 'geodir_term_save_category_fields', $term_id, $tt_id, $taxonomy );
}

Expand All @@ -702,7 +724,7 @@ public function regenerate_term_icon( $term_id ){
$this->generate_cat_icon($icon,$color);
return true;
}

return false;
}

Expand Down Expand Up @@ -741,7 +763,7 @@ public function generate_cat_icon($icon,$color){
}
}


return $cat_icon;
}

Expand Down Expand Up @@ -770,7 +792,7 @@ public function get_columns( $columns ) {

return $columns;
}

/**
* Get sortable columns.
*
Expand All @@ -779,7 +801,7 @@ public function get_columns( $columns ) {
*/
public function get_sortable_columns( $columns ) {
$columns['cat_ID_num'] = 'term_id';

return $columns;
}

Expand All @@ -795,7 +817,7 @@ public function get_column( $columns, $column, $id ) {
if ( $column == 'cat_ID_num' ) {
$columns .= $id;
}

if ( $column == 'cat_icon' && $icon = geodir_get_cat_icon( $id, true, true ) ) {
$columns .= '<img src="' . esc_url( $icon ) . '" />';
}
Expand Down Expand Up @@ -955,7 +977,7 @@ public static function get_category_select($post_type = '', $selected = '', $is_

/**
* Return the schemas options as an array.
*
*
* @return mixed|void
*/
public static function get_schemas(){
Expand Down Expand Up @@ -1119,7 +1141,7 @@ public function on_delete_term( $term, $tt_id, $taxonomy = '', $deleted_term = a

if ( $post_type ) {
$table = geodir_db_cpt_table( $post_type );

foreach ( $object_ids as $post_id ) {
$post_tags = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) );
$post_tags = ! empty( $post_tags ) && ! is_wp_error( $post_tags ) ? array_map( 'trim', $post_tags ) : '';
Expand Down
1 change: 0 additions & 1 deletion includes/admin/settings/class-geodir-settings-cpt-cf.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function init_hooks() {
add_action( 'geodir_manage_available_fields_custom', array( $this, 'output_custom_fields' ) );
}

add_action( 'admin_footer', array( $this, 'font_awesome_select' ) );
}

/**
Expand Down
1 change: 1 addition & 0 deletions includes/admin/settings/class-geodir-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct() {
* Get font awesome selectbox.
*
* @since 2.0.0
* @deprecated 2.3.26
*/
public function font_awesome_select(){
?>
Expand Down
11 changes: 6 additions & 5 deletions includes/admin/settings/data_fontawesome.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// @todo i don't think this is used in core anymore, we should check extensions and remove if not.
// Font Awesome v. 5

function geodir_font_awesome_array() {
Expand All @@ -17,10 +18,10 @@ function geodir_font_awesome_array() {
}

/**
* Free Icons
* Free Icons
*/
function geodir_font_awesome_free_array() {
return array(
return array(
'fab fa-500px' => 'f26e',
'fab fa-accessible-icon' => 'f368',
'fab fa-accusoft' => 'f369',
Expand Down Expand Up @@ -1614,10 +1615,10 @@ function geodir_font_awesome_free_array() {
}

/**
* Pro Icons
* Pro Icons
*/
function geodir_font_awesome_pro_array() {
return array(
return array(
'fas fa-abacus' => 'f640',
'far fa-abacus' => 'f640',
'fal fa-abacus' => 'f640',
Expand Down Expand Up @@ -6024,4 +6025,4 @@ function geodir_font_awesome_pro_array() {
'fal fa-yin-yang' => 'f6ad'
);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@
'type' => 'iconpicker',
'wrap_class' => geodir_advanced_toggle_class(),
'value' => $value,
'extra_attributes' => defined('FAS_PRO') && FAS_PRO ? array(
'data-fa-icons' => true,
'data-bs-toggle' => "tooltip",
'data-bs-trigger' => "focus",
'title' => __('For pro icon variants (light, thin, duotone), paste the class here','geodirectory'),
) : array(),
)
);

Expand Down
7 changes: 6 additions & 1 deletion includes/admin/views/html-admin-settings-cpt-tab-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</div>
<script type="text/template" class="dd-setting <?php echo 'dd-type-'.esc_attr( $tab->tab_type );?> d-none ">
<?php
//include_once( dirname( __FILE__ ) . '/../settings/data_fontawesome.php' );
echo geodir_notification( array('info'=>__('Name and Icon settings are not used for sub items except fieldset.','geodirectory')) );

echo aui()->input(
Expand All @@ -36,6 +35,12 @@
'label' => __('Icon','geodirectory'),
'type' => 'iconpicker',
'value' => esc_attr($tab->tab_icon),
'extra_attributes' => defined('FAS_PRO') && FAS_PRO ? array(
'data-fa-icons' => true,
'data-bs-toggle' => "tooltip",
'data-bs-trigger' => "focus",
'title' => __('For pro icon variants (light, thin, duotone), paste the class here','geodirectory'),
) : array(),
)
);

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ __WARNING: GDv2 is a significant update over GDv1 and may require manual work, s

= GeoDirectory Business Directory Plugin v2.3.27 =
* OSM map do not load properly when rendered in hidden element - FIXED
* Changed taxonomy icon selector to new version where icon class can be pasted in - CHANGED

= GeoDirectory Business Directory Plugin v2.3.26 - 2023-10-06 =
* Validate revision ID belongs to parent on revision save or the wrong media files can be removed - FIXED
Expand Down
Loading

0 comments on commit ffa9b3a

Please sign in to comment.