1<?php 2/* 3 * Copyright (c) 2011 Mark C. Prins <mc.prins@gmail.com> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18/** 19 * DokuWiki Plugin geotag (Action Component) 20 * 21 * @license BSD 22 * @author Mark C. Prins <mc.prins@gmail.com> 23 */ 24if (!defined('DOKU_INC')) die(); 25 26if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 27if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 28if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 29 30require_once DOKU_PLUGIN.'action.php'; 31 32class action_plugin_geotag extends DokuWiki_Action_Plugin { 33 34 public function register(Doku_Event_Handler &$controller) { 35 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metaheader_output'); 36 $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'ping', array()); 37 } 38 39 public function handle_metaheader_output(Doku_Event &$event, $param) { 40 global $ID; 41 $geotags = p_get_metadata($ID,'geo',true); 42 $region=$geotags['region']; 43 $lat=$geotags['lat']; 44 $lon=$geotags['lon']; 45 $country=$geotags['country']; 46 $placename=$geotags['placename']; 47 48 if (!empty($region)) {$event->data['meta'][] = array('name' => 'geo.region','content' => $region,);} 49 if (!empty($placename)) {$event->data['meta'][] = array('name' => 'geo.placename','content' => $placename,);} 50 if (!(empty($lat)&&empty($lon))) {$event->data['meta'][] = array('name' => 'geo.position','content' => $lat.';'.$lon,);} 51 if (!empty($country)) {$event->data['meta'][] = array('name' => 'geo.country','content' => $country,);} 52 if (!(empty($lat)&&empty($lon))) {$event->data['meta'][] = array('name' => 'ICBM','content' => $lat.', '.$lon,);} 53 } 54 55 function ping(&$event, $param) { 56 if (!$this->getConf('geotag_pinggeourl')) return false; // config says don't ping 57 if ($event->data[3]) return false; // old revision saved 58 if (@file_exists($event->data[0][0])) return false; // file not new 59 if (!$event->data[0][1]) return false; // file is empty 60 61 global $conf; 62 63 $request = 'p='.DOKU_URL; 64 $url = 'http://geourl.org/ping/'; 65 $header[] = 'Host: geourl.org'; 66 $header[] = 'Content-type: text/html'; 67 $header[] = 'Content-length: '.strlen($request); 68 69 $http = new DokuHTTPClient(); 70 return $http->get($url, $request); 71 } 72} 73