PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ playar/com_imajiematch/site/geo/oar-browser/oar-browser.php

http://playar.googlecode.com/
PHP | 1016 lines | 843 code | 99 blank | 74 comment | 50 complexity | 19768bc3d7fd7dbc4a2bc7f739936003 MD5 | raw file
Possible License(s): AGPL-3.0, Apache-2.0
  1. <?php
  2. /*
  3. LightRod OAR Browser
  4. Copyright (C) 2001 - 2010 High Country Software Ltd.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU Affero General Public License as
  7. published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Affero General Public License for more details.
  13. You should have received a copy of the GNU Affero General Public License
  14. along with this program. If not, see http://www.gnu.org/licenses/.
  15. Usage:
  16. See http://www.lightrod.org/ 'LightRod OAR Browser' section for the most up-to-date instructions.
  17. For assistance:
  18. peter AT lightrod.org
  19. or the LightRod forums
  20. */
  21. //set the error level of the website - don't include warnings
  22. error_reporting(E_ERROR | E_PARSE); //Needed for Windows compatability
  23. //Used by the layout pages - needed to be absolute given templates
  24. if($_SERVER['HTTP_X_FORWARDED_HOST']) {
  25. //If on a load balancer
  26. $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
  27. if(($host == 'owlz.org')||($host == 'www.owlz.org')) {
  28. $oar_browser_dir = 'http://' . $host . "/";
  29. } else {
  30. $oar_browser_dir = 'http://' . $host . dirname($_SERVER['SCRIPT_NAME']) . "/";
  31. }
  32. } else {
  33. //A regular machine
  34. $host = $_SERVER['HTTP_HOST'];
  35. $oar_browser_dir = 'http://' . $host . dirname($_SERVER['SCRIPT_NAME']) . "/";
  36. }
  37. if($_SERVER["SERVER_NAME"] == "127.0.0.1") {
  38. define("GOOGLE_MAPS_KEY", 'ABQIAAAAK9scMBruVrJb9OaY1EFbeRQmM3h9L3BgTlGR6dGXr_-vPADENhSNYAiWEUEANdtJWw0vzj9A-uEurQ');
  39. } else {
  40. //if( strstr('internal',$_SERVER["SERVER_NAME"] != false)) {
  41. // $oar_browser_dir = 'http://owlz.org/';
  42. //}
  43. //Atomjump - or put your own key in here
  44. //define("GOOGLE_MAPS_KEY", 'ABQIAAAAqZq5joilTRJEerD58NWIiBTJvMA1VJ3LRQ4VO6FcYp9qeXpADxQgij2d-hn-oLcc_kMwQb9PI9BvIg');
  45. //Lightrod.org
  46. //define("GOOGLE_MAPS_KEY", "ABQIAAAAqZq5joilTRJEerD58NWIiBQ9HUNJ69cB_yBrpo2qKRgj0mhLyRSOUW2EqO_rW29i0RYWJLGgNWROhw");
  47. //Get any config from the user's own server
  48. if(file_exists("../config/browser.php")) {
  49. require_once("../config/browser.php");
  50. } else {
  51. //oar.lightrod.org
  52. //define("GOOGLE_MAPS_KEY", "ABQIAAAAqZq5joilTRJEerD58NWIiBRlOYGdwPi-gcmsssDy8Wj8iMd7lBTCQx2LEqqO3WVU2F15opgzbQAt8A");
  53. //owlz.org
  54. define("GOOGLE_MAPS_KEY", "ABQIAAAAqZq5joilTRJEerD58NWIiBTs2-HNR4z63Cui3xThNlGOwd6zfhSvl4VD-Y9iWFaRGHTGHm1uBDpD_A");
  55. }
  56. }
  57. //Used by the layout pages - needed to be absolute given templates
  58. $oar_browser_path = $oar_browser_dir . "oar-browser.php";
  59. //print_r($_SERVER);
  60. //Some definitions
  61. define('LIST_VIEW', 1);
  62. define('MAP_VIEW', 2);
  63. //Input URL
  64. $oar = new oarBrowser($_REQUEST['url'],
  65. $_REQUEST['lat'],
  66. $_REQUEST['lon'],
  67. $_REQUEST['srch'],
  68. $_REQUEST['pageKey'],
  69. $_REQUEST['viewType'],
  70. $_REQUEST['template'],
  71. $_REQUEST['linkTarget'],
  72. $_REQUEST['geoBias'],
  73. $_REQUEST['zoom'],
  74. $_REQUEST['address'],
  75. $_REQUEST['listHeight'],
  76. $_REQUEST['rvolve'],
  77. $oar_browser_path,
  78. $oar_browser_dir);
  79. //Read any filters that exist for e.g. a text search
  80. $oar->parse_filters();
  81. //Read robots.txt file from URL, or read meta tag from homepage to find layer query string
  82. if(isset($_REQUEST['url'])) {
  83. if($query_string = $oar->get_layer_query_str()) {
  84. //Optionally prepare the filters for user input
  85. //echo "Filtersnow=" . $oar->filters_now . " Search now=" . $oar->search_now;
  86. if(($oar->filters_now == true)&&($oar->search_now != 1)) {
  87. $results = $oar->parse_options_to_filters($oar->oar_filters);
  88. } else {
  89. //Read layer
  90. $results = $oar->read_layer($_REQUEST['lat'], $_REQUEST['lon']);
  91. //print_r($results);
  92. }
  93. //echo $query_string;
  94. } else {
  95. $oar->error_message = "D&eacute;sol&eacute; ! Il n'y a pas d'ImajieMatch dans ton secteur.<br/>";
  96. }
  97. }
  98. class oarBrowser
  99. {
  100. public $url;
  101. public $url_with_http;
  102. public $favicon;
  103. public $oar_server;
  104. public $oar_filters;
  105. public $oar_description;
  106. public $oar_logo;
  107. public $results;
  108. public $latitude;
  109. public $longitude;
  110. public $search_now;
  111. public $query_1_param;
  112. public $query_1_val;
  113. public $query_2_param;
  114. public $query_2_val;
  115. public $query_3_param;
  116. public $query_3_val;
  117. public $page_key;
  118. public $filters_now;
  119. public $error_message;
  120. public $default_search_engine;
  121. public $view_type;
  122. public $template_url;
  123. public $body_onload;
  124. public $oar_browser_path;
  125. public $oar_browser_dir;
  126. public $oar_mapmarker;
  127. public $link_target;
  128. public $geo_bias;
  129. public $init_map_zoom;
  130. public $address;
  131. public $list_height;
  132. public $list_width;
  133. public $rvolve_user_id;
  134. public function __construct($url, $lat, $lon, $search, $page_key = null, $view_type = LIST_VIEW, $template_url = null, $my_link_target = "_parent", $my_geo_bias, $my_init_map_zoom, $my_address = null, $my_list_height = null, $my_rvolve = null, $oar_browser_path, $oar_browser_dir)
  135. {
  136. $this->url = $url;
  137. //Custom Nakdreality shortcut
  138. if(substr($url, 0,1) == '%') {
  139. $layer = substr($url, 1);
  140. $this->url = "http://poi.nakdreality.com/clients/" . $layer . "/";
  141. }
  142. if((isset($lat))&&($lat!='undefined')) {
  143. $this->latitude = $lat;
  144. } else {
  145. $this->latitude = 51.4726158; //Grenwich
  146. }
  147. if((isset($lon))&&($lon!='undefined')) {
  148. $this->longitude = $lon;
  149. } else {
  150. $this->longitude = 0.0; //Grenwich
  151. }
  152. if((isset($search))&&($search!='undefined')) {
  153. $this->search_now = $search;
  154. } else {
  155. $this->search_now = 0;
  156. }
  157. $this->filters_now = false; //Display filters
  158. if((isset($page_key))&&($page_key!='undefined')) {
  159. $this->page_key = $page_key;
  160. } else {
  161. $this->page_key = 0; //Assume no page key
  162. }
  163. if(isset($_COOKIE['default_search_engine'])) {
  164. $this->default_search_engine = $_COOKIE['default_search_engine'];
  165. } else {
  166. //Use our hosting providers as an example
  167. //POI engine
  168. $this->default_search_engine = "http://key.nakdreality.com/nakdreality/[SEARCH]/lr/locations/";
  169. }
  170. /*
  171. if(substr($url, 0,1) == '.') {
  172. //NakdReality Keyword engine
  173. $this->default_search_engine = "http://www.nakdreality.com/search?userId=0&layerName=[SEARCH]";
  174. }*/
  175. if(isset($view_type)) {
  176. $this->view_type = $view_type;
  177. } else {
  178. $this->view_type = LIST_VIEW;
  179. }
  180. if(isset($template_url)) {
  181. $this->template_url = $template_url;
  182. }
  183. $this->oar_browser_path = $oar_browser_path;
  184. $this->oar_browser_dir = $oar_browser_dir;
  185. $this->oar_mapmarker = "";
  186. if($my_link_target == "") {
  187. //Default to a whole new page from within a frame
  188. $this->link_target="_parent";
  189. } else {
  190. $this->link_target = $my_link_target;
  191. }
  192. if(isset($my_geo_bias)) {
  193. //Default to a whole new page from within a frame
  194. $this->geo_bias = $my_geo_bias;
  195. } else {
  196. $this->geo_bias = "";
  197. }
  198. if(isset($my_init_map_zoom)) {
  199. $this->init_map_zoom = $my_init_map_zoom;
  200. } else {
  201. $this->init_map_zoom = "false"; //This is a javsacript false so needs to be text
  202. }
  203. $this->address = $my_address;
  204. if(isset($my_list_height)) {
  205. list($this->list_width, $this->list_height) = explode(",",$my_list_height);
  206. }
  207. if(isset($my_rvolve)) {
  208. $this->rvolve_user_id = $my_rvolve;
  209. } else {
  210. $this->rvolve_user_id = false;
  211. }
  212. }
  213. public function parse_filters()
  214. {
  215. //These are input filters to the main search that we are calling
  216. foreach($_REQUEST as $name => $value)
  217. {
  218. //echo $name . " = " . $value ."<br>";
  219. if(strpos($name, "query1_") !== false) {
  220. $this->query_1_param = substr($name, 7);
  221. $this->query_1_val = $value;
  222. }
  223. if(strpos($name, "query2_") !== false) {
  224. $this->query_2_param = substr($name, 7);
  225. $this->query_2_val = $value;
  226. }
  227. if(strpos($name, "query3_") !== false) {
  228. $this->query_3_param = substr($name, 7);
  229. $this->query_3_val = $value;
  230. }
  231. }
  232. }
  233. public function parse_options_to_filters($options_text)
  234. {
  235. //Input
  236. //"text_box|query|Enter your search term,
  237. // option_box|myopt{'Option 1'=1;'Option 2'=2}|Select your option,
  238. // text_box|radius|Radius"
  239. $return_array = array();
  240. $filters = explode(",", $options_text);
  241. $cnt = 1;
  242. foreach($filters as $filter)
  243. {
  244. //OK we have text like "text_box:'Enter your search terms'=query"
  245. if($cnt < 4) { //Only currently support 3 option filters
  246. $command_terms = explode("|" , trim($filter));
  247. if($command_terms[0] == 'text_box') {
  248. //echo $command_terms[1];
  249. //print_r($terms);
  250. $return_array['filter' . $cnt . 'Param'] = $command_terms[1];
  251. $return_array['filter' . $cnt . 'Text'] = str_ireplace("'", "", $command_terms[2]);
  252. //echo $return_array['filter' . $cnt . 'Text'];
  253. }
  254. }
  255. $cnt++;
  256. }
  257. $this->results = $return_array;
  258. return $return_array;
  259. }
  260. private function get_meta_data($html) {
  261. //Function doesn't currently work - but I'm told it is faster
  262. if(preg_match('/<meta[^>]+name=\"oar-server\"[^>]+content=\"([^\"]*)\"[^>]+>/i', $line, $match)) {
  263. $meta['oar-server'] = $match[1];
  264. }
  265. return $meta;
  266. }
  267. public function get_layer_query_str()
  268. {
  269. ini_set('user_agent', 'oar-lightrod-browser (http://www.lightrod.org)');
  270. $a_match = false;
  271. //echo $this->url; //TEMPIN
  272. //exit(0);
  273. $url_with_http = $this->url;
  274. if(stristr($this->url,"http://") == false) {
  275. $url_with_http = "http://" . $this->url;
  276. }
  277. $this->url_with_http = $url_with_http; //Save for later
  278. $parsed = @parse_url($url_with_http);
  279. if($parsed != false) {
  280. $parsed_host = "http://{$parsed['host']}/";
  281. $this->favicon = $parsed_host . "favicon.ico"; //Default favicon
  282. if(@file_get_contents($this->favicon) == false) {
  283. //No such file, then set to lightrod icon
  284. $this->favicon = "lrod_favicon.ico";
  285. }
  286. $html = @file_get_contents($url_with_http);
  287. if($html == false) {
  288. //Try searching off the default search engine - this is a plain text search or layar
  289. //name most likely
  290. $url_with_http = str_ireplace("[SEARCH]", $this->url, $this->default_search_engine);
  291. $html = @file_get_contents($url_with_http);
  292. //Get the favicon from the search engine
  293. $parsed = @parse_url($url_with_http);
  294. if($parsed != false) {
  295. $parsed_host = "http://{$parsed['host']}/";
  296. $this->favicon = $parsed_host . "favicon.ico"; //Default favicon
  297. }
  298. }
  299. if ($html != false) {
  300. //Faster but not currently working $meta_tag_array = $this->get_meta_data($html);
  301. $meta_tag_array = get_meta_tags($url_with_http); //TODO: we're extracting the file twice, make above work
  302. if(isset($meta_tag_array['oar-server'])) {
  303. //Found in the meta tags
  304. $this->oar_server = $meta_tag_array['oar-server'];
  305. $a_match = $this->oar_server;
  306. //Use for testing:
  307. //$meta_tag_array['oar-options'] = "text_box|query|Enter your search terms"; //TEMPIN!!
  308. //Now check for options meta tags
  309. if(isset($meta_tag_array['oar-options'])) {
  310. $this->filters_now = true;
  311. //echo "In here" . $meta_tag_array['oar-options'];
  312. $this->oar_filters = $meta_tag_array['oar-options'];
  313. }
  314. //Now check for map marker meta tags
  315. if(isset($meta_tag_array['oar-mapmarker'])) {
  316. //echo "In here" . $meta_tag_array['oar-options'];
  317. $this->oar_mapmarker = $meta_tag_array['oar-mapmarker'];
  318. }
  319. } else {
  320. $robotstxt = @file("http://{$parsed['host']}/robots.txt");
  321. if($robotstxt) {
  322. foreach($robotstxt as $line) {
  323. if(preg_match('/OAR-server: (.*)/i', $line, $match)) {
  324. //Found a match
  325. $this->oar_server = $match[1];
  326. $a_match = $this->oar_server;
  327. //Check for options
  328. if(preg_match('/OAR-options: (.*)/i', $line, $match)) {
  329. $this->oar_filters = $match[1];
  330. $this->filters_now = true;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. //Get additional meta tags
  337. if(isset($meta_tag_array['oar-logo'])) {
  338. $this->oar_logo = $meta_tag_array['oar-logo'];
  339. }
  340. if(isset($meta_tag_array['oar-description'])) {
  341. $this->oar_description = $meta_tag_array['oar-description'];
  342. }
  343. //This is a temporary hack - need to read proper favicon tags
  344. if(isset($meta_tag_array['oar-favicon'])) {
  345. $this->favicon = $meta_tag_array['oar-favicon'];
  346. }
  347. if(isset($meta_tag_array['oar-ads-id'])) {
  348. $this->rvolve_user_id = $meta_tag_array['oar-ads-id'];
  349. }
  350. }
  351. }
  352. return $a_match;
  353. }
  354. public function check_replace($param, $value, $replace, $with, $replace2, $with2, $post = false)
  355. {
  356. //Creates a URL name/value pair, but replaces an existing one with a new value if necessary
  357. if(($replace == $param)&&
  358. ($replace != null)) {
  359. $value = $with;
  360. }
  361. if(($replace2 == $param)&&
  362. ($replace2 != null)) {
  363. $value = $with2;
  364. }
  365. if($post == true) {
  366. return "<input type='hidden' name=\"". $param ."\" value=\"" . $value . "\">";
  367. } else {
  368. return "&" . $param . "=" . $value;
  369. }
  370. }
  371. public function get_current_url($replace = null, $with = null, $replace2 = null, $with2 = null, $external = false, $include_latlon = true, $post = false)
  372. {
  373. if($include_latlon === true) {
  374. if($post == false) {
  375. $layer = $layer . "lat=" . $this->latitude . "&lon=" . $this->longitude;
  376. } //we always include lat/lon in the post request
  377. }
  378. //Add filter's parameters
  379. if($this->query_1_param) {
  380. //This has a text query too
  381. $query1 = $this->query_1_param;
  382. if($external == true) {
  383. $query1 = "query1_" . $this->query_1_param;
  384. }
  385. $layer .= $this->check_replace($query1, urlencode($this->query_1_val), $replace, $with, $replace2, $with2, $post); //TODO: search for 'mobile phone' on thundre, eventually urlencodes one too many times
  386. } else {
  387. if(post == false) {
  388. //No filters and importantly, we pass a determine_filters request in. At the server end this
  389. //can be use to not carry out a search, for speed, but just pass back the filters themselves.
  390. $layer .= $this->check_replace("determine_filters", "1", $replace, $with, $replace2, $with2);
  391. }
  392. }
  393. if($this->query_2_param) {
  394. //This has a text query too
  395. $query2 = $this->query_2_param;
  396. if($external == true) {
  397. $query1 = "query2_" . $this->query_2_param;
  398. }
  399. $layer .= $this->check_replace($query2, urlencode($this->query_2_val), $replace, $with, $replace2, $with2, $post);
  400. }
  401. if($this->query_3_param) {
  402. //This has a text query too
  403. $query3 = $this->query_3_param;
  404. if($external == true) {
  405. $query3 = "query3_" . $this->query_3_param;
  406. }
  407. $layer .= $this->check_replace($query3, urlencode($this->query_3_val), $replace, $with, $replace2, $with2, $post);
  408. }
  409. if($this->page_key != 0) {
  410. if($post == false) {
  411. //This is a second page or further
  412. $layer .= $this->check_replace("pageKey", $this->page_key, $replace, $with, $replace2, $with2);
  413. } //we always include page key in the post
  414. }
  415. if($this->view_type != 0) {
  416. if($post == false) {
  417. $layer .= $this->check_replace("viewType", $this->view_type, $replace, $with, $replace2, $with2);
  418. } ////we always include view type in the post
  419. }
  420. if($this->search_now != 0) {
  421. $layer .= $this->check_replace("srch", $this->search_now, $replace, $with, $replace2, $with2, $post);
  422. }
  423. if($this->address) {
  424. if($post == false) {
  425. $layer .= $this->check_replace("address", urlencode($this->address), $replace, $with, $replace2, $with2);
  426. } //we always include the address in a post request
  427. }
  428. if($this->template_url != '') {
  429. $layer .= $this->check_replace("template", $this->template_url, $replace, $with, $replace2, $with2, $post);
  430. }
  431. if($this->link_target != '') {
  432. $layer .= $this->check_replace("linkTarget", $this->link_target, $replace, $with, $replace2, $with2, $post);
  433. }
  434. if($this->geo_bias != '') {
  435. $layer .= $this->check_replace("geoBias", $this->geo_bias, $replace, $with, $replace2, $with2, $post);
  436. }
  437. if($this->list_height != '') {
  438. $layer .= $this->check_replace("listHeight", $this->list_width . "," . $this->list_height, $replace, $with, $replace2, $with2, $post);
  439. }
  440. if($this->rvolve_user_id != '') {
  441. $layer .= $this->check_replace("rvolve", $this->rvolve_user_id, $replace, $with, $replace2, $with2, $post);
  442. }
  443. return $layer;
  444. }
  445. public function read_layer()
  446. {
  447. //Read the JSON
  448. $results = array();
  449. if(strpos($this->oar_server, "?") === false) {
  450. $layer = $this->oar_server . "?";
  451. } else {
  452. $layer = $this->oar_server . "&";
  453. }
  454. $layer.= $this->get_current_url();
  455. //echo $layer;
  456. //Read the actual layer
  457. $json = file_get_contents($layer);
  458. if ($json != false) {
  459. $this->results = json_decode($json, true);
  460. }
  461. //http://www.padzz-business.co.uk/layar-server.php?countryCode=NL&lon=-0.102996826172&timestamp=1262892521148&userId=6f85d06929d160a7c8a3cc1ab4b54b87db99f74b&developerId=2616&developerHash=f0293c7a476a8a157f116a2d7d946427ee75aabd&radius=5000&lat=51.4548626583&layerName=padzdev&phoneId=6f85d06929d160a7c8a3cc1ab4b54b87db99f74b&accuracy=100
  462. //http://www.padzz-business.co.uk/layar-server.php?radius=5000&lat=51.4548626583&lon=-0.102996826172&layerName=padzdev
  463. return $this->results;
  464. }
  465. public function display_layer($results)
  466. {
  467. //Called from the HTML layer file
  468. //Input an array in Layar format and display as a results set
  469. //print_r($results);
  470. if((($results['searchFilters'] === true)&&($this->search_now != 1))|| //JSON return case
  471. (($this->filters_now == true)&&($this->search_now != 1))) { //Meta tag options case
  472. //We want to show the search filter(s)
  473. require_once("layouts/lay_search_filters.php");
  474. } else {
  475. //Show results
  476. switch($this->view_type)
  477. {
  478. case LIST_VIEW:
  479. {
  480. if(count($results) > 0) {
  481. if(is_array($results)) {
  482. if($results['errorCode'] == 0) {
  483. //Display the results
  484. require_once("layouts/lay_results.php");
  485. }
  486. else {
  487. echo $results['errorString'];
  488. }
  489. } else {
  490. ?>
  491. Invalide. Les messages d'erreurs suivant ont &eacute;t&eacute; enregist&eacute;s:
  492. <?php
  493. echo $results;
  494. }
  495. } else {
  496. ?>Aucun r&eacute;sultat !
  497. <?php
  498. }
  499. }
  500. break;
  501. case MAP_VIEW:
  502. {
  503. //Display the map no matter what
  504. require_once("layouts/lay_map_results.php");
  505. }
  506. break;
  507. }
  508. }
  509. /*
  510. Array
  511. (
  512. [layer] => padzdev
  513. [errorString] => ok
  514. [morePages] =>
  515. [errorCode] => 0
  516. [nextPageKey] =>
  517. [hotspots] => Array
  518. (
  519. [0] => Array
  520. (
  521. [actions] => Array
  522. (
  523. [0] => Array
  524. (
  525. [uri] => http://www.padz.com
  526. [label] => My Action
  527. [autoTriggerRange] =>
  528. [autoTriggerOnly] =>
  529. )
  530. )
  531. [attribution] => LightRod.org
  532. [distance] => 0.0496695185
  533. [id] => 1715
  534. [imageURL] => http://www.padzz-business.co.uk/assets/adverts/images/p-mayfair-house-95.jpg
  535. [lat] => 51500152
  536. [lon] => -126236
  537. [line2] => Hi there
  538. [line3] =>
  539. [line4] =>
  540. [title] => My Marker
  541. [dimension] =>
  542. [transform] => Array
  543. (
  544. [rel] =>
  545. [angle] => 0
  546. [scale] => 0
  547. )
  548. [object] => Array
  549. (
  550. [baseURL] =>
  551. [full] =>
  552. [reduced] =>
  553. [icon] =>
  554. [size] =>
  555. )
  556. [alt] =>
  557. [relative_alt] =>
  558. [type] => 0
  559. )
  560. [1] => Array
  561. (
  562. [actions] => Array
  563. (
  564. [0] => Array
  565. (
  566. [uri] => http://www.padz.com
  567. [label] => My Action
  568. [autoTriggerRange] =>
  569. [autoTriggerOnly] =>
  570. )
  571. )
  572. */
  573. }
  574. static function limit_chars($input_string, $max_chars, $break_string, $clip_hard = true)
  575. {
  576. //Pass in a string and chop at the max number of chars, but on a word basis. Append break_string (usually ".." or "...")
  577. //afterwards. Returns the new string.
  578. //Clip hard set to true, will chop a word in two at the max number of chars if it is overridden - this
  579. //is the case when you have a small number of $max_chars.
  580. //Break_string is often ".."
  581. if(strlen($input_string) > $max_chars) {
  582. $input_string = current(explode("\n", wordwrap($input_string, $max_chars, "\n"))) . $break_string; //This gets the full words.
  583. }
  584. if($clip_hard == true) {
  585. if(strlen($author) > $max_chars+strlen($break_string)) {
  586. //Still longer than the size + the '..'s. Must be a single long word. Trim off the characters
  587. $author = substr($author, 0, $max_chars) . $break_string;
  588. }
  589. }
  590. return $input_string;
  591. }
  592. function get_favicon($html) {
  593. //TODO: make this function work and get the proper fav icon
  594. preg_match_all("|<link[^>]+name=\"([^\"]*)\"[^>]+content=\"([^\"]*)\"[^>]+>|i", $html, $out,PREG_PATTERN_ORDER);
  595. for ($i=0;$i < count($out[1]);$i++) {
  596. // loop through the meta data - add your own tags here if you need
  597. if (strtolower($out[1][$i]) == "keywords") $meta['keywords'] = $out[2][$i];
  598. if (strtolower($out[1][$i]) == "description") $meta['description'] = $out[2][$i];
  599. }
  600. return $meta;
  601. }
  602. public function get_body_onload()
  603. {
  604. //Gets the javascript for a body onload command - separated so that we can insert it into
  605. //a template
  606. $this->body_onload = "";
  607. if((isset($_REQUEST['url']))&&($this->latitude != 0.0)&&($this->longitude!=0.0)) {
  608. //Already have location
  609. if($this->view_type == MAP_VIEW) {
  610. $this->body_onload = "initializeMap(" . $this->latitude . "," . $this->longitude . "," . $this->init_map_zoom . ");";
  611. }
  612. } else {
  613. //Find location
  614. if($this->address != '') {
  615. //Use inputted location
  616. $this->body_onload .= "geocodeAddress(\"" . $this->address . "\"); initializeMap(document.lpf.lat.value, document.lpf.lon.value," . $this->init_map_zoom . ");";
  617. //if($this->view_type == LIST_VIEW) {
  618. //If it is a list view, then we have to do another search?
  619. // $this->body_onload .= " document.lpf.submit()";
  620. //}
  621. } else {
  622. //Get user to input location
  623. $this->body_onload = "atl_submit_on_success=false; find_location();";
  624. if($this->view_type == MAP_VIEW) {
  625. $this->body_onload .= "initializeMap(" . $this->latitude . "," . $this->longitude . "," . $this->init_map_zoom . ");";
  626. }
  627. }
  628. }
  629. }
  630. public function parse_template_basic($template_url)
  631. {
  632. //Take the URL, extract the text from the file into a string and search for text 'OWLZ_FULL_BODY'
  633. //e.g. http://www.atomjump.com/clients/byke/, where would pass in 'clients/byke/'
  634. //Would have to be from the same domain as the content to stop site cross-scripting security holes.
  635. //So we append the url to the content url that is being browsed.
  636. //Also include in the body onload - the body onload var, and in the body unload, "GUnload();"
  637. //echo $this->url_with_http . $template_url;
  638. $full_url = $this->url_with_http;
  639. if(substr($full_url, -1) != '/') { //append a / if not there already
  640. $full_url .= "/";
  641. }
  642. $full_url .= $template_url;
  643. $html = file_get_contents($full_url);
  644. if ($html != false) {
  645. //echo "In here";
  646. //Try inserting into the onload statement
  647. $pattern = '/onload[ ]*=[ ]*"(.*?)"/i';
  648. $replacement = 'onload=\"${1}' . ";" . $this->body_onload . "\"";
  649. $html = preg_replace($pattern, $replacement, $html, 1, $count);
  650. if($count < 1) {
  651. //No existing onload found. Insert the onload after the body
  652. //echo "no match";
  653. $html = preg_replace("/\<[ ]*body[ ]*/i", "<body onload='" . $this->body_onload . "' ", $html, 1, $count_b);
  654. } else {
  655. //echo "match found";
  656. }
  657. //Now insert into the unload statement
  658. // onunload="GUnload();"
  659. $pattern = '/onunload[ ]*=[ ]*"(.*?)"/i';
  660. $replacement = '${1}' . "; GUnload();";
  661. $html = preg_replace($pattern, $replacement, $html, 1, $count);
  662. if($count < 1) {
  663. //No existing onunload found. Insert the onload after the body
  664. //echo "no match";
  665. $html = preg_replace("/\<[ ]*body[ ]*/i", "<body onunload='GUnload();' ", $html, 1, $count_b);
  666. } else {
  667. //echo "match found";
  668. }
  669. //Now insert into the header some header stuff
  670. $header = $this->get_oar_header_as_var();
  671. $html = preg_replace("/\<head\>/i", "<head> " . $header, $html);
  672. //Get the text before 'OWLZ_FULL_BODY'
  673. //preg_match("/(.*?)OWLZ_FULL_BODY(.*?)/g", $html, $matches);
  674. $matches = preg_split("/OWLZ_FULL_BODY/", $html);
  675. $status = true;
  676. } else {
  677. //echo "No template";
  678. //Default to no template - couldn't read properly
  679. $status = false;
  680. }
  681. $return_array[] = $matches[0];
  682. $return_array[] = $matches[1];
  683. $return_array[] = $status;
  684. return $return_array;
  685. }
  686. public function oar_header($oar_browser_dir)
  687. {
  688. ?>
  689. <script type="text/javascript">
  690. function premap_message() {
  691. document.getElementById("location_message").innerHTML = "We recommend downloading Firefox 3.5 and clicking 'Geolocate me', otherwise zoom in on your shopping destination by doubling clicking on the map to street level.";
  692. }
  693. function searchAgainIfResults() {
  694. <?php //If this is a results page, and we've just found a location, call the submit to do a search again
  695. //from this new location
  696. if(isset($this->results)) { ?>
  697. document.lpf.submit();
  698. <?php } ?>
  699. }
  700. </script>
  701. <script src="<?php echo $oar_browser_dir ?>js/geolocation.js" type="text/javascript"></script>
  702. <script src="<?php echo $oar_browser_dir ?>js/homepage.js" type="text/javascript"></script>
  703. <!-- We haven't yet styled this properly: TODO -->
  704. <link rel="stylesheet" type="text/css" href="css/main.css?version=1.1"/>
  705. <?php //See http://www.boutell.com/newfaq/creating/iphone.html ?>
  706. <!--[if !IE]>-->
  707. <link media="only screen and (max-width: 480px)"
  708. rel="stylesheet" type="text/css" href="css/phone.css"/>
  709. <!--<![endif]-->
  710. <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo GOOGLE_MAPS_KEY; ?>
  711. &sensor=true"
  712. type="text/javascript"></script>
  713. <script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript" charset="utf-8"></script>
  714. <script src="<?php echo $oar_browser_dir ?>js/geo.js" type="text/javascript" charset="utf-8"></script>
  715. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  716. <script src="<?php echo $oar_browser_dir ?>js/location-input.js?version=2" type="text/javascript"></script>
  717. <script type="text/javascript" src="<?php echo $oar_browser_dir ?>js/jquery-1.3.1.min.js"></script>
  718. <?php
  719. return;
  720. }
  721. public function get_oar_header_as_var() {
  722. //Put require output into a variable
  723. ob_start();
  724. $this->oar_header($this->oar_browser_dir);
  725. return ob_get_clean();
  726. }
  727. }
  728. //Get the body onload
  729. $oar->get_body_onload();
  730. if(!$oar->template_url) {
  731. //Include the main page
  732. require("layouts/lay_main_page.php");
  733. } else {
  734. //A basic template - parse the template
  735. list($before_main, $after_main, $status) = $oar->parse_template_basic($oar->template_url);
  736. if($status == true) {
  737. echo $before_main;
  738. require("layouts/lay_main_page.php");
  739. echo $after_main;
  740. } else {
  741. //Just a normal page - error reading template
  742. $oar->template_url = "";
  743. require("layouts/lay_main_page.php");
  744. }
  745. }
  746. ?>