Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagojsag committed Feb 20, 2013
0 parents commit e27e94f
Show file tree
Hide file tree
Showing 6 changed files with 22,851 additions and 0 deletions.
45 changes: 45 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
add_action('admin_menu', 'cartopress_admin_menu' );
add_action('admin_init', 'cartopress_admin_init');

function cartopress_section_main_output() {
echo '<p>Intro text for our settings section</p>';
}

function cp_cartodb_account_input() {
$value = get_option('cp_cartodb_account');
echo "<input id='plugin_text_string' name='cp_cartodb_account' size='20' type='text' value='$value' />";
}

function cartopress_options() {
//must check that the user has the required capability
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e( 'CartoPress Settings', 'cartopress' ) ?></h2>
<form action="options.php" method="post">
<?php settings_fields('cartopress'); ?>
<?php do_settings_sections('cartopress'); ?>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
</p>
</form>
</div>
<?php

}

function cartopress_admin_menu() {
if (!current_user_can('manage_options'))
{
wp_die( __('You do not have sufficient permissions to access this page.') );
}
add_options_page( __( 'CartoPress Options', 'cartopress'), __('CartoPress', 'cartopress'), 'manage_options', 'cartopress', 'cartopress_options');
}

function cartopress_admin_init() {
register_setting('cartopress', 'cp_cartodb_account' );
add_settings_section('cartopress_section_main', __("CartoDB Main Settings", 'cartopress' ), 'cartopress_section_main_output', 'cartopress');
add_settings_field('cp_cartodb_account', __("CartoDB Account Name:", 'cartopress' ), 'cp_cartodb_account_input', 'cartopress', 'cartopress_section_main');
}
?>
2 changes: 2 additions & 0 deletions assets/css/cartopress.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
div.map {display:hidden;}
div.map, div.map img {box-shadow:none;}
22,649 changes: 22,649 additions & 0 deletions assets/js/lib/cartodb.uncompressed.js

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function main(options) {

var map = L.map(options['map'], {
zoomControl: false,
center: [options['x'], options['y']],
zoom: options['zoom']
});

// add a nice baselayer from mapbox
L.tileLayer('http://{s}.tiles.mapbox.com/v3/d4weed.map-da1z3qw8/{z}/{x}/{y}.png', {
attribution: 'MapBox'
}).addTo(map);

cartodb.createLayer(map, 'http://'+options['user']+'.cartodb.com/api/v1/viz/'+options['table']+'/viz.json', {
query: 'select * from '+options['table']+' where '+options['filter'],
})
.on('done', function(layer) {
console.log('select * from '+options['table']+' where '+options['filter']);

map.on('layeradd', function(){$('#'+options['map']).show();});
map.addLayer(layer);

layer.on('featureOver', function(e, pos, latlng, data) {
});

layer.on('error', function(err) {
cartodb.log.log('error: ' + err);
});

}).on('error', function() {
cartodb.log.log("some error occurred");
});

}
83 changes: 83 additions & 0 deletions cartopress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
Plugin Name: CartoPress
Description: CartoPress integrates CartoDB into WordPress.
Version: 0.1.0
Author: Tiagojsag
License: GPLv2 or later
*/

/**
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

if ( is_admin() )
require_once dirname( __FILE__ ) . '/admin.php';

function cartodb_tag_func( $atts ) {
extract(shortcode_atts( array(
'table' => '',
'width' => '100%',
'height' => '300px',
'x' => 0,
'y' => 0,
'zoom' => 1,
'filter' => '1=1'
), $atts ));

if (empty($table))
return;

$mapId = rand();

$output = '
<div id="cartopressmap-'.$mapId.'" style="width:'.$width.';height:'.$height.'" class="map"></div>
<script>
window.onload =
main({
user: \''.get_option('cp_cartodb_account').'\',
table: \''.$table.'\',
map: \'cartopressmap-'.$mapId.'\',
x: '.$x.',
y: '.$y.',
zoom: '.$zoom.',
filter: "'.htmlspecialchars_decode($filter).'"
});
</script>
';
return $output;
}

function check_shortcode($posts) {
if ( empty($posts) )
return $posts;

foreach ($posts as $post) {
if ( stripos($post->post_content, '[cartodb') !== false )
{
wp_enqueue_style('cartodb', 'http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.css');
wp_enqueue_style('cartopress', '/wp-content/plugins/cartopress/assets/css/cartopress.css');
wp_enqueue_script('cartodb','http://libs.cartocdn.com/cartodb.js/v2/cartodb.js', array('jquery'));
wp_enqueue_script('cartopress', '/wp-content/plugins/cartopress/assets/js/script.js', array('jquery', 'cartodb'));
}
break;
}
return $posts;
}

add_action('the_posts', 'check_shortcode');
add_shortcode( 'cartodb', 'cartodb_tag_func' );
?>
38 changes: 38 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=== CartoPress - CartoDB integration for WordPress ===
Contributors: tiagojsag
Tags: catodb
Requires at least: 3.0
Tested up to: 3.5
Stable tag: 1.0.0
License: GPLv2 or later

CartoPress integrates CartoDB into WordPress.

== Description ==

This pluggins provides VERY BASIC (for now) integration with CartoDB for WordPress.
Right now only public tables are supported, and a limited number of parameters
can be configured in order to render maps in your visualizations.
This plugin is under active development, and any suggestions are welcome,
although I can't make any promises on timetables.

== Installation ==

Just install like any other WordPress plugin

== Configuration ==

A "CartoPress" configuration page is provided for admins, under "Settings".
Currently it just accepts your CartoDB username.

== Usage ==

Maps can be renderes in your posts using Shortcode, like so:

[cartodb table="your-table" zoom="4" filter="lon > '-3' " x="40" y="20" width="100px" height="200px"]

These are all the options available at the moment, and they are quite self-explanatory.

== Changelog ==

0.1.0 - Initial version

0 comments on commit e27e94f

Please sign in to comment.