Compare commits

..

1 Commits

Author SHA1 Message Date
ba9eebe2fa Add: Utils for migration 2023-01-09 15:35:54 +01:00
5 changed files with 929 additions and 375 deletions

View File

@ -1,189 +0,0 @@
div.datepicker {
position: relative;
width: 196px;
height: 147px;
position: absolute;
cursor: default;
top: 0;
left: 0;
display: none;
}
.datepickerContainer {
background: white;
position: absolute;
top: 10px;
left: 10px;
}
.datepickerBorderT {
position: absolute;
left: 10px;
top: 0;
right: 10px;
height: 10px;
background: url(../img/datepicker_t.png);
}
.datepickerBorderB {
position: absolute;
left: 10px;
bottom: 0;
right: 10px;
height: 10px;
background: url(../img/datepicker_b.png);
}
.datepickerBorderL {
position: absolute;
left: 0;
bottom: 10px;
top: 10px;
width: 10px;
background: url(../img/datepicker_l.png);
}
.datepickerBorderR {
position: absolute;
right: 0;
bottom: 10px;
top: 10px;
width: 10px;
background: url(../img/datepicker_r.png);
}
.datepickerBorderTL {
position: absolute;
top: 0;
left: 0;
width: 10px;
height: 10px;
background: url(../img/datepicker_tl.png);
}
.datepickerBorderTR {
position: absolute;
top: 0;
right: 0;
width: 10px;
height: 10px;
background: url(../img/datepicker_tr.png);
}
.datepickerBorderBL {
position: absolute;
bottom: 0;
left: 0;
width: 10px;
height: 10px;
background: url(../img/datepicker_bl.png);
}
.datepickerBorderBR {
position: absolute;
bottom: 0;
right: 0;
width: 10px;
height: 10px;
background: url(../img/datepicker_br.png);
}
.datepickerHidden {
display: none;
}
div.datepicker table {
border-collapse:collapse;
}
div.datepicker a {
color: #222;
text-decoration: none;
cursor: default;
outline: none;
}
div.datepicker table td {
text-align: right;
padding: 0;
margin: 0;
}
div.datepicker th {
text-align: center;
color: #999;
font-weight: normal;
}
div.datepicker tbody th {
text-align: left;
}
div.datepicker tbody a {
display: block;
}
.datepickerDays a {
width: 20px;
line-height: 16px;
height: 16px;
padding-right: 2px;
}
.datepickerYears a,
.datepickerMonths a{
width: 44px;
line-height: 36px;
height: 36px;
text-align: center;
}
td.datepickerNotInMonth a {
color: #eee;
}
tbody.datepickerDays td.datepickerSelected{
background: #ccc;
}
tbody.datepickerDays td.datepickerNotInMonth.datepickerSelected {
background: #17384d;
}
tbody.datepickerYears td.datepickerSelected,
tbody.datepickerMonths td.datepickerSelected{
background: #17384d;
}
div.datepicker a:hover,
div.datepicker a:hover {
color: red;
}
div.datepicker td.datepickerNotInMonth a:hover {
color: #999;
}
div.datepicker tbody th {
text-align: left;
}
.datepickerSpace div {
width: 20px;
}
.datepickerGoNext a,
.datepickerGoPrev a,
.datepickerMonth a {
text-align: center;
height: 20px;
line-height: 20px;
}
.datepickerGoNext a {
float: right;
width: 20px;
}
.datepickerGoPrev a {
float: left;
width: 20px;
}
table.datepickerViewDays tbody.datepickerMonths,
table.datepickerViewDays tbody.datepickerYears {
display: none;
}
table.datepickerViewMonths tbody.datepickerDays,
table.datepickerViewMonths tbody.datepickerYears,
table.datepickerViewMonths tr.datepickerDoW {
display: none;
}
table.datepickerViewYears tbody.datepickerDays,
table.datepickerViewYears tbody.datepickerMonths,
table.datepickerViewYears tr.datepickerDoW {
display: none;
}
td.datepickerDisabled a,
td.datepickerDisabled.datepickerNotInMonth a{
color: #333;
}
td.datepickerDisabled a:hover {
color: #333;
}
td.datepickerSpecial a {
background: #700;
}
td.datepickerSpecial.datepickerSelected a {
background: #a00;
}

View File

@ -1,18 +0,0 @@
#map_canvas, #map_canvas_options{width:100%; height:400px;}
#sound-att-table {width:100%; table-layout: fixed; word-break: break-word; border-collapse: collapse;}
#sound-att-table th{text-align:left;}
#sound-att-table .soundmap-att-left{width:60%; padding-right:6px}
#sound-att-table tr {border-bottom:1px solid #666;}
#sound-att-table td {padding: 3px 0;}
.uploadFileQueued{
height:36px;
margin:10px 0;
}
.filename{
position:relative;
margin-top:10px;
font-weight: bold;
}

View File

@ -1,135 +0,0 @@
#map_canvas, #map_canvas_options{width:100%; height:400px;}
#sound-att-table {width:100%; table-layout: fixed; word-break: break-word; border-collapse: collapse;}
#sound-att-table th{text-align:left;}
#sound-att-table .soundmap-att-left{width:60%; padding-right:6px}
#sound-att-table tr {border-bottom:1px solid #666;}
#sound-att-table td {padding: 3px 0;}
#sound-att-table .soundmap-att-left span{
float: left;
}
.uploadFileQueued{
height:36px;
margin:10px 0;
}
.filename{
position:relative;
margin-top:10px;
font-weight: bold;
}
#uploader_drop{
height: 100px;
width: 100%;
}
#uploader{
}
#uploader_drop.hover{
background-color: #94cde7;
}
#uploader_over.hover{
display: block;
}
#uploader_buttons{
text-align: center;
width: 100%;
margin-top: 20px;
}
#uploader_buttons h4{
border: 0;
background-image: none;
background-color: transparent;
font-size: 18px;
margin-bottom: 5px;
font-weight: normal;
}
.fileItem{
height: 40px;
}
.fileItem .fileName{
margin-left: 10px;
}
.meter {
height: 8px; /* Can be anything */
position: relative;
background: #555;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
padding: 0px;
-webkit-box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
-moz-box-shadow : inset 0 -1px 1px rgba(255,255,255,0.3);
box-shadow : inset 0 -1px 1px rgba(255,255,255,0.3);
}
.meter > span {
display: block;
height: 100%;
-webkit-border-top-right-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
-moz-border-radius-topright: 8px;
-moz-border-radius-bottomright: 8px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
-webkit-border-top-left-radius: 20px;
-webkit-border-bottom-left-radius: 20px;
-moz-border-radius-topleft: 20px;
-moz-border-radius-bottomleft: 20px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
background-color: rgb(43,194,83);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(43,194,83)),
color-stop(1, rgb(84,240,84))
);
background-image: -webkit-linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
background-image: -moz-linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
background-image: -ms-linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
background-image: -o-linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
-webkit-box-shadow:
inset 0 2px 9px rgba(255,255,255,0.3),
inset 0 -2px 6px rgba(0,0,0,0.4);
-moz-box-shadow:
inset 0 2px 9px rgba(255,255,255,0.3),
inset 0 -2px 6px rgba(0,0,0,0.4);
position: relative;
overflow: hidden;
}
.file-delete{
display: block;
width: 11px;
height: 11px;
background-image: url(../img/delete.png);
float: right;
margin-top: 3px;
}

View File

@ -130,6 +130,7 @@ if (!class_exists('Soundmap')){
if ($files){ if ($files){
foreach($files as $file) { foreach($files as $file) {
$data = wp_prepare_attachment_for_js( $file ); $data = wp_prepare_attachment_for_js( $file );
if (is_array($data)) :
$out .= "<div class='soundmap-attach-item'> $out .= "<div class='soundmap-attach-item'>
<!-- <div class='att-icon'><img src='{$data['icon']}'/></div> --> <!-- <div class='att-icon'><img src='{$data['icon']}'/></div> -->
<div class='att-info'><strong>{$data['title']}</strong><br/> <div class='att-info'><strong>{$data['title']}</strong><br/>
@ -137,6 +138,7 @@ if (!class_exists('Soundmap')){
<source src='{$data['url']}' type='{$data['mime']}'> <source src='{$data['url']}' type='{$data['mime']}'>
</audio><br/> </audio><br/>
<a href='#' class='delete-att-item'>Borrar</a></div><div class='clear'></div><input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>"; <a href='#' class='delete-att-item'>Borrar</a></div><div class='clear'></div><input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
endif;
} }
} }
echo '<div id="soundmap-attachments-list">' . $out . '</div>'; echo '<div id="soundmap-attachments-list">' . $out . '</div>';
@ -395,31 +397,133 @@ if (!class_exists('Soundmap')){
/* REST API Options */ /* REST API Options */
add_action('rest_api_init', function() { add_action('rest_api_init', function() {
register_rest_field('marker','georeference',
array( /* REST API expand fields */
'get_callback' => 'marker_get_georeference',
'schema' => null
)
);
});
add_action('rest_api_init',function() {
register_rest_field('marker','media', register_rest_field('marker','media',
array( array(
'get_callback' => 'marker_get_media', 'get_callback' => 'marker_get_media',
'schema' => null 'schema' => null
) )
); );
});
add_action('rest_api_init', function() {
register_rest_field('marker','author', register_rest_field('marker','author',
array( array(
'get_callback' => 'marker_get_author', 'get_callback' => 'marker_get_author',
'schema' => null 'schema' => null
) )
); );
register_rest_field('marker','georeference',
array(
'get_callback' => 'marker_get_georeference',
'schema' => null
)
);
/* REST API utils for migration - Temp functions */
register_rest_route('soundmap', '/translate/post', array(
'methods' => 'GET',
'callback' => 'soundmap_save_post_translation',
'permission_callback' => '__return_true'
));
register_rest_route('soundmap', '/translate/term', array(
'methods' => 'GET',
'callback' => 'soundmap_save_term_translation',
'permission_callback' => '__return_true'
));
}); });
function soundmap_save_term_translation($request) {
$taxonomy=$request->get_param('taxonomy');
$termA=$request->get_param('termA'); // slug
$langA=$request->get_param('langA'); // locale
$response = false;
if ( isset($taxonomy) && isset($termA) ) :
$termB = $termA."-es";
$termC = $termA."-en";
if ( term_exists($termA) && term_exists($termB) && term_exists($termC) ) :
pll_set_term_language(term_exists($termA), 'eu');
pll_set_term_language(term_exists($termB), 'es');
pll_set_term_language(term_exists($termC), 'en');
$translation = array(
'eu' => term_exists($termA),
'es' => term_exists($termB),
'en' => term_exists($termC)
);
pll_save_term_translations($translation);
$response = true;
endif;
endif;
return new WP_REST_Response($response);
}
function soundmap_post_exists( $id ) {
return is_string( get_post_status( $id ) );
}
function soundmap_save_post_translation($request) {
// http://docker:8089/wp-json/soundmap/translate/post?postA=43688&langA=es&postB=12707&langB=eu
$postA=$request->get_param('postA'); // slug
$langA=$request->get_param('langA'); // locale
//$postB=$request->get_param('postB');
//$langB=$request->get_param('langB');
$response = false;
if ( isset($postA) ) :
$pA = get_page_by_path( $postA, OBJECT, 'marker' );
$pB = get_page_by_path( $postA."-es", OBJECT, 'marker' );
$pC = get_page_by_path( $postA."-en", OBJECT, 'marker' );
//return new WP_REST_Response(get_page_by_path( "lesaka-ekaitz-elektromagnetikoa-es", OBJECT, 'marker' ));
if ( $pA && $pB && $pC ) :
pll_set_post_language($pA->ID, 'eu');
pll_set_post_language($pB->ID, 'es');
pll_set_post_language($pC->ID, 'en');
$translation = array(
'eu' => $pA->ID,
'es' => $pB->ID,
'en' => $pC->ID
);
pll_save_post_translations($translation);
$response = true;
endif;
endif;
return new WP_REST_Response($response);
}
function marker_get_georeference ($object, $field_name, $request){ function marker_get_georeference ($object, $field_name, $request){
//return $object['id']; //return $object['id'];
$lat = get_post_meta($object['id'], 'soundmap_marker_lat', true); $lat = get_post_meta($object['id'], 'soundmap_marker_lat', true);

792
soundmap.php.000 Normal file
View File

@ -0,0 +1,792 @@
<?php
/**
* @package Soundmap
*/
/*
Plugin Name: Soundmap
Plugin URI: http://www.soinumapa.net
Description: New version of the Soinumapa Plugin for creating sound maps
Version: 0.5
Author: Xavier Balderas & Luca Rullo
Author URI: http://www.audio-lab.org
License: GPLv2 or later
*/
require_once (WP_PLUGIN_DIR . "/soundmap/api/soundmap.tags.php");
require_once (WP_PLUGIN_DIR . "/soundmap/api/soundmap.api.php");
if (!class_exists('Soundmap')){
/**
* Soundmap Class Definition
*/
class Soundmap
{
public $config = array();
function __construct(){
//Register hooks and filters
$this->register_hooks();
$this->register_filters();
$this->register_shortcode();
}
function register_shortcode() {
add_shortcode('soinumapa-map',array($this,'shortcode_map'));
}
function shortcode_map($atts) {
return '<div id="map_canvas" class="soinumapa-map"></div>';
}
function register_content_type(){
$labels = array(
'name' => __('Marks', 'soundmap'),
'singular_name' => __('Mark', 'soundmap'),
'add_new' => _x('Add New', 'marker', 'soundmap'),
'add_new_item' => __('Add New Marker', 'soundmap'),
'edit_item' => __('Edit Marker', 'soundmap'),
'new_item' => __('New Marker', 'soundmap'),
'all_items' => __('All Markers', 'soundmap'),
'view_item' => __('View Marker', 'soundmap'),
'search_items' => __('Search Markers', 'soundmap'),
'not_found' => __('No markers found', 'soundmap'),
'not_found_in_trash' => __('No markers found in Trash', 'soundmap'),
'parent_item_colon' => '',
'menu_name' => 'Markers'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'marker', 'with_front' => false ),
'capability_type' => 'post',
'has_archive' => true,
'show_in_rest' => true,
'hierarchical' => false,
'menu_position' => 5,
'register_meta_box_cb' => array($this, 'metaboxes_register_callback'),
'supports' => array('title','editor','thumbnail')
);
register_post_type('marker',$args);
register_taxonomy_for_object_type('category', 'marker');
register_taxonomy_for_object_type('post_tag', 'marker');
} // register_content_type
function init(){
$this->config['on_page'] = FALSE;
$this->load_options();
$this->register_content_type();
}// init
function metaboxes_register_callback(){
add_meta_box('soundmap-map', __("Place the Marker", 'soundmap'), array($this, 'map_meta_box'), 'marker', 'normal', 'high');
add_meta_box('soundmap-media-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high');
add_meta_box('soundmap-media-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high');
// Ya no es necesario
//add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this, 'email_meta_box'), 'marker', 'side', 'low');
} //metaboxes_register_callback
function email_meta_box(){
global $post;
$mail = get_post_meta($post->ID, 'EMAIL', TRUE);
echo "<p>" . $mail . "</p>";
}
function info_meta_box(){
global $post;
$soundmap_author = get_post_meta($post->ID, 'soundmap_marker_author', TRUE);
echo '<label for="soundmap-marker-author">' . __('Author', 'soundmap') . ': </label>';
echo '<input type="text" name="soundmap_marker_author" id="soundmap-marker-author" value="' . $soundmap_author . '">';
}
function attachments_meta_box(){
global $post;
$files = get_post_meta($post->ID, 'soundmap_attachments_id', FALSE);
echo '<div id="soundmap-attachments">';
echo '<div class="add_button_container"><input type="button" id="add_files" class="button button-primary button-large" value="Add Files"></div>';
$out = '';
if ($files){
foreach($files as $file) {
$data = wp_prepare_attachment_for_js( $file );
if (is_array($data)) :
$out .= "<div class='soundmap-attach-item'>
<!-- <div class='att-icon'><img src='{$data['icon']}'/></div> -->
<div class='att-info'><a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/>
<audio controls>
<source src='{$data['url']} type='{$data['mime']}'>
</audio><br/>
<a href='#' class='delete-att-item'>Borrar</a></div><div class='clear'></div><input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
endif;
}
}
echo '<div id="soundmap-attachments-list">' . $out . '</div>';
echo '</div>';
}
function map_meta_box(){
global $post;
$soundmap_lat = get_post_meta($post->ID, 'soundmap_marker_lat', TRUE);
$soundmap_lng = get_post_meta($post->ID, 'soundmap_marker_lng', TRUE);
echo '<input type="hidden" name="soundmap_map_noncename" id="soundmap_map_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
echo '<div id="map_canvas"></div>';
echo '<label for="soundmap-marker-lat">' . __('Latitud', 'soundmap') . '</label>';
echo '<input type="text" name="soundmap_marker_lat" id="soundmap-marker-lat" value = "' . $soundmap_lat . '">';
echo '<label for="soundmap-marker-lng">' . __('Longitud', 'soundmap') . '</label>';
echo '<input type="text" name="soundmap_marker_lng" id="soundmap-marker-lng" value = "'. $soundmap_lng . '">';
echo '<script></script>';
}
function load_options(){
$_config = array();
//Load defaults;
$defaults = array();
$defaults['on_page'] = FALSE;
$defaults['origin']['lat'] = 0;
$defaults['origin']['lng'] = 0;
$defaults['origin']['zoom'] = 10;
$defaults['mapType'] = 'SATELLITE';
$defaults['player_plugin'] = "";
$_config = maybe_unserialize(get_option('soundmap'));
$_config = wp_parse_args($_config, $defaults);
$this->config = $_config;
//Load text domain for translations
load_plugin_textdomain('soundmap', "wp-content/plugins/soundmap/languages", dirname( plugin_basename( __FILE__ ) ) . "/languages");
} //load_options
function admin_menu(){
add_options_page(__('Sound Map Configuration','soundmap'), __('Sound Map','soundmap'), 'manage_options', 'soundmap-options-menu', array($this, 'admin_menu_page_callback'));
}// admin_menu
function enqueue_map_scripts(){
wp_enqueue_script('leafletjs','https://unpkg.com/leaflet@1.9.3/dist/leaflet.js',array(),'1.9.3',TRUE); // add Leaflet.js
wp_enqueue_style('leafletcss',"https://unpkg.com/leaflet@1.9.3/dist/leaflet.css",array(),'1.9.3','all'); // add CSS Leaflet
}
function wp_enqueue_scripts(){
$this->enqueue_map_scripts();
wp_enqueue_script('jquery');
wp_enqueue_script('underscore');
wp_enqueue_script('mediaelement');
wp_enqueue_script('soundmap-front', plugins_url('js/soundmap.front.js', __FILE__), array(), '0.1', TRUE);
wp_enqueue_style('soundmap-front-css', plugins_url('css/soundmap.front.css', __FILE__), array(), '0.1', 'all');
$params = array();
$params['origin'] = $this->config['origin'];
$params['mapType'] = $this->config['mapType'];
$params['locale'] = get_locale();
$params['ajaxurl'] = admin_url('admin-ajax.php');
wp_localize_script('soundmap-front','Soundmap',$params);
}
function admin_enqueue_scripts($hook){
global $current_screen;
if (($hook == 'post-new.php' || $hook == 'post.php') && $current_screen->post_type == "marker"){
$this->enqueue_map_scripts();
wp_enqueue_script('underscore');
wp_enqueue_style('soundmap-add-css', plugins_url('css/soundmap.add.css', __FILE__), array(), '0.1', 'all');
wp_enqueue_script('soundmap-add', plugins_url('js/soundmap.add.js', __FILE__), array(), '0.1', TRUE);
$params = array();
$params['origin'] = $this->config['origin'];
$params['mapType'] = $this->config['mapType'];
$params['locale'] = get_locale();
wp_localize_script('soundmap-add','Soundmap',$params);
}else if($hook == 'settings_page_soundmap-options-menu'){
$this->enqueue_map_scripts();
wp_enqueue_script('underscore');
wp_enqueue_script('soundmap-config', plugins_url('js/soundmap.config.js', __FILE__), array(), '0.1', TRUE);
wp_enqueue_style('soundmap-config-css', plugins_url('css/soundmap.config.css', __FILE__), array(), '0.1', 'all');
$params = array();
$params['origin'] = $this->config['origin'];
$params['mapType'] = $this->config['mapType'];
$params['locale'] = get_locale();
wp_localize_script('soundmap-config','Soundmap',$params);
}//if
} // admin_enqueue_scripts
function save_options(){
$_config = array();
//Load defaults;
$_config ['origin']['lat'] = $_POST['soundmap_op_origin_lat'];
$_config ['origin']['lng'] = $_POST['soundmap_op_origin_lng'];
$_config ['origin']['zoom'] = $_POST['soundmap_op_origin_zoom'];
$_config ['mapType'] = $_POST['soundmap_op_origin_type'];
if(isset($_POST['soundmap_op_plugin']))
$_config ['player_plugin'] = $_POST['soundmap_op_plugin'];
update_option('soundmap',maybe_serialize($_config));
$this->config = wp_parse_args($_config, $this->config);
}// save_post
function admin_menu_page_callback(){
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if (isset($_POST['soundmap_op_noncename'])){
if ( !wp_verify_nonce( $_POST['soundmap_op_noncename'], plugin_basename( __FILE__ ) ) )
return;
$this->save_options();
$this->load_options();
}
?>
<div class="wrap">
<h2><?php _e("Sound Map Configuration", 'soundmap') ?></h2>
<div id="map_canvas_options"></div>
<form method="post" action = "" id="form-soundmap-options">
<h3><?php _e('Map Configuration','soundmap') ?></h3>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Origin configuration','soundmap') ?></th>
<td>
<fieldset>
<span class="description"><?php _e("Choose the original configuration with the map.", 'soundmap') ?></span>
<br>
<label for="soundmap_op_origin_lat"><?php _e('Latitude','soundmap') ?>: </label><br>
<input class="regular-text" name="soundmap_op_origin_lat" id="soundmap_op_origin_lat" type="text" value="<?php echo $this->config['origin']['lat'] ?>">
<br>
<label for="soundmap_op_origin_lng"><?php _e('Longitude','soundmap') ?>: </label><br>
<input class="regular-text" name="soundmap_op_origin_lng" id="soundmap_op_origin_lng" type="text" value="<?php echo $this->config['origin']['lng'] ?>">
<br>
<label for="soundmap_op_origin_zoom"><?php _e('Zoom','soundmap') ?>: </label><br>
<input class="small-text" name="soundmap_op_origin_zoom" id="soundmap_op_origin_zoom" type="text" value="<?php echo $this->config['origin']['zoom'] ?>">
<input type="hidden" name="soundmap_op_origin_type" id="soundmap_op_origin_type" value='<?php echo $this->config['mapType'] ?>'>
</fieldset>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
</p>
<input type="hidden" name="soundmap_op_noncename" id="soundmap_op_noncename" value="<?php echo wp_create_nonce( plugin_basename(__FILE__) ) ?>" />
</form>
</div>
<?php
} // admin_menu_page_callback
function save_post($post_id) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if (isset($_POST['soundmap_map_noncename'])){
if ( !wp_verify_nonce( $_POST['soundmap_map_noncename'], plugin_basename( __FILE__ ) ) )
return;
}else{
return;
}
// Check permissions
if ( 'marker' == $_POST['post_type'] )
{
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
$soundmark_lat = $_POST['soundmap_marker_lat'];
$soundmark_lng = $_POST['soundmap_marker_lng'];
$soundmark_author = $_POST['soundmap_marker_author'];
update_post_meta($post_id, 'soundmap_marker_lat', $soundmark_lat);
update_post_meta($post_id, 'soundmap_marker_lng', $soundmark_lng);
update_post_meta($post_id, 'soundmap_marker_author', $soundmark_author);
//before searching on all the $_POST array, let's take a look if there is any upload first!
if(isset($_POST['soundmap-att-ids'])){
$files = $_POST['soundmap-att-ids'];
delete_post_meta($post_id, 'soundmap_attachments_id');
foreach ($files as $key => $value){
add_post_meta($post_id, 'soundmap_attachments_id', $value);
};
}else{
delete_post_meta($post_id, 'soundmap_attachments_id');
// PORQUE? esto genera un null
//add_post_meta($post_id, 'soundmap_attachments_id', 'null');
};
delete_transient( 'soundmap_JSON_markers' );
}
function wp_print_footer_scripts(){
$params = array();
$params['ajaxurl'] = admin_url( 'admin-ajax.php' );
if (isset($this->config['query'])){
if(is_array($this->config['query'])){
$params ['query'] = json_encode($this->config['query']);
}else{
$params ['query'] = $this->config['query'];
}
}
$params['plugin_url'] = plugins_url( $path = '', __FILE__);
wp_localize_script( 'soundmap', 'WP_Soundmap', $params);
}
function register_hooks(){
add_action('init', array($this, 'init'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('save_post', array($this,'save_post'));
add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'));
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('init', array($this, 'add_feed'));
//AJAX ACTIONS
add_action('wp_ajax_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
add_action('wp_ajax_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
add_action('wp_ajax_nopriv_soundmap_load_infowindow', array($this, 'load_infowindow'));
add_action('wp_ajax_soundmap_load_infowindow', array($this, 'load_infowindow'));
add_action('wp_ajax_soundmap-get-markers',array($this, 'soundmap_get_markers'));
add_action('wp_ajax_nopriv_soundmap-get-markers',array($this,'soundmap_get_markers'));
add_action('wp_ajax_soundmap-get-content',array($this, 'soundmap_get_content'));
/* REST API Options */
add_action('rest_api_init', function() {
/* REST API expand fields */
register_rest_field('marker','media',
array(
'get_callback' => 'marker_get_media',
'schema' => null
)
);
register_rest_field('marker','author',
array(
'get_callback' => 'marker_get_author',
'schema' => null
)
);
register_rest_field('marker','georeference',
array(
'get_callback' => 'marker_get_georeference',
'schema' => null
)
);
/* REST API utils for migration - Temp functions */
register_rest_route('soundmap', '/translate/post', array(
'methods' => 'GET',
'callback' => 'soundmap_save_post_translation',
'permission_callback' => '__return_true'
));
register_rest_route('soundmap', '/translate/term', array(
'methods' => 'GET',
'callback' => 'soundmap_save_term_translation',
'permission_callback' => '__return_true'
));
});
function soundmap_save_term_translation($request) {
$taxonomy=$request->get_param('taxonomy');
$termA=$request->get_param('termA'); // slug
$langA=$request->get_param('langA'); // locale
$response = false;
if ( isset($taxonomy) && isset($termA) ) :
$termB = $termA."-es";
$termC = $termA."-en";
if ( term_exists($termA) && term_exists($termB) && term_exists($termC) ) :
pll_set_term_language(term_exists($termA), 'eu');
pll_set_term_language(term_exists($termB), 'es');
pll_set_term_language(term_exists($termC), 'en');
$translation = array(
'eu' => term_exists($termA),
'es' => term_exists($termB),
'en' => term_exists($termC)
);
pll_save_term_translations($translation);
$response = true;
endif;
endif;
return new WP_REST_Response($response);
}
function soundmap_post_exists( $id ) {
return is_string( get_post_status( $id ) );
}
function soundmap_save_post_translation($request) {
// http://docker:8089/wp-json/soundmap/translate/post?postA=43688&langA=es&postB=12707&langB=eu
$postA=$request->get_param('postA'); // slug
$langA=$request->get_param('langA'); // locale
//$postB=$request->get_param('postB');
//$langB=$request->get_param('langB');
$response = false;
if ( isset($postA) ) :
$pA = get_page_by_path( $postA, OBJECT, 'marker' );
$pB = get_page_by_path( $postA."-es", OBJECT, 'marker' );
$pC = get_page_by_path( $postA."-en", OBJECT, 'marker' );
//return new WP_REST_Response(get_page_by_path( "lesaka-ekaitz-elektromagnetikoa-es", OBJECT, 'marker' ));
if ( $pA && $pB && $pC ) :
pll_set_post_language($pA->ID, 'eu');
pll_set_post_language($pB->ID, 'es');
pll_set_post_language($pC->ID, 'en');
$translation = array(
'eu' => $pA->ID,
'es' => $pB->ID,
'en' => $pC->ID
);
pll_save_post_translations($translation);
$response = true;
endif;
endif;
return new WP_REST_Response($response);
}
function marker_get_georeference ($object, $field_name, $request){
//return $object['id'];
$lat = get_post_meta($object['id'], 'soundmap_marker_lat', true);
$lng = get_post_meta($object['id'], 'soundmap_marker_lng', true);
return [$lng,$lat];
}
function marker_get_author ($object,$field_name, $request) {
return get_post_meta($object['id'],'soundmap_marker_author',true);
}
function marker_get_media ($object, $field_name, $request) {
$files = get_post_meta($object['id'], 'soundmap_attachments_id', FALSE);
$files_str = [];
if ($files) :
foreach($files as $file){
$data = wp_prepare_attachment_for_js( $file );
array_push($files_str,$data);
}
endif;
return $files_str;
}
/* add_action('wp_ajax_nopriv_soundmap_file_uploaded', array($this, 'ajax_file_uploaded_callback'));
add_action('wp_ajax_nopriv_soundmap_save_public_upload', array($this, 'save_public_upload'));
add_action('wp_ajax_nopriv_soundmap_verify_captcha', array($this, 'verify_captcha'));*/
}
function add_feed(){
global $wp_rewrite;
add_feed('podcast', array($this, 'customfeed'));
add_action('generate_rewrite_rules', array($this, 'rewrite_rules'));
$wp_rewrite->flush_rules();
}
function rewrite_rules($wp_rewrite){
$new_rules = array(
'feed/(.+)' => 'index.php?feed='.$wp_rewrite->preg_index(1)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
function customfeed(){
load_template( WP_PLUGIN_DIR . '/soundmap/theme/rss-markers.php'); // You'll create a your-custom-feed.php file in your theme's directory
}
function soundmap_get_content(){
if (!isset($_POST['id']))
wp_send_json_error();
$id = $_POST['id'];
$marker = get_post($id);
if(!$marker)
wp_send_json_error();
global $post;
$post = $marker;
setup_postdata($marker);
$mark = new stdclass();
$mark->id = $id;
$mark->autor = get_post_meta($id, 'soundmap_marker_author', TRUE);
$mark->files = array();
$files = get_post_meta($id, 'soundmap_attachments_id', FALSE);
foreach ($files as $key => $value){
$att = wp_prepare_attachment_for_js( $value );
$mark->files[] = $att;
}
if ($theme=$this->get_template_include('window')){
ob_start();
include ($theme);
$mark->html = ob_get_clean();
}
wp_send_json_success($mark);
}
function load_infowindow(){
$marker_id = $_REQUEST['marker'];
$marker = get_post($marker_id);
global $post;
$post = $marker;
setup_postdata($marker);
if(!$marker)
die();
$feature = new stdclass();
$feature->autor = get_post_meta($marker_id, 'soundmap_marker_author', TRUE);
$files = get_post_meta($marker_id, 'soundmap_attachments_id', FALSE);
$info['m_files'] = array();
foreach ($files as $key => $value){
$file = array();
$att = get_post($value);
$file['id'] = $value;
$file['fileURI'] = wp_get_attachment_url($value);
$file['filePath'] = get_attached_file($value);
$file['info'] = "";//soundmap_get_id3info($file['filePath']);
$file['name'] = $att->post_name;
$info['m_files'][] = $file;
}
if ($theme=$this->get_template_include('window')){
ob_start();
include ($theme);
$output = ob_get_flush();
wp_send_json_success($output);
}
die();
}
function get_template_include($templ){
if (!$templ)
return FALSE;
$theme_file = TEMPLATEPATH . DIRECTORY_SEPARATOR . $templ . '.php';
$plugin_file = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'soundmap' . DIRECTORY_SEPARATOR . 'theme' . DIRECTORY_SEPARATOR . 'theme_' . $templ . '.php';
if (file_exists($theme_file))
return $theme_file;
if(file_exists($plugin_file))
return $plugin_file;
return FALSE;
}
function soundmap_get_markers(){
/*if (!isset($_POST['query']))
wp_send_json_error();*/
$q = $_POST['query'];
if (!is_array($q)) {$q=array($q); }
if (is_array($q)){
$options = array(
'post_type' => 'marker',
'post_status' => 'publish'
);
$options = array_merge($options, $q);
$query = new WP_Query($options);
if ( !$query->have_posts() )
wp_send_json_error();
$posts = $query->posts;
$feature_collection = new stdclass();
$feature_collection->type = 'FeatureCollection';
$feature_collection->features = array();
foreach($posts as $post){
$post_id = $post->ID;
$m_lat = get_post_meta($post_id,'soundmap_marker_lat', TRUE);
$m_lng = get_post_meta($post_id,'soundmap_marker_lng', TRUE);
$title = get_the_title ($post_id);
$feature = new stdclass();
$feature->type = 'Feature';
$feature->geometry = new stdclass();
$feature->geometry->type = 'Point';
$feature->geometry->coordinates = array(floatval($m_lng), floatval($m_lat));
$feature->properties = new stdclass();
$feature->properties->id = $post_id;
$feature->properties->title = $title;
/*$feature->properties = array();
$feature->properties['title']=$title;
$feature->properties['id']=$id;
$feature->properties['marker-color']="#ff00ff";*/
//$feature->properties['title']="ssss";
$feature_collection->features[] = $feature;
}
wp_send_json_success($feature_collection);
}
}
function JSON_load_markers(){
if (!isset($_POST['query']))
return;
//checkeo la cache
$save_transient = false;
if ($_POST['query']=='all'){
$transient_data = get_transient( 'soundmap_JSON_markers' );
if($transient_data !== false){
echo json_encode($transient_data);
die();
}
$query = new WP_Query(array('post_type' => 'marker', 'post_status' => 'publish'));
$save_transient = true;
}else{
if (!is_array($_POST["query"])){
$markers_list = json_decode($_POST['query']);
}else{$markers_list = $_POST['query'];}
$query = new WP_Query(array('post_type' => 'marker', 'post_status' => 'publish', 'post__in' => $markers_list));
}
$markers = array();
if ( !$query->have_posts() )
die();
$posts = $query->posts;
$feature_collection = new stdclass();
$feature_collection->type = 'FeatureCollection';
$feature_collection->features = array();
foreach($posts as $post){
$post_id = $post->ID;
$m_lat = get_post_meta($post_id,'soundmap_marker_lat', TRUE);
$m_lng = get_post_meta($post_id,'soundmap_marker_lng', TRUE);
$title = get_the_title ($post_id);
$feature = new stdclass();
$feature->type = 'Feature';
$feature->geometry = new stdclass();
$feature->geometry->type = 'Point';
$feature->geometry->coordinates = array(floatval($m_lng), floatval($m_lat));
$feature->properties = new stdclass();
$feature->properties->id = $post_id;
$feature->properties->title = $title;
$feature_collection->features[] = $feature;
}
if ($save_transient)
set_transient( 'soundmap_JSON_markers', $feature_collection, 60*60*12 );
echo json_encode($feature_collection);
die();
}
function register_filters(){
//add_filter( 'pre_get_posts', array($this, 'pre_get_posts'));
}
function set_query($query){
if (!is_array($query)){
//miramos si es texto
if ($query == "all"){
$this->config['query'] = 'all';
}
}else{
$this->config['query'] = $query;
}
}
function getID3($file){
$getID3 = new getID3;
$result = array();
$fileInfo = $getID3->analyze($file);
if(isset($fileInfo['error']))
return;
if (isset($fileInfo['playtime_string']))
$result['play_time'] = $fileInfo['playtime_string'];
if (isset($fileInfo['fileformat']))
$result['format'] = $fileInfo['fileformat'];
return $result;
}
}
}
global $soundmap;
$soundmap = new Soundmap();