Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added Location Highlighter - Lite

  • Loading branch information...
commit 6a0e26cae683d03a29b5a89a2ea3fbc8636f365b 1 parent 0c7b051
@mpetr authored
View
1  README
@@ -0,0 +1 @@
+Welcome and hope something from here will help spice up your Ushahidi deployment!
View
86 locationhighlightlite/controllers/admin/locationhighlightlite_settings.php
@@ -0,0 +1,86 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * This controller is used to add/ remove admin areas for the Location Hightlight plugin
+ *
+ */
+
+
+class LocationHighlightLite_settings_Controller extends Admin_Controller
+{
+
+ function __construct()
+ {
+ parent::__construct();
+ $this->template->this_page = 'manage';
+
+ // If user doesn't have access, redirect to dashboard
+ if ( ! admin::permissions($this->user, "manage"))
+ {
+ url::redirect(url::site().'admin/dashboard');
+ }
+ }
+
+ /*
+ Add Edit Layers (KML, KMZ, GeoRSS)
+ */
+ function index()
+ {
+ $this->template->content = new View('locationhighlightlite/settings');
+
+ // setup and initialize form field names
+ $form = array
+ (
+ 'file' => '',
+ );
+
+ // copy the form as errors, so the errors will be stored with keys corresponding to the form field names
+ $errors = $form;
+ $form_error = FALSE;
+ $form_saved = FALSE;
+
+ // check, has the form been submitted, if so, setup validation
+ if ($_POST)
+ {
+
+ //echo Kohana::debug($_POST);die();
+ // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
+ $post = Validation::factory(array_merge($_POST,$_FILES));
+ // Add some filters
+ $post->pre_filter('trim', TRUE);
+ // Add some rules, the input field, followed by a list of checks, carried out in order
+ $post->add_rules('file', 'upload::valid','upload::type[kml]', 'upload::required');
+
+ // Test to see if things passed the rule checks
+ if ($post->validate())
+ {
+ // Upload KML
+ $path_info = upload::save("file", "LocationHighlightLite.kml");
+
+ $form_saved = TRUE;
+ $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
+ }
+ // No! We have validation errors, we need to show the form again, with the errors
+ else
+ {
+ // repopulate the form fields
+ $form = arr::overwrite($form, $post->as_array());
+
+ // populate the error fields, if any
+ $errors = arr::overwrite($errors, $post->errors('layer'));
+ $form_error = TRUE;
+ }
+ }// $_POST
+
+
+
+ $this->template->content->errors = $errors;
+ $this->template->content->form_error = $form_error;
+ $this->template->content->form_saved = $form_saved;
+
+ }
+
+
+
+
+
+}//end class
View
54 locationhighlightlite/hooks/locationhighlightlite.php
@@ -0,0 +1,54 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Sets up the hooks
+ *
+ * @author Petr Bartos
+ * @author John Etherton
+ * @package LocationHighlightLite
+ */
+
+class locationhighlightlite {
+
+ /**
+ * Registers the main event add method
+ */
+ public function __construct()
+ {
+ // Hook into routing
+ Event::add('system.pre_controller', array($this, 'add'));
+ $this->post_data = null; //initialize this for later use
+
+ }
+
+ /**
+ * Adds all the events to the main Ushahidi application
+ */
+ public function add()
+ {
+
+ // Only add the events if we are on that controller
+ if (Router::$controller == 'reports')
+ {
+ switch (Router::$method)
+ {
+ // Hook into the Report Add/Edit Form in Admin
+ case 'edit':
+ plugin::add_stylesheet('locationhighlightlite/media/css/locationhighlightlite');
+ plugin::add_javascript('locationhighlightlite/media/js/locationhighlightlite');
+ break;
+
+ //Hook into frontend Submit View
+ case 'submit':
+ plugin::add_stylesheet('locationhighlightlite/media/css/locationhighlightlite');
+ plugin::add_javascript('locationhighlightlite/media/js/locationhighlightlite');
+ break;
+
+ default:
+ break;
+ }//end of switch
+ }//end of if reports
+ }
+
+}
+
+new locationhighlightlite;
View
12 locationhighlightlite/i18n/en_US/layer.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Language file
+ *
+ */
+
+ $lang = array(
+ 'file'=>array('default'=>'File must be a KML or KMZ file'),
+ 'name'=>array('default'=>'Name must be between 3 and 80 characters long'),
+ );
+
+
View
36 locationhighlightlite/media/css/locationhighlightlite.css
@@ -0,0 +1,36 @@
+.location_box,
+a.location_clearmap{
+ display: block;
+ clear: block;
+ float: left;
+ background: rgba(255, 253, 205, 1);
+ margin: .5em 1em .5em 0;
+ padding: 1em;
+ border-radius: 9px;
+ }
+a.location_clearmap {
+ background: #ccc;
+ font-weight: bold;
+ text-decoration: none;
+ }
+a.location_clearmap:hover {
+ background: red;
+ color: #fff;
+ }
+.location_box h4 {
+ margin-bottom: 5px;
+ font-weight: bold;
+ font-size: 1.3em;
+ text-transform: uppercase;
+ }
+.location_box a {
+ font-weight: bold;
+ }
+
+/* administration report form */
+div.f-col-1 .location_box {
+ width: 477px;
+ }
+div.f-col-1 .location_box h4 {
+ padding-top: 0;
+ }
View
34 locationhighlightlite/media/js/locationhighlightlite.js
@@ -0,0 +1,34 @@
+/*
+* Add KML Layers
+*/
+function locationHighlightLite_init()
+{
+ var layerURL = "/media/uploads/LocationHighlightLite.kml" + "?" + Math.random();
+
+ //create new layer
+ var layer = new OpenLayers.Layer.Vector("Location", {
+ projection: map.displayProjection,
+ strategies: [new OpenLayers.Strategy.Fixed()],
+ protocol: new OpenLayers.Protocol.HTTP({
+ url: layerURL,
+ format: new OpenLayers.Format.KML({
+ extractStyles: true,
+ extractAttributes: true
+ })
+ })
+ });
+
+
+ // Add New Layer
+ map.addLayer(layer);
+
+ return false;
+}
+
+
+// can't find better way for binding to 'map' var, which isn't initialized at this time
+jQuery(document).ready(function($) {
+ window.setTimeout(function() {
+ map.events.register("loadend", locationHighlightLite_init());
+ }, 2000);
+});
View
21 locationhighlightlite/readme.txt
@@ -0,0 +1,21 @@
+=== About ===
+name: Location Highlighter - Lite
+website: http://apps.ushahidi.com
+description: Adds default layer to map in submit/edit report pages. You specify how the layer will look like - useful for highlighting areas
+version: 1.0
+requires: 2.1
+tested up to: 2.1
+author: Petr Bartos. Based on work of John Etherton
+
+== Description ==
+When users are adding new reports to the map they may struggle to find landmarks or administrative boundaries that make it easier
+for them to contextualize what they're looking at and figure out where they need to put the marker. This plugin will highlight an area that you have defined
+by KML file.
+
+Looking for more? Check "Location Highlighter" plugin of John Etherton.
+
+== Installation ==
+1. Copy the entire /locationhighlightlite/ directory into your /plugins/ directory.
+2. Activate the plugin.
+
+== Changelog ==
View
64 locationhighlightlite/views/locationhighlightlite/settings.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * More settings
+ *
+ */
+?>
+ <div class="bg">
+ <?php
+ if ($form_error) {
+ ?>
+ <!-- red-box -->
+ <div class="red-box">
+ <h3><?php echo Kohana::lang('ui_main.error');?></h3>
+ <ul>
+ <?php
+ foreach ($errors as $error_item => $error_description)
+ {
+ // print "<li>" . $error_description . "</li>";
+ print (!$error_description) ? '' : "<li>" . $error_description . "</li>";
+ }
+ ?>
+ </ul>
+ </div>
+ <?php
+ }
+
+ if ($form_saved) {
+ ?>
+ <!-- green-box -->
+ <div class="green-box">
+ <h3><?php echo Kohana::lang('ui_main.saved') ?></h3>
+ </div>
+ <?php
+ }
+ ?>
+
+
+
+
+
+ <h2>Set highlighted location</h2>
+
+ <!-- tab -->
+ <div class="tab">
+ <?php print form::open(NULL,array('enctype' => 'multipart/form-data',
+ 'id' => 'layerMain', 'name' => 'layerMain')); ?>
+
+ <div class="tab_form_item">
+ Upload KML File:
+ <?php print form::upload('file', '', ''); ?>
+ </div>
+
+ <div style="clear:both"></div>
+ <div class="tab_form_item">
+ This layer will be shown on the map on "Submit a report" page<br /><br/>
+ <input type="image" src="<?php echo url::base() ?>media/img/admin/btn-save.gif" class="save-rep-btn" />
+ </div>
+ <?php print form::close(); ?>
+ </div>
+ </div>
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.