soundmap_theme/georss.php
2016-11-29 01:18:17 +01:00

101 lines
3.8 KiB
PHP

<?php
/**
* Template Name: GeoJSON
*
* @package WordPress
* @subpackage SoundMap Theme
* @since SoundMap 1.0
*/
//$tag = "gipuzkoako-urak";
//query_posts('tag='.$tag);
if (isset($_GET['tag'])) { $tag = $_GET['tag']; } else { $tag="";}
//if (isset($_GET['tag'])) { $tag = $_GET['tag']; } else { $tag="gipuzkoako-urak,debabarrena-bajo-deva";}
if (isset($_GET['author_id'])) { $author = $_GET['author_id']; } else { $author="";}
$not_post = [8973,8822,9136,9750,9749,10544,10781,9745,9895,9666,9441,9497,9174];
$tag_not = [1411,1047,1048,1287,883,1050];
$args = array(
'nopaging' => true,
'orderby' => 'rand',
'order' => 'ASC',
'post_type' => 'marker',
'post_status' => 'any',
'author' => $author,
'tag' => $tag,
'post__not_in' => $not_post,
'tag__not_in' => $tag_not,
//'tag__in' => array( 37, 47 ),
);
$all_posts=new WP_Query($args);
$tracklist = "";
$tracklist = "<div id='track-list'><div class='antiscroll-wrap'><div id='tracks-wrapper' class='antiscroll-inner'><ul>";
$objetos = array();
$links = "";
$span = array();
$total = count($all_posts->posts);
//echo $total;
echo '{
"type": "FeatureCollection",
"crs": {"type": "name", "properties": { "name": "EPSG:3857" } },
"features": [';
foreach( $all_posts->posts as $post ) : setup_postdata($post);
$tit = array();
$tit['titulo'] = $post->post_title;
$tit['id'] = $post->ID;
$tit['author']=get_post_meta($post->ID,'soundmap_marker_author',TRUE);
$tags = wp_get_post_tags( $post->ID, array( 'fields' => 'names' ) );
$tags = implode(", ",$tags);
$tit['category'] = get_the_category($post->ID);
$c="no-category";
if (!empty($tit['category'])) { foreach ($tit['category'] as $cat): $c=$cat->name; endforeach;}
//print_R($tit['category']);
$image_id = get_post_thumbnail_id($tit['id']);
$imagesize="single-post-thumbnail";
$tit['img'] = wp_get_attachment_image_src($image_id);
$tit['img'] = basename($tit['img'][0]);
$image_url = get_the_post_thumbnail($tit['id']);
$m_lat = get_post_meta($post->ID,'soundmap_marker_lat', TRUE);
$m_lng = get_post_meta($post->ID,'soundmap_marker_lng', TRUE);
$tit['date']=get_post_meta($post->ID,'soundmap_marker_date', TRUE);
$data = array();
$files = get_post_meta($post->ID, 'soundmap_attachments_id', FALSE);
$data['m_files'] = array();
foreach ($files as $key => $value){
$file = array();
$att = get_post($value);
$file['fileURI'] = wp_get_attachment_url($value);
$tracklist .="<li><a data-id='{$post->ID}' href='{$file['fileURI']}'>{$post->post_title}</a></li>";
$data['m_files'][] = $file;
}
$tit['archivos'] = $data['m_files'];
$objetos[] = $tit;
$order = array("\r\n", "\n", "\r");
$order2 = array("<div>\r\n", "</div>\r\n");
$content = json_encode(str_replace($order,'<br/>',str_replace($order2,'',trim($post->post_content))));
//json_encode(trim(preg_replace('"', '',$content)))
echo ' { "type": "Feature"';
if ($m_lng!="") : echo ', "geometry": {"type": "Point","coordinates": ['.$m_lng.', '.$m_lat.']}'; endif;
echo ', "properties": { "id" : '.$tit['id'].', "date" : "'.$tit['date'].'", "category": "'.$c.'","title": '.json_encode($tit['titulo']).', "author" : "'.$tit['author'].'", "href" : "", "content" : '.$content.', "attachment" : "'.$file['fileURI'].'","image-url":"'.str_replace('"','\'',$image_url).'","image" : "'.str_replace('"','\'',$image_url).'" }
},';
endforeach;
echo '{"type":"Feature"}';
echo " ]
}";
?>