better file organisation and default settings
This commit is contained in:
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -10,17 +10,6 @@ Author URI:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* global variables :
|
|
||||||
*/
|
|
||||||
|
|
||||||
$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE';
|
|
||||||
$mp_icon_url = '/wp-content/plugins/map_prof/marker.png';
|
|
||||||
$mp_icon_size = [50, 50];
|
|
||||||
$mp_icon_label_color = "red";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inclusions :
|
* inclusions :
|
||||||
*/
|
*/
|
||||||
@@ -28,6 +17,27 @@ $mp_icon_label_color = "red";
|
|||||||
include_once(dirname(__FILE__) . '/mp_console_log.php');
|
include_once(dirname(__FILE__) . '/mp_console_log.php');
|
||||||
require_once(dirname(__FILE__) . '/mp_url_api.php');
|
require_once(dirname(__FILE__) . '/mp_url_api.php');
|
||||||
require_once(dirname(__FILE__) . '/mp_add_to_scripts.php');
|
require_once(dirname(__FILE__) . '/mp_add_to_scripts.php');
|
||||||
|
require_once(dirname(__FILE__) . '/settings/mp_required.php');
|
||||||
|
require_once(dirname(__FILE__) . '/settings/mp_optionnals.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* global variables :
|
||||||
|
*/
|
||||||
|
|
||||||
|
$mp_icon_url = '/wp-content/plugins/map_prof/images/' . $mp_icon_file;
|
||||||
|
$mp_icon_size = [50, 50];
|
||||||
|
if (isset($mp_icon_size_setting)) {
|
||||||
|
if (is_array($mp_icon_size_setting)) {
|
||||||
|
if (count($mp_icon_size_setting) === 2) {
|
||||||
|
if ( is_numeric($mp_icon_size_setting[0]) && is_numeric($mp_icon_size_setting[1]) ) {
|
||||||
|
$mp_icon_size = $mp_icon_size_setting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//$mp_icon_label_color = "red";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/mp_coordinates_from_posts.php');
|
require_once(dirname(__FILE__) . '/mp_get_markers.php');
|
||||||
|
|
||||||
function mp_get_locations() {
|
function mp_php_to_js($php_var, $js_var_name) {
|
||||||
|
$js_var = 'let ' . $js_var_name . ' = ';
|
||||||
$posts_list = mp_get_published_posts();
|
$js_var .= json_encode($php_var);
|
||||||
$locs = mp_retrieve_address($posts_list);
|
$js_var .= ';';
|
||||||
|
return $js_var;
|
||||||
$locations = 'let locations = [';
|
|
||||||
foreach ($locs as $value) {
|
|
||||||
$locations .= json_encode($value);
|
|
||||||
$locations .= ',';
|
|
||||||
};
|
|
||||||
$locations .= '];';
|
|
||||||
return $locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mp_get_icon_url() {
|
|
||||||
global $mp_icon_url;
|
|
||||||
$markers =
|
|
||||||
'let icon_url = "'
|
|
||||||
. $mp_icon_url
|
|
||||||
. '";'
|
|
||||||
;
|
|
||||||
return $markers;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mp_get_icon_size() {
|
|
||||||
global $mp_icon_size;
|
|
||||||
$markers =
|
|
||||||
'let icon_size = ['
|
|
||||||
. $mp_icon_size[0]
|
|
||||||
. ", "
|
|
||||||
. $mp_icon_size[1]
|
|
||||||
. '];'
|
|
||||||
;
|
|
||||||
return $markers;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mp_get_icon_color() {
|
|
||||||
global $mp_icon_label_color;
|
|
||||||
$markers =
|
|
||||||
'let icon_label_color = "'
|
|
||||||
. $mp_icon_label_color
|
|
||||||
. '";'
|
|
||||||
;
|
|
||||||
return $markers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mp_add_to_scripts() {
|
function mp_add_to_scripts() {
|
||||||
wp_add_inline_script('mp_init_map', mp_get_locations(), 'before');
|
global $mp_icon_size;
|
||||||
wp_add_inline_script('mp_init_map', mp_get_icon_url(), 'before');
|
global $mp_icon_url;
|
||||||
wp_add_inline_script('mp_init_map', mp_get_icon_size(), 'before');
|
// global $mp_icon_label_color;
|
||||||
wp_add_inline_script('mp_init_map', mp_get_icon_color(), 'before');
|
$markers = mp_get_published_markers();
|
||||||
|
|
||||||
|
wp_add_inline_script('mp_init_map', mp_php_to_js($markers, 'locations'), 'before');
|
||||||
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_url, 'icon_url'), 'before');
|
||||||
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size, 'icon_size'), 'before');
|
||||||
|
// wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_label_color, 'icon_label_color'), 'before');
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -160,4 +160,10 @@ function mp_retrieve_address(&$posts_list) {
|
|||||||
return $locs;
|
return $locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mp_get_published_markers() {
|
||||||
|
$posts_list = mp_get_published_posts();
|
||||||
|
$markers = mp_retrieve_address($posts_list);
|
||||||
|
return $markers;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -44,7 +44,7 @@ function mp_init_map() {
|
|||||||
label = {
|
label = {
|
||||||
// text: String(count),
|
// text: String(count),
|
||||||
text: "hello",
|
text: "hello",
|
||||||
color: icon_label_color,
|
// color: icon_label_color,
|
||||||
fontSize: "12px",
|
fontSize: "12px",
|
||||||
};
|
};
|
||||||
let markers = [];
|
let markers = [];
|
||||||
|
|||||||
14
srcs/plugins/map_prof/settings/mp_optionnals.php
Normal file
14
srcs/plugins/map_prof/settings/mp_optionnals.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* les parametres suivants sont optionnels pour le fonctionnement du plugin
|
||||||
|
* le plugin fonctionne sans eux, grace a des valeurs par defauts
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* dimensions de l'icone des marqueurs */
|
||||||
|
$mp_icon_size_setting = [40, 40];
|
||||||
|
|
||||||
|
/* */
|
||||||
|
//$mp_icon_label_color = "red";
|
||||||
|
|
||||||
|
?>
|
||||||
14
srcs/plugins/map_prof/settings/mp_required.php
Normal file
14
srcs/plugins/map_prof/settings/mp_required.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* les parametres suivants sont necessaires pour le fonctionnement du plugin
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* cle api de google maps */
|
||||||
|
$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE';
|
||||||
|
|
||||||
|
/* nom du fichier image situe dans le dossier "images" */
|
||||||
|
/* pour l'icone des marqueurs sur la carte */
|
||||||
|
$mp_icon_file = 'marker.png';
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user