getdirections.module 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666
  1. <?php
  2. /**
  3. * @file
  4. * Fetches google map directions.
  5. */
  6. define('GETDIRECTIONS_PATH', drupal_get_path('module', 'getdirections'));
  7. /**
  8. * Implements hook_help().
  9. */
  10. function getdirections_help($path, $arg) {
  11. switch ($path) {
  12. case 'admin/help#getdirections':
  13. $output = '<p>' . t('Fetches google map directions.') . '</p>';
  14. return $output;
  15. }
  16. }
  17. /**
  18. * Implements hook_init().
  19. */
  20. function getdirections_init() {
  21. if (! module_load_include('inc', 'getdirections', 'getdirections.config')) {
  22. define('GETDIRECTIONS_WAYPOINTS_MAX', 8);
  23. }
  24. module_load_include('inc', 'getdirections', 'getdirections.api');
  25. if (module_exists('colorbox')) {
  26. $getdirections_colorbox = variable_get('getdirections_colorbox', array(
  27. 'enable' => 0,
  28. 'width' => 600,
  29. 'height' => 600,
  30. ));
  31. $settings = array('getdirections_colorbox' => $getdirections_colorbox);
  32. drupal_add_js($settings, 'setting');
  33. drupal_add_js(GETDIRECTIONS_PATH . '/js/getdirections.js');
  34. }
  35. }
  36. /**
  37. * Implements hook_permission().
  38. */
  39. function getdirections_permission() {
  40. return array(
  41. 'access gmap getdirections' => array(
  42. 'title' => t('Access Getdirections'),
  43. 'description' => t('View and use the Getdirections module.')
  44. ),
  45. 'access user getdirections' => array(
  46. 'title' => t('Access user Getdirections'),
  47. 'description' => t('View users with the Getdirections module.')
  48. ),
  49. );
  50. }
  51. /**
  52. * Implement hook_menu().
  53. */
  54. function getdirections_menu() {
  55. $items = array();
  56. $items['admin/config/services/getdirections'] = array(
  57. 'title' => 'Get directions',
  58. 'description' => 'Configure Get directions',
  59. 'page callback' => 'drupal_get_form',
  60. 'page arguments' => array('getdirections_settings_form'),
  61. 'access arguments' => array('administer site configuration'),
  62. 'type' => MENU_NORMAL_ITEM,
  63. 'file' => 'getdirections.admin.inc',
  64. );
  65. $items['getdirections'] = array(
  66. 'title' => 'Get directions',
  67. 'description' => 'Get directions on a map',
  68. 'access arguments' => array('access gmap getdirections'),
  69. 'page callback' => 'getdirections_direction',
  70. 'type' => MENU_SUGGESTED_ITEM,
  71. );
  72. // location enabled
  73. $items['getdirections/location/%getdirections_fromto/%getdirections_id'] = array(
  74. 'title' => 'Get directions',
  75. 'access callback' => 'getdirections_access_location',
  76. 'page callback' => 'getdirections_node_setlocation',
  77. 'page arguments' => array(2, 3),
  78. 'type' => MENU_CALLBACK,
  79. );
  80. $items['getdirections/locations/%getdirections_id/%getdirections_id'] = array(
  81. 'title' => 'Get directions',
  82. 'access callback' => 'getdirections_access_location',
  83. 'page callback' => 'getdirections_node_setlocations',
  84. 'page arguments' => array(2, 3),
  85. 'type' => MENU_CALLBACK,
  86. );
  87. $items['getdirections/locations_via/%getdirections_via'] = array(
  88. 'title' => 'Get directions',
  89. 'access callback' => 'getdirections_access_location',
  90. 'page callback' => 'getdirections_node_setlocations_via',
  91. 'page arguments' => array(2),
  92. 'type' => MENU_CALLBACK,
  93. );
  94. $items['getdirections/location_user/%getdirections_fromto/%getdirections_uid'] = array(
  95. 'title' => 'Get directions',
  96. 'access callback' => 'getdirections_access_user_location',
  97. 'page callback' => 'getdirections_user_setlocation',
  98. 'page arguments' => array(2, 3),
  99. 'type' => MENU_CALLBACK,
  100. );
  101. $items['getdirections/locations_user/%getdirections_uid/%getdirections_uid'] = array(
  102. 'title' => 'Get directions',
  103. 'access callback' => 'getdirections_access_user_location',
  104. 'page callback' => 'getdirections_user_setlocations',
  105. 'page arguments' => array(2, 3),
  106. 'type' => MENU_CALLBACK,
  107. );
  108. $items['getdirections/location_n2u/%getdirections_id/%getdirections_uid'] = array(
  109. 'title' => 'Get directions',
  110. 'access callback' => 'getdirections_access_user_location',
  111. 'page callback' => 'getdirections_n2u_setlocation',
  112. 'page arguments' => array(2, 3),
  113. 'type' => MENU_CALLBACK,
  114. );
  115. $items['getdirections/location_u2n/%getdirections_uid/%getdirections_id'] = array(
  116. 'title' => 'Get directions',
  117. 'access callback' => 'getdirections_access_user_location',
  118. 'page callback' => 'getdirections_u2n_setlocation',
  119. 'page arguments' => array(2, 3),
  120. 'type' => MENU_CALLBACK,
  121. );
  122. $items['getdirections/locations_user_via/%getdirections_via'] = array(
  123. 'title' => 'Get directions',
  124. 'access callback' => 'getdirections_access_location',
  125. 'page callback' => 'getdirections_user_setlocations_via',
  126. 'page arguments' => array(2),
  127. 'type' => MENU_CALLBACK,
  128. );
  129. $items['getdirections/latlon/%getdirections_fromto/%getdirections_latlon/%'] = array(
  130. 'title' => 'Get directions',
  131. 'access arguments' => array('access gmap getdirections'),
  132. 'page callback' => 'getdirections_latlon',
  133. 'page arguments' => array(2, 3, 4),
  134. 'type' => MENU_CALLBACK,
  135. );
  136. $items['getdirections/latlons/%'] = array(
  137. 'title' => 'Get directions',
  138. 'access arguments' => array('access gmap getdirections'),
  139. 'page callback' => 'getdirections_latlons',
  140. 'page arguments' => array(2),
  141. 'type' => MENU_CALLBACK,
  142. );
  143. $items['getdirections/location_id/%getdirections_fromto/%getdirections_id'] = array(
  144. 'title' => 'Get directions',
  145. 'access callback' => 'getdirections_access_location',
  146. 'page callback' => 'getdirections_setlocation_id',
  147. 'page arguments' => array(2, 3),
  148. 'type' => MENU_CALLBACK,
  149. );
  150. if (getdirections_get_vocabularies()) {
  151. // taxonomy_term
  152. $items['getdirections/location_term/%getdirections_fromto/%getdirections_id'] = array(
  153. 'title' => 'Get directions',
  154. 'access callback' => 'getdirections_access_location',
  155. 'page callback' => 'getdirections_term_setlocation',
  156. 'page arguments' => array(2, 3),
  157. 'type' => MENU_CALLBACK,
  158. );
  159. }
  160. if (getdirections_check_entity_type('comment')) {
  161. // comment
  162. $items['getdirections/location_comment/%getdirections_fromto/%getdirections_id'] = array(
  163. 'title' => 'Get directions',
  164. 'access callback' => 'getdirections_access_location',
  165. 'page callback' => 'getdirections_comment_setlocation',
  166. 'page arguments' => array(2, 3),
  167. 'type' => MENU_CALLBACK,
  168. );
  169. }
  170. $items['getdirections/%getdirections_entity_type/%getdirections_fromto/%getdirections_id'] = array(
  171. 'title' => 'Get directions',
  172. 'access callback' => 'getdirections_access_location',
  173. 'page callback' => 'getdirections_entity_setlocation',
  174. 'page arguments' => array(1, 2, 3),
  175. 'type' => MENU_CALLBACK,
  176. );
  177. $items['getdirections/%getdirections_entity_type/%getdirections_id/%getdirections_entity_type/%getdirections_id'] = array(
  178. 'title' => 'Get directions',
  179. 'access callback' => 'getdirections_access_location',
  180. 'page callback' => 'getdirections_entity_setlocations',
  181. 'page arguments' => array(1, 2, 3, 4),
  182. 'type' => MENU_CALLBACK,
  183. );
  184. $items['getdirections_box'] = array(
  185. 'title' => 'Get directions',
  186. 'access arguments' => array('access gmap getdirections'),
  187. 'page callback' => 'getdirections_direction_box',
  188. 'type' => MENU_CALLBACK,
  189. );
  190. if (module_exists('date_popup')) {
  191. $items['getdirections/getdirections_get_datestamp'] = array(
  192. 'access arguments' => array('access gmap getdirections'),
  193. 'page callback' => 'getdirections_get_datestamp',
  194. 'type' => MENU_CALLBACK,
  195. );
  196. }
  197. if (module_exists('smart_ip')) {
  198. $items['getdirections/smart_ip'] = array(
  199. 'page callback' => 'getdirections_smart_ip',
  200. 'access arguments' => array('access content'),
  201. 'type' => MENU_CALLBACK,
  202. );
  203. }
  204. if (module_exists('ip_geoloc')) {
  205. $items['getdirections/ip_geoloc'] = array(
  206. 'page callback' => 'getdirections_ip_geoloc',
  207. 'access arguments' => array('access content'),
  208. 'type' => MENU_CALLBACK,
  209. );
  210. }
  211. return $items;
  212. }
  213. /**
  214. * menu placeholder functions
  215. */
  216. function getdirections_fromto_load($arg) {
  217. $allowed = array('from', 'to');
  218. return ( in_array($arg, $allowed) ? $arg : FALSE);
  219. return $arg;
  220. }
  221. function getdirections_id_load($arg) {
  222. return (is_numeric($arg) && $arg > 0 ? $arg : FALSE);
  223. }
  224. function getdirections_uid_load($arg) {
  225. return ((is_numeric($arg) && $arg > 0 && getdirections_user_check($arg)) ? $arg : FALSE);
  226. }
  227. function getdirections_via_load($arg) {
  228. if (stristr($arg, ',')) {
  229. $x = explode(',', $arg);
  230. foreach ($x as $v) {
  231. if (! is_numeric($v)) {
  232. return FALSE;
  233. }
  234. }
  235. return $arg;
  236. }
  237. return FALSE;
  238. }
  239. function getdirections_latlon_load($arg) {
  240. if (getdirections_latlon_check($arg)) {
  241. return $arg;
  242. }
  243. return FALSE;
  244. }
  245. function getdirections_entity_type_load($arg) {
  246. if (getdirections_check_entity_type($arg)) {
  247. return $arg;
  248. }
  249. return FALSE;
  250. }
  251. /**
  252. * menu access functions
  253. */
  254. function getdirections_access_location() {
  255. if (user_access('access gmap getdirections')) {
  256. if (getdirections_get_current_supported_module()) {
  257. return TRUE;
  258. }
  259. }
  260. return FALSE;
  261. }
  262. function getdirections_access_user_location() {
  263. if (user_access('access user getdirections') && getdirections_check_entity_type('user')) {
  264. return TRUE;
  265. }
  266. return FALSE;
  267. }
  268. /**
  269. * Function to setup the map and form
  270. *
  271. * @param string $direction
  272. * Optional. The direction the supplied input applies to
  273. * @param string $location
  274. * Optional. The string to search with
  275. * @param string $country
  276. * Optional. The country
  277. * @param string $latlon
  278. * Optional. Comma delimited string containing latitude and longitude
  279. * @return
  280. * Returns the themed map and form
  281. */
  282. function getdirections_direction($direction='', $location='', $country='', $latlon='', $entity_id=0, $entity_type='node', $width='', $height='') {
  283. if (! getdirections_check()) {
  284. return t('You need to !c first.', array('!c' => l('configure Getdirections', 'admin/config/services/getdirections')));
  285. }
  286. $getdirections_defaults = getdirections_defaults();
  287. $getdirections_misc = getdirections_misc_defaults();
  288. getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  289. $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  290. $mapid = getdirections_get_key();
  291. drupal_add_js(array('getdirections' => array($mapid => $getdirections_settings)), 'setting');
  292. if ($getdirections_misc['keep_title'] && $entity_id && $direction) {
  293. if ($direction == 'to') {
  294. $direction_translated = t('to');
  295. }
  296. elseif ($direction == 'from') {
  297. $direction_translated = t('from');
  298. }
  299. // entityfy this
  300. if ($entity_type == 'term') {
  301. $entity_type = 'taxonomy_term';
  302. }
  303. // is it location enabled?
  304. if (getdirections_check_entity_type($entity_type)) {
  305. $entity_get_info = entity_get_info($entity_type);
  306. if ($entity_get_info['fieldable']) {
  307. $load_hook = $entity_get_info['load hook'];
  308. $entity = $load_hook($entity_id);
  309. $entity_title = '';
  310. if (isset($entity_get_info['entity keys']['label'])) {
  311. $entity_title = $entity_get_info['entity keys']['label'];
  312. }
  313. elseif ($entity_type == 'user') {
  314. $entity_title = 'name';
  315. }
  316. if (isset($entity->{$entity_title})) {
  317. $title = $entity->{$entity_title};
  318. drupal_set_title(t('Get directions @d !t', array('@d' => $direction_translated, '!t' => $title)));
  319. }
  320. }
  321. }
  322. }
  323. if (empty($width)) {
  324. $width = $getdirections_defaults['width'];
  325. }
  326. if (empty($height)) {
  327. $height = $getdirections_defaults['height'];
  328. }
  329. // remove brackets if any
  330. $latlon = preg_replace("/^\(|\)$/", '', $latlon);
  331. $raw_form = drupal_get_form('getdirections_direction_form', $mapid, $direction, $location, $country, $latlon);
  332. $form = render($raw_form);
  333. return theme('getdirections_show', array('form' => $form, 'mapid' => $mapid, 'width' => $width, 'height' => $height, 'entity_id' => $entity_id, 'entity_type' => $entity_type));
  334. }
  335. /**
  336. * Function to setup the map and form
  337. *
  338. * @param string $direction
  339. * Optional. The direction the supplied input applies to
  340. * @param string $location
  341. * Optional. The string to search with
  342. * @param string $country
  343. * Optional. The country
  344. * @param string $latlon
  345. * Optional. Comma delimited string containing latitude and longitude
  346. * @param int $lid
  347. * Optional. location identifier
  348. * @param $type
  349. * Optional. Used to distinguish various sources
  350. * @return
  351. * Returns the themed map and form
  352. */
  353. function getdirections_direction_other($direction='', $location='', $country='', $latlon='', $lid=0, $type='', $width='', $height='') {
  354. if (! getdirections_check()) {
  355. return t('You need to !c first.', array('!c' => l('configure Getdirections', 'admin/config/services/getdirections')));
  356. }
  357. $getdirections_defaults = getdirections_defaults();
  358. $getdirections_misc = getdirections_misc_defaults();
  359. getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  360. $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  361. $mapid = getdirections_get_key();
  362. drupal_add_js(array('getdirections' => array($mapid => $getdirections_settings)), 'setting');
  363. if ($getdirections_misc['keep_title'] && $lid && $direction) {
  364. if ($type == 'location') {
  365. if ($direction == 'to') {
  366. $direction_translated = t('to');
  367. }
  368. elseif ($direction == 'from') {
  369. $direction_translated = t('from');
  370. }
  371. $t = getdirections_get_lid_title($lid);
  372. if ($t) {
  373. drupal_set_title(t('Get directions @d !t', array('@d' => $direction_translated, '!t' => $t)));
  374. }
  375. }
  376. }
  377. if (empty($width)) {
  378. $width = $getdirections_defaults['width'];
  379. }
  380. if (empty($height)) {
  381. $height = $getdirections_defaults['height'];
  382. }
  383. // remove brackets if any
  384. $latlon = preg_replace("/^\(|\)$/", '', $latlon);
  385. $raw_form = drupal_get_form('getdirections_direction_form', $mapid, $direction, $location, $country, $latlon);
  386. $form = render($raw_form);
  387. return theme('getdirections_show', array('form' => $form, 'mapid' => $mapid, 'width' => $width, 'height' => $height, 'entity_id' => 0, 'entity_type' => '', 'lid' => $lid, 'type' => $type));
  388. }
  389. /**
  390. * Function to setup the map
  391. *
  392. * @param string $fromlocs
  393. * Required. The string to display for From.
  394. * @param string $fromlatlon
  395. * Required. The location point for From. In decimal latitude,longitude
  396. * @param string $tolocs
  397. * Required. The string to display for To.
  398. * @param string $tolatlon
  399. * Required. The location point for To. In decimal latitude,longitude
  400. * @return
  401. * Returns the themed map.
  402. */
  403. function getdirections_locations($fromlocs, $fromlatlon, $tolocs, $tolatlon, $width='', $height='') {
  404. if (! getdirections_check()) {
  405. return t('You need to !c first.', array('!c' => l('configure Getdirections', 'admin/config/services/getdirections')));
  406. }
  407. $getdirections_defaults = getdirections_defaults();
  408. $getdirections_misc = getdirections_misc_defaults();
  409. getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  410. $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  411. // remove brackets if any
  412. $fromlatlon = preg_replace("/^\(|\)$/", '', $fromlatlon);
  413. $getdirections_settings['fromlatlon'] = $fromlatlon;
  414. $tolatlon = preg_replace("/^\(|\)$/", '', $tolatlon);
  415. $getdirections_settings['tolatlon'] = $tolatlon;
  416. $mapid = getdirections_get_key();
  417. drupal_add_js(array('getdirections' => array($mapid => $getdirections_settings)), 'setting');
  418. if (empty($width)) {
  419. $width = $getdirections_defaults['width'];
  420. }
  421. if (empty($height)) {
  422. $height = $getdirections_defaults['height'];
  423. }
  424. return theme('getdirections_show_locations', array('mapid' => $mapid, 'width' => $width, 'height' => $height, 'fromlocs' => $fromlocs, 'tolocs' => $tolocs));
  425. }
  426. /**
  427. * Function to setup the map
  428. *
  429. * @param array $locs
  430. * Required. An array of location descriptions.
  431. * @param array $latlons
  432. * Required. An array of decimal latitude,longitude
  433. * @return
  434. * Returns the themed map.
  435. */
  436. function getdirections_locations_via($locs, $latlons, $width='', $height='') {
  437. if (! getdirections_check()) {
  438. return t('You need to !c first.', array('!c' => l('configure Getdirections', 'admin/config/services/getdirections')));
  439. }
  440. $getdirections_defaults = getdirections_defaults();
  441. $getdirections_misc = getdirections_misc_defaults();
  442. getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  443. $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  444. $getdirections_settings['latlons'] = implode('|', $latlons);
  445. $mapid = getdirections_get_key();
  446. drupal_add_js(array('getdirections' => array($mapid => $getdirections_settings)), 'setting');
  447. if (empty($width)) {
  448. $width = $getdirections_defaults['width'];
  449. }
  450. if (empty($height)) {
  451. $height = $getdirections_defaults['height'];
  452. }
  453. return theme('getdirections_show_locations_via', array('mapid' => $mapid, 'width' => $width, 'height' => $height, 'locs' => $locs));
  454. }
  455. /**
  456. *
  457. *
  458. */
  459. function getdirections_get_settings($getdirections_defaults, $getdirections_misc) {
  460. global $language, $is_https;
  461. $lla = explode(',', $getdirections_defaults['latlong']);
  462. $settings = array(
  463. 'lat' => $lla[0],
  464. 'lng' => $lla[1],
  465. 'zoom' => $getdirections_defaults['zoom'],
  466. 'controltype' => $getdirections_defaults['controltype'],
  467. 'pancontrol' => $getdirections_defaults['pancontrol'],
  468. 'mtc' => $getdirections_defaults['mtc'],
  469. 'maptype' => $getdirections_defaults['maptype'],
  470. 'baselayers' => $getdirections_defaults['baselayers'],
  471. 'unitsystem' => $getdirections_defaults['unitsystem'],
  472. 'scale' => $getdirections_defaults['scale'],
  473. 'overview' => $getdirections_defaults['overview'],
  474. 'overview_opened' => $getdirections_defaults['overview_opened'],
  475. 'scrollwheel' => $getdirections_defaults['scrollwheel'],
  476. 'draggable' => $getdirections_defaults['draggable'],
  477. 'streetview_show' => $getdirections_defaults['streetview_show'],
  478. 'transit_date_format' => $getdirections_defaults['transit_date_format'],
  479. 'map_backgroundcolor' => $getdirections_defaults['map_backgroundcolor'],
  480. 'waypoints' => intval($getdirections_defaults['waypoints']),
  481. 'waypoints_optimise' => intval($getdirections_defaults['waypoints_optimise']),
  482. 'waypoint_color' => $getdirections_defaults['waypoint_color'],
  483. 'advanced_autocomplete' => $getdirections_defaults['advanced_autocomplete'],
  484. 'advanced_autocomplete_bias' => $getdirections_defaults['advanced_autocomplete_bias'],
  485. 'advanced_autocomplete_via' => $getdirections_defaults['advanced_autocomplete_via'],
  486. 'panoramio_use' => $getdirections_misc['panoramio_use'],
  487. 'panoramio_show' => $getdirections_misc['panoramio_show'],
  488. 'panoramio_state' => $getdirections_misc['panoramio_state'],
  489. 'bicycleinfo' => $getdirections_misc['bicycleinfo'],
  490. 'bicycleinfo_state' => $getdirections_misc['bicycleinfo_state'],
  491. 'transitinfo' => $getdirections_misc['transitinfo'],
  492. 'transitinfo_state' => $getdirections_misc['transitinfo_state'],
  493. 'trafficinfo' => $getdirections_misc['trafficinfo'],
  494. 'trafficinfo_state' => $getdirections_misc['trafficinfo_state'],
  495. 'geolocation_enable' => $getdirections_misc['geolocation_enable'],
  496. 'geolocation_option' => $getdirections_misc['geolocation_option'],
  497. 'show_distance' => ($getdirections_misc['show_distance'] ? t('Total distance') : ''),
  498. 'show_duration' => ($getdirections_misc['show_duration'] ? t('Total duration') : ''),
  499. 'weather_use' => $getdirections_misc['weather_use'],
  500. 'weather_show' => $getdirections_misc['weather_show'],
  501. 'weather_state' => $getdirections_misc['weather_state'],
  502. 'weather_temp' => $getdirections_misc['weather_temp'],
  503. 'weather_speed' => $getdirections_misc['weather_speed'],
  504. 'weather_label' => $getdirections_misc['weather_label'],
  505. 'weather_cloud' => $getdirections_misc['weather_cloud'],
  506. 'weather_cloud_state' => $getdirections_misc['weather_cloud_state'],
  507. 'weather_clickable' => $getdirections_misc['weather_clickable'],
  508. 'weather_info' => $getdirections_misc['weather_info'],
  509. 'switchfromto' => $getdirections_misc['switchfromto'],
  510. 'use_https' => ($is_https ? 1 : 0),
  511. 'mylocale' => $language->language,
  512. 'smartip_callback_url' => url("getdirections/smart_ip"),
  513. 'ip_geoloc_callback_url' => url("getdirections/ip_geoloc"),
  514. 'nokeyboard' => $getdirections_defaults['nokeyboard'],
  515. 'nodoubleclickzoom' => $getdirections_defaults['nodoubleclickzoom'],
  516. );
  517. return $settings;
  518. }
  519. /**
  520. *
  521. *
  522. */
  523. function getdirections_get_key() {
  524. static $getdirections_mapid = 0;
  525. $getdirections_mapid++;
  526. return 'key_' . $getdirections_mapid;
  527. }
  528. /**
  529. * Function to setup the form
  530. *
  531. * @param string $fromto
  532. * Optional. The direction the supplied input applies to
  533. * @param string $loc
  534. * Optional. The string to search with
  535. * @param string $country
  536. * Optional. The country
  537. * @param string $latlon
  538. * Optional. Comma delimited string containing latitude and longitude
  539. * @return
  540. * Returns the form
  541. */
  542. function getdirections_direction_form($form, &$form_state, $mapid, $fromto='', $loc='', $country='', $latlon='') {
  543. $getdirections_defaults = getdirections_defaults();
  544. $getdirections_misc = getdirections_misc_defaults();
  545. $form = array();
  546. $form += _getdirections_direction_form($getdirections_defaults, $getdirections_misc, $mapid, $fromto, $loc, $country, $latlon);
  547. return $form;
  548. }
  549. /**
  550. *
  551. *
  552. */
  553. function _getdirections_direction_form($defaults, $misc, $mapid, $fromto='', $loc='', $country='', $latlon='') {
  554. $islocation = module_exists('location');
  555. $isgetlocations_fields = module_exists('getlocations_fields');
  556. if ($defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && ! $defaults['advanced_autocomplete']) {
  557. $default_country = ($islocation ? variable_get('location_default_country', '') : variable_get('site_default_country', ''));
  558. $countries = array(
  559. '#type' => 'select',
  560. '#title' => t('Country'),
  561. '#options' => array_merge(array('' => t('Please select')), ($islocation ? _location_supported_countries() : getlocations_fields_get_countries_list())),
  562. '#default_value' => $default_country,
  563. );
  564. }
  565. // weights
  566. if ($defaults['use_advanced']) {
  567. $from_country_weight = 1;
  568. $from_weight = 2;
  569. $to_country_weight = 3;
  570. $to_weight = 4;
  571. }
  572. else {
  573. $from_weight = 1;
  574. $from_country_weight = 2;
  575. $to_weight = 3;
  576. $to_country_weight = 4;
  577. }
  578. $form = array(
  579. '#action' => '#',
  580. '#attributes' => array(
  581. 'class' => array('getdirections_form'),
  582. ),
  583. );
  584. if ($fromto == 'from') {
  585. $form['from_' . $mapid] = array(
  586. '#type' => 'hidden',
  587. '#value' => $latlon,
  588. );
  589. if (empty($loc)) {
  590. if (empty($country)) {
  591. $mfrom = t('Starting point');
  592. }
  593. else {
  594. $mfrom = drupal_strtoupper($country);
  595. }
  596. }
  597. else {
  598. $mfrom = $loc;
  599. $form['from_address_' . $mapid] = array(
  600. '#type' => 'hidden',
  601. '#value' => $loc,
  602. );
  603. }
  604. $form['mfrom'] = array(
  605. '#type' => 'item',
  606. '#title' => t('From'),
  607. '#markup' => $mfrom,
  608. );
  609. }
  610. else {
  611. $from_desc = t('Enter the address, postcode and/or city and country from where you want to start your journey.');
  612. if ($defaults['use_advanced'] && $defaults['advanced_autocomplete']) {
  613. $from_desc = t('Start typing the address of your starting point, then select from the dropdown menu.');
  614. }
  615. if ($defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && ! $defaults['advanced_autocomplete']) {
  616. $form['country_from_' . $mapid] = $countries;
  617. $form['country_from_' . $mapid]['#weight'] = $from_country_weight;
  618. $from_desc = t('Enter the address, postcode and/or city from where you want to start your journey.');
  619. }
  620. $form['from_' . $mapid] = array(
  621. '#type' => 'textfield',
  622. '#title' => t('Starting from'),
  623. '#size' => $defaults['from_width'],
  624. '#required' => TRUE,
  625. '#description' => $from_desc,
  626. '#weight' => $from_weight,
  627. );
  628. }
  629. if ($fromto == 'to') {
  630. $form['to_' . $mapid] = array(
  631. '#type' => 'hidden',
  632. '#value' => $latlon,
  633. );
  634. if (empty($loc)) {
  635. if (empty($country)) {
  636. $mto = t('Destination');
  637. }
  638. else {
  639. $mto = drupal_strtoupper($country);
  640. }
  641. }
  642. else {
  643. $mto = $loc;
  644. $form['to_address_' . $mapid] = array(
  645. '#type' => 'hidden',
  646. '#value' => $loc,
  647. );
  648. }
  649. $form['mto'] = array(
  650. '#type' => 'item',
  651. '#title' => t('To'),
  652. '#markup' => $mto,
  653. );
  654. }
  655. else {
  656. $to_desc = t('Enter the address, postcode and/or city and country of your journey destination.');
  657. if ($defaults['use_advanced'] && $defaults['advanced_autocomplete']) {
  658. $to_desc = t('Start typing the address of your destination, then select from the dropdown menu.');
  659. }
  660. if ($defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && ! $defaults['advanced_autocomplete']) {
  661. $form['country_to_' . $mapid] = $countries;
  662. $form['country_to_' . $mapid]['#weight'] = $to_country_weight;
  663. $to_desc = t('Enter the address, postcode and/or city of your journey destination.');
  664. }
  665. $form['to_' . $mapid] = array(
  666. '#type' => 'textfield',
  667. '#title' => t('Destination'),
  668. '#size' => $defaults['to_width'],
  669. '#required' => TRUE,
  670. '#description' => $to_desc,
  671. '#weight' => $to_weight,
  672. );
  673. }
  674. $wt = 6;
  675. if ($defaults['travelmode_show']) {
  676. $form['travelmode_' . $mapid] = array(
  677. '#type' => 'select',
  678. '#title' => t('Travel mode'),
  679. '#options' => array(
  680. 'driving' => t('Driving'),
  681. 'walking' => t('Walking'),
  682. 'bicycling' => t('Bicycling'),
  683. 'transit' => t('Public transport'),
  684. ),
  685. '#default_value' => 'driving',
  686. '#weight' => $wt,
  687. );
  688. $wt = $wt + 2;
  689. if (module_exists('date_popup')) {
  690. $form['transit_date_select_' . $mapid] = array(
  691. '#type' => 'select',
  692. '#title' => t('Date select'),
  693. '#options' => array(
  694. 'depart' => t('Departure time'),
  695. 'arrive' => t('Arrival time'),
  696. ),
  697. '#default_value' => 'depart',
  698. '#prefix' => '<div id="getdirections_transit_dates_wrapper_' . $mapid . '">',
  699. '#weight' => $wt,
  700. );
  701. $wt = $wt + 2;
  702. if ($defaults['transit_date_format'] == 'int') {
  703. $fmt = 'j/n/Y H:i';
  704. }
  705. else {
  706. $fmt = 'n/j/Y H:i';
  707. }
  708. $form['transit_dates_' . $mapid] = array(
  709. '#type' => 'date_popup',
  710. '#default_value' => '',
  711. '#date_year_range' => '-0:+1',
  712. '#date_format' => $fmt,
  713. '#mindate' => "+0",
  714. '#suffix' => '</div>',
  715. '#weight' => $wt,
  716. );
  717. $wt = $wt + 2;
  718. }
  719. }
  720. if ($defaults['travelextras_show']) {
  721. $form['travelextras_' . $mapid] = array(
  722. '#type' => 'checkboxes',
  723. '#title' => t('Travel options'),
  724. '#options' => array(
  725. 'avoidhighways' => t('Avoid Highways'),
  726. 'avoidtolls' => t('Avoid Tolls'),
  727. 'altroute' => t('Alternative routes'),
  728. ),
  729. '#weight' => $wt,
  730. );
  731. $wt = $wt + 2;
  732. }
  733. if ($defaults['use_advanced'] && $defaults['advanced_autocomplete'] && $defaults['waypoints'] > 0 && $defaults['advanced_autocomplete_via'] && ! $defaults['advanced_alternate']) {
  734. for ($ct = 1; $ct <= $defaults['waypoints']; $ct++) {
  735. $form['via_autocomplete_' . $mapid . '_' . $ct] = array(
  736. '#type' => 'textfield',
  737. '#title' => t('Via !c', array('!c' => $ct)),
  738. '#size' => $defaults['advanced_autocomplete_via_width'],
  739. '#weight' => $wt,
  740. );
  741. $wt = $wt + 2;
  742. }
  743. }
  744. if ($misc['switchfromto'] && ! $fromto && ! $defaults['use_advanced']) {
  745. $form['switchfromto_' . $mapid] = array(
  746. '#type' => 'markup',
  747. '#markup' => '<input type="button" id="getdirections_togglefromto_' . $mapid . '" class="switchfromto" name="op" value="' . t('Switch From/To') . '">',
  748. '#weight' => $wt,
  749. );
  750. $wt = $wt + 2;
  751. }
  752. // mapid for use in theme
  753. $form['mapid'] = array('#type' => 'value', '#value' => $mapid);
  754. if ($defaults['use_advanced'] && ! $defaults['advanced_autocomplete']) {
  755. $form['next_' . $mapid] = array(
  756. '#type' => 'button',
  757. '#value' => t('Next'),
  758. '#attributes' => array('onclick' => 'Drupal.getdirections.nextbtn(); return false;'),
  759. '#weight' => $wt,
  760. );
  761. $wt = $wt + 2;
  762. }
  763. $form['submit_' . $mapid] = array(
  764. '#type' => 'button',
  765. '#value' => t('Get Directions'),
  766. '#weight' => $wt,
  767. );
  768. return $form;
  769. }
  770. /**
  771. * Some defaults.
  772. */
  773. function getdirections_defaults() {
  774. global $is_https;
  775. $defaults = array(
  776. 'width' => '300px',
  777. 'height' => '200px',
  778. 'latlong' => '40,0',
  779. 'zoom' => 3,
  780. 'controltype' => 'small',
  781. 'pancontrol' => 1,
  782. 'mtc' => 'standard',
  783. 'maptype' => 'Map',
  784. 'baselayers' => array(
  785. 'Map' => 1,
  786. 'Satellite' => 1,
  787. 'Hybrid' => 1,
  788. 'Physical' => 1,
  789. 'OpenStreetMap' => 0,
  790. ),
  791. 'unitsystem' => 'metric',
  792. 'scale' => 0,
  793. 'overview' => 0,
  794. 'overview_opened' => 0,
  795. 'scrollwheel' => 0,
  796. 'draggable' => 1,
  797. 'streetview_show' => 0,
  798. 'travelmode_show' => 0,
  799. 'transit_dates' => 0,
  800. 'transit_date_format' => 'int',
  801. 'travelextras_show' => 0,
  802. 'map_backgroundcolor' => '',
  803. 'from_width' => 20,
  804. 'to_width' => 20,
  805. 'use_country_dropdown' => 1,
  806. 'use_advanced' => 0,
  807. 'waypoints' => 0,
  808. 'waypoints_optimise' => 0,
  809. 'waypoint_color' => 'white',
  810. 'advanced_autocomplete' => 0,
  811. 'advanced_autocomplete_bias' => 0,
  812. 'advanced_autocomplete_via' => 0,
  813. 'advanced_autocomplete_via_width' => 20,
  814. 'advanced_alternate' => 0,
  815. 'use_https' => ($is_https ? 1 : 0),
  816. 'nokeyboard' => 0,
  817. 'nodoubleclickzoom' => 0,
  818. 'region_bias' => variable_get('site_default_country', ''),
  819. );
  820. $getdirections_defaults = variable_get('getdirections_default', array());
  821. // remove old stuff
  822. if (isset($getdirections_defaults['behavior'])) {
  823. if (isset($getdirections_defaults['behavior']['scale'])) {
  824. $getdirections_defaults['scale'] = $getdirections_defaults['behavior']['scale'];
  825. }
  826. if (isset($getdirections_defaults['behavior']['scrollwheel'])) {
  827. $getdirections_defaults['scrollwheel'] = $getdirections_defaults['behavior']['scrollwheel'];
  828. }
  829. if (isset($getdirections_defaults['behavior']['draggable'])) {
  830. $getdirections_defaults['draggable'] = $getdirections_defaults['behavior']['draggable'];
  831. }
  832. if (isset($getdirections_defaults['behavior']['overview'])) {
  833. $getdirections_defaults['overview'] = $getdirections_defaults['behavior']['overview'];
  834. }
  835. if (isset($getdirections_defaults['behavior']['overview_opened'])) {
  836. $getdirections_defaults['overview_opened'] = $getdirections_defaults['behavior']['overview_opened'];
  837. }
  838. unset($getdirections_defaults['behavior']);
  839. }
  840. $newdefaults = getdirections_adjust_vars($defaults, $getdirections_defaults);
  841. return $newdefaults;
  842. }
  843. /**
  844. *
  845. *
  846. */
  847. function getdirections_returnlink_defaults() {
  848. $defaults = array(
  849. 'node_enable' => 0,
  850. 'node_link' => t('Return to page'),
  851. 'user_enable' => 0,
  852. 'user_link' => t('Return to page'),
  853. 'taxonomy_term_enable' => 0,
  854. 'taxonomy_term_link' => t('Return to page'),
  855. 'comment_enable' => 0,
  856. 'comment_link' => t('Return to page'),
  857. );
  858. $getdirections_returnlink_defaults = variable_get('getdirections_returnlink', array());
  859. $newdefaults = getdirections_adjust_vars($defaults, $getdirections_returnlink_defaults);
  860. return $newdefaults;
  861. }
  862. /**
  863. *
  864. *
  865. */
  866. function getdirections_colorbox_defaults() {
  867. $defaults = array(
  868. 'enable' => 0,
  869. 'width' => 600,
  870. 'height' => 600,
  871. );
  872. $getdirections_colorbox_defaults = variable_get('getdirections_colorbox', array());
  873. $newdefaults = getdirections_adjust_vars($defaults, $getdirections_colorbox_defaults);
  874. return $newdefaults;
  875. }
  876. /**
  877. *
  878. *
  879. */
  880. function getdirections_misc_defaults() {
  881. $defaults = array(
  882. 'keep_title' => 0,
  883. 'show_distance' => 0,
  884. 'trafficinfo' => 0,
  885. 'trafficinfo_state' => 0,
  886. 'bicycleinfo' => 0,
  887. 'bicycleinfo_state' => 0,
  888. 'switchfromto' => 0,
  889. 'show_duration' => 0,
  890. 'panoramio_use' => 0,
  891. 'panoramio_show' => 0,
  892. 'panoramio_state' => 0,
  893. 'transitinfo' => 0,
  894. 'transitinfo_state' => 0,
  895. 'geolocation_enable' => 0,
  896. 'geolocation_option' => 1,
  897. 'geolocation_mobile_check' => 1,
  898. 'weather_use' => 0,
  899. 'weather_show' => 0,
  900. 'weather_state' => 0,
  901. 'weather_temp' => 1,
  902. 'weather_speed' => 1,
  903. 'weather_label' => 0,
  904. 'weather_cloud' => 1,
  905. 'weather_cloud_state' => 0,
  906. 'weather_clickable' => 1,
  907. 'weather_info' => 1,
  908. );
  909. $getdirections_misc_defaults = variable_get('getdirections_misc', array());
  910. $newdefaults = getdirections_adjust_vars($defaults, $getdirections_misc_defaults);
  911. return $newdefaults;
  912. }
  913. /**
  914. * Function to setup the map
  915. *
  916. * @param string $entity_type
  917. * Required. The Entity type, eg node, user etc
  918. * @param string $direction
  919. * Required. The direction the supplied input applies to
  920. * @param int $entity_id
  921. * Required. The entity identifier.
  922. * @return
  923. * Returns the themed map
  924. */
  925. function getdirections_entity_setlocation($entity_type, $direction, $entity_id, $width='', $height='') {
  926. if (is_numeric($entity_id) && $entity_id && getdirections_check_entity_type($entity_type)) {
  927. $location = getdirections_load_locations($entity_id, $entity_type);
  928. if (count($location)) {
  929. $country = (isset($location[0]['country']) ? $location[0]['country'] : '');
  930. $latlon = $location[0]['latitude'] . ',' . $location[0]['longitude'];
  931. // sanity check
  932. if (! getdirections_latlon_check($latlon)) {
  933. watchdog('getdirections', 'Lat, Lon failed for !e id !nid', array('!e' => $entity_type, '!nid' => $entity_id), WATCHDOG_WARNING);
  934. $latlon = getdirections_load_latlon_defaults();
  935. }
  936. // $locs only used for display now
  937. $locs = _getdirections_loadaddress($location[0]);
  938. $content = getdirections_direction($direction, $locs, $country, $latlon, $entity_id, $entity_type, $width, $height);
  939. return $content;
  940. }
  941. }
  942. return getdirections_direction();
  943. }
  944. // backwards compat
  945. function getdirections_setlocation($direction, $nid, $width='', $height='') {
  946. return getdirections_entity_setlocation('node', $direction, $nid, $width, $height);
  947. }
  948. /**
  949. * Function to setup the map
  950. *
  951. * @param string $from_entity_type
  952. * Required. The Entity type of the starting point, eg node, user etc
  953. * @param int $from_entity_id
  954. * Required. The identifier of the starting point.
  955. * @param string $from_entity_type
  956. * Required. The Entity type of the destination, eg node, user etc
  957. * @param int $from_entity_id
  958. * Required. The identifier of the destination.
  959. *
  960. * @return
  961. * Returns the themed map
  962. */
  963. function getdirections_entity_setlocations($from_entity_type, $from_entity_id, $to_entity_type, $to_entity_id, $width='', $height='') {
  964. if (is_numeric($from_entity_id) && $from_entity_id && is_numeric($to_entity_id) && $to_entity_id && getdirections_check_entity_type($from_entity_type) && getdirections_check_entity_type($to_entity_type)) {
  965. // from
  966. $from_location = getdirections_load_locations($from_entity_id, $from_entity_type);
  967. if (count($from_location)) {
  968. $from_latlon = $from_location[0]['latitude'] . ',' . $from_location[0]['longitude'];
  969. // sanity check
  970. if (! getdirections_latlon_check($from_latlon)) {
  971. watchdog('getdirections', 'Lat, Lon failed for !e id !nid', array('!e' => $from_entity_type, '!nid' => $from_entity_id), WATCHDOG_WARNING);
  972. $from_latlon = getdirections_load_latlon_defaults();
  973. }
  974. $from_locs = _getdirections_loadaddress($from_location[0]);
  975. // to
  976. $to_location = getdirections_load_locations($to_entity_id, $to_entity_type);
  977. if (count($to_location)) {
  978. $to_latlon = $to_location[0]['latitude'] . ',' . $to_location[0]['longitude'];
  979. // sanity check
  980. if (! getdirections_latlon_check($to_latlon)) {
  981. watchdog('getdirections', 'Lat, Lon failed for !e id !nid', array('!e' => $to_entity_type, '!nid' => $to_entity_id), WATCHDOG_WARNING);
  982. $to_latlon = getdirections_load_latlon_defaults();
  983. }
  984. $to_locs = _getdirections_loadaddress($to_location[0]);
  985. $content = getdirections_locations($from_locs, $from_latlon, $to_locs, $to_latlon, $width, $height);
  986. return $content;
  987. }
  988. }
  989. }
  990. return getdirections_direction();
  991. }
  992. /**
  993. * Function to setup the map to display waypoints
  994. *
  995. * @param string $entity_ids
  996. * Required. A comma delimited list of identifiers
  997. * @param string $from_entity_type
  998. * Required. The Entity type of the points, eg node, user etc
  999. * @return
  1000. * Returns the themed map
  1001. */
  1002. function getdirections_entity_setlocations_via($entity_ids, $entity_type, $width='', $height='') {
  1003. // $entity_ids is a comma delimeted list
  1004. $arr_entity_ids = explode(',', $entity_ids);
  1005. foreach ($arr_entity_ids AS $key => $entity_id) {
  1006. if ($key > GETDIRECTIONS_WAYPOINTS_MAX && $key < count($arr_entity_ids)) {
  1007. continue;
  1008. }
  1009. if (! is_numeric($entity_id) || ! $entity_id) {
  1010. continue;
  1011. }
  1012. $locations = getdirections_load_locations($entity_id, $entity_type);
  1013. if (! count($locations)) {
  1014. continue;
  1015. }
  1016. $locs[] = _getdirections_loadaddress($locations[0]);
  1017. $latlon = $locations[0]['latitude'] . ',' . $locations[0]['longitude'];
  1018. // sanity check
  1019. if (! getdirections_latlon_check($latlon)) {
  1020. watchdog('getdirections', 'Lat, Lon failed for user id !nid', array('!nid' => $entity_id), WATCHDOG_WARNING);
  1021. continue;
  1022. }
  1023. $latlons[] = $latlon;
  1024. }
  1025. $content = getdirections_locations_via($locs, $latlons, $width, $height);
  1026. return $content;
  1027. }
  1028. /**
  1029. * Function to setup the map and form
  1030. *
  1031. * @param string $direction
  1032. * Required. The direction the supplied input applies to
  1033. * @param int $uid
  1034. * Required. The uid of the location owner
  1035. * @return
  1036. * Returns the themed map and form
  1037. */
  1038. function getdirections_user_setlocation($direction, $uid, $width='', $height='') {
  1039. $content = getdirections_entity_setlocation('user', $direction, $uid, $width, $height);
  1040. return $content;
  1041. }
  1042. /**
  1043. * Function to setup the map
  1044. *
  1045. * @param int $fromuid
  1046. * Required. The uid of the starting point
  1047. * @param int $touid
  1048. * Required. The uid of the destination
  1049. * @return
  1050. * Returns the themed map
  1051. */
  1052. function getdirections_user_setlocations($fromuid, $touid, $width='', $height='') {
  1053. $content = getdirections_entity_setlocations('user', $fromuid, 'user', $touid, $width, $height);
  1054. return $content;
  1055. }
  1056. /**
  1057. * Function to setup the map and form
  1058. *
  1059. * @param string $direction
  1060. * Required. The direction the supplied input applies to
  1061. * @param int $nid
  1062. * Required. The nid of the location node
  1063. * @return
  1064. * Returns the themed map and form
  1065. */
  1066. function getdirections_node_setlocation($direction, $nid, $width='', $height='') {
  1067. $content = getdirections_entity_setlocation('node', $direction, $nid, $width, $height);
  1068. return $content;
  1069. }
  1070. /**
  1071. * Function to setup the map
  1072. *
  1073. * @param int $fromnid
  1074. * Required. The nid of the starting point
  1075. * @param int $tonid
  1076. * Required. The nid of the destination
  1077. * @return
  1078. * Returns the themed map
  1079. */
  1080. function getdirections_node_setlocations($fromnid, $tonid, $width='', $height='') {
  1081. $content = getdirections_entity_setlocations('node', $fromnid, 'node', $tonid, $width, $height);
  1082. return $content;
  1083. }
  1084. /**
  1085. * Function to setup the map
  1086. *
  1087. * @param int $nid
  1088. * Required. The nid of the starting point
  1089. * @param int $uid
  1090. * Required. The uid of the destination
  1091. * @return
  1092. * Returns the themed map
  1093. */
  1094. function getdirections_n2u_setlocation($nid, $uid, $width='', $height='') {
  1095. $content = getdirections_entity_setlocations('node', $nid, 'user', $uid, $width, $height);
  1096. return $content;
  1097. }
  1098. /**
  1099. * Function to setup the map and form
  1100. *
  1101. * @param int $uid
  1102. * Required. The uid of the starting point
  1103. * @param int $nid
  1104. * Required. The nid of the destination
  1105. * @return
  1106. * Returns the themed map
  1107. */
  1108. function getdirections_u2n_setlocation($uid, $nid, $width='', $height='') {
  1109. $content = getdirections_entity_setlocations('user', $uid, 'node', $nid, $width, $height);
  1110. return $content;
  1111. }
  1112. /**
  1113. * Function to setup the map to display waypoints
  1114. *
  1115. * @param $uids
  1116. * Required. A comma delimited list of uids
  1117. * @return
  1118. * Returns the themed map
  1119. */
  1120. function getdirections_user_setlocations_via($uids, $width='', $height='') {
  1121. $content = getdirections_entity_setlocations_via($uids, 'user', $width, $height);
  1122. return $content;
  1123. }
  1124. /**
  1125. * Function to setup the map to display waypoints
  1126. *
  1127. * @param string $nids
  1128. * Required. A comma delimited list of nids
  1129. * @return
  1130. * Returns the themed map
  1131. */
  1132. function getdirections_node_setlocations_via($nids, $width='', $height='') {
  1133. $content = getdirections_entity_setlocations_via($nids, 'node', $width, $height);
  1134. return $content;
  1135. }
  1136. /**
  1137. * Function to setup the map and form
  1138. *
  1139. * @param string $direction
  1140. * Required. The direction the supplied input applies to
  1141. * @param int $tid
  1142. * Required. The tid of the location enabled taxonomy term
  1143. * @return
  1144. * Returns the themed map and form
  1145. */
  1146. function getdirections_term_setlocation($direction, $tid, $width='', $height='') {
  1147. $content = getdirections_entity_setlocation('taxonomy_term', $direction, $tid, $width, $height);
  1148. return $content;
  1149. }
  1150. /**
  1151. * Function to setup the map and form
  1152. *
  1153. * @param string $direction
  1154. * Required. The direction the supplied input applies to
  1155. * @param int $cid
  1156. * Required. The cid of the location enabled comment
  1157. * @return
  1158. * Returns the themed map and form
  1159. */
  1160. function getdirections_comment_setlocation($direction, $cid, $width='', $height='') {
  1161. $content = getdirections_entity_setlocation('comment', $direction, $cid, $width, $height);
  1162. return $content;
  1163. }
  1164. /**
  1165. * Function to setup the map
  1166. *
  1167. * @param string $lls
  1168. * Required. A pipe delimited string of latitude,longitude pairs.
  1169. * @return
  1170. * Returns the themed map
  1171. */
  1172. function getdirections_latlons($lls, $width='', $height='') {
  1173. $latlons = array();
  1174. $locs = array();
  1175. $arrlls = explode('|', $lls);
  1176. foreach ($arrlls AS $key => $ll) {
  1177. if ($key > GETDIRECTIONS_WAYPOINTS_MAX && $key < count($arrlls)) {
  1178. continue;
  1179. }
  1180. if (! getdirections_latlon_check($ll)) {
  1181. watchdog('getdirections', 'Lat, Lon failed for !ll', array('!ll' => $ll), WATCHDOG_WARNING);
  1182. continue;
  1183. }
  1184. $latlons[] = $ll;
  1185. }
  1186. $content = getdirections_locations_via($locs, $latlons, $width, $height);
  1187. return $content;
  1188. }
  1189. /**
  1190. * Function to setup the map and form
  1191. *
  1192. * @param string $direction
  1193. * Required. The direction the supplied input applies to
  1194. * @param string $latlon
  1195. * Required. A latitude,longitude pair
  1196. * @param string $locs
  1197. * Optional. a description of the target.
  1198. * @return
  1199. * Returns the themed map and form
  1200. */
  1201. function getdirections_latlon($direction, $latlon, $locs='', $width='', $height='') {
  1202. $country = '';
  1203. $id = 0;
  1204. $type = 'other';
  1205. if (! getdirections_latlon_check($latlon)) {
  1206. watchdog('getdirections', 'Lat, Lon failed for user id !uid', array('!uid' => $uid), WATCHDOG_WARNING);
  1207. $latlon = getdirections_load_latlon_defaults();
  1208. }
  1209. $content = getdirections_direction_other($direction, $locs, $country, $latlon, $id, $type, $width, $height);
  1210. return $content;
  1211. }
  1212. /**
  1213. * Function to setup the map and form
  1214. *
  1215. * @param string $direction
  1216. * Required. The direction the supplied input applies to
  1217. * @param int $lid
  1218. * Required. The lid of the location
  1219. * @return
  1220. * Returns the themed map and form
  1221. */
  1222. function getdirections_setlocation_id($direction, $lid, $width='', $height='') {
  1223. if (is_numeric($lid) && $lid) {
  1224. $location = getdirections_load_location($lid);
  1225. if (is_array($location) && count($location)) {
  1226. $country = (isset($location['country']) ? $location['country'] : '');
  1227. $latlon = $location['latitude'] . ',' . $location['longitude'];
  1228. // sanity check
  1229. if (! getdirections_latlon_check($latlon)) {
  1230. watchdog('getdirections', 'Lat, Lon failed for location id !lid', array('!lid' => $lid), WATCHDOG_WARNING);
  1231. $latlon = getdirections_load_latlon_defaults();
  1232. }
  1233. // $locs only used for display now
  1234. $locs = _getdirections_loadaddress($location);
  1235. $content = getdirections_direction_other($direction, $locs, $country, $latlon, $lid, 'location', $width, $height);
  1236. return $content;
  1237. }
  1238. }
  1239. return getdirections_direction();
  1240. }
  1241. /**
  1242. * Function to setup the map scripts
  1243. *
  1244. * @param $defaults
  1245. * Required. the current settings.
  1246. * Sets up the call to googlemaps, css and the relevant getdirections js in html head
  1247. */
  1248. function getdirections_setup_map($defaults, $misc_defaults) {
  1249. global $language, $is_https;
  1250. $getdirections_paths = getdirections_paths_get();
  1251. // v3 googlemaps API
  1252. $key = variable_get('getdirections_api3_key', '');
  1253. $query = array();
  1254. if (! empty($key)) {
  1255. $query['key'] = $key;
  1256. }
  1257. $query['sensor'] = 'false';
  1258. $query['language'] = $language->language;
  1259. if ($defaults['region_bias']) {
  1260. $query['region'] = $defaults['region_bias'];
  1261. }
  1262. $libraries = array();
  1263. if ($defaults['advanced_autocomplete']) {
  1264. $libraries['places'] = 'places';
  1265. }
  1266. if ($misc_defaults['panoramio_use']) {
  1267. $libraries['panoramio'] = 'panoramio';
  1268. }
  1269. if ($misc_defaults['weather_use']) {
  1270. $libraries['weather'] = 'weather';
  1271. }
  1272. // more libraries here
  1273. // compat with getlocations
  1274. if (module_exists('getlocations')) {
  1275. $getlocations_defaults = getlocations_defaults();
  1276. if (function_exists('getlocations_places_check')) {
  1277. if (getlocations_places_check()) {
  1278. $libraries['places'] = 'places';
  1279. }
  1280. }
  1281. elseif ($getlocations_defaults['places']) {
  1282. $libraries['places'] = 'places';
  1283. }
  1284. if ($getlocations_defaults['panoramio_use']) {
  1285. $libraries['panoramio'] = 'panoramio';
  1286. }
  1287. if ($getlocations_defaults['weather_use']) {
  1288. $libraries['weather'] = 'weather';
  1289. }
  1290. }
  1291. // load libraries if any
  1292. if (count($libraries)) {
  1293. $query['libraries'] = implode(',', $libraries);
  1294. }
  1295. $scheme = ($is_https ? 'https' : 'http');
  1296. $gmapdomain = "maps.googleapis.com/maps/api/js";
  1297. $gmaplink = url($scheme . '://' . $gmapdomain, array('query' => $query));
  1298. if (isset($defaults['preview_map'])) {
  1299. $js = $getdirections_paths['getdirections_preview_path'];
  1300. }
  1301. else {
  1302. if ($defaults['use_advanced']) {
  1303. if ($defaults['advanced_alternate']) {
  1304. $js = $getdirections_paths['getdirections_v3b_path'];
  1305. }
  1306. else {
  1307. $js = $getdirections_paths['getdirections_v3a_path'];
  1308. }
  1309. }
  1310. else {
  1311. $js = $getdirections_paths['getdirections_v3_path'];
  1312. }
  1313. }
  1314. drupal_add_js($gmaplink, 'external');
  1315. drupal_add_css(GETDIRECTIONS_PATH . '/getdirections.css');
  1316. drupal_add_js($js);
  1317. }
  1318. /**
  1319. * Implements hook_views_api().
  1320. */
  1321. function getdirections_views_api() {
  1322. return array('api' => 3);
  1323. }
  1324. /**
  1325. * Function to collect an address
  1326. *
  1327. * @param array $location
  1328. * @param bool $addcountry
  1329. *
  1330. * @return
  1331. * Returns array.
  1332. */
  1333. function _getdirections_loadaddress($location, $addcountry = TRUE) {
  1334. // theme it so others can change it
  1335. return theme('getdirections_loadaddress', array('location' => $location, 'addcountry' => $addcountry));
  1336. }
  1337. /**
  1338. * Function to collect an address from addressfield
  1339. *
  1340. * @param array $address
  1341. * @param bool $addcountry
  1342. *
  1343. * @return
  1344. * Returns array.
  1345. */
  1346. function _getdirections_addressfield_loadaddress($address, $addcountry = TRUE) {
  1347. // theme it so others can change it
  1348. return theme('getdirections_addressfield_loadaddress', array('address' => $address, 'addcountry' => $addcountry));
  1349. }
  1350. /**
  1351. * Function to check the user status and existence
  1352. *
  1353. * @param int $uid
  1354. *
  1355. * @return
  1356. * Returns status.
  1357. */
  1358. function getdirections_user_check($uid) {
  1359. $query = db_select('users', 'u')->fields('u', array('status'))->condition('u.uid', $uid);
  1360. $row = $query->execute()->fetchAssoc();
  1361. return (isset($row['status']) && $row['status'] ? TRUE : FALSE);
  1362. }
  1363. /**
  1364. * Function to get the vid from node table.
  1365. *
  1366. * @param int $nid
  1367. *
  1368. * @return
  1369. * Returns vid.
  1370. */
  1371. // NOT IN USE
  1372. function getdirections_get_vid($nid) {
  1373. if (is_numeric($nid) && $nid ) {
  1374. $query = db_select('node', 'n')->fields('n', array('vid'))->condition('n.nid', $nid);
  1375. $row = $query->execute()->fetchAssoc();
  1376. return (isset($row['vid']) && $row['vid'] ? $row['vid'] : FALSE);
  1377. }
  1378. return FALSE;
  1379. }
  1380. /**
  1381. * Function to get the nid from node table.
  1382. *
  1383. * @param int $vid
  1384. *
  1385. * @return
  1386. * Returns nid.
  1387. */
  1388. // NOT IN USE
  1389. function getdirections_get_nid($vid) {
  1390. if (is_numeric($vid) && $vid ) {
  1391. $query = db_select('node', 'n')->fields('n', array('nid'))->condition('n.vid', $vid);
  1392. $row = $query->execute()->fetchAssoc();
  1393. return (isset($row['nid']) && $row['nid'] ? $row['nid'] : FALSE);
  1394. }
  1395. return FALSE;
  1396. }
  1397. /**
  1398. * Function to get the node identifier if available
  1399. *
  1400. * @param int $lid
  1401. *
  1402. * @return
  1403. * Returns nid.
  1404. */
  1405. // NOT IN USE
  1406. function getdirections_get_nid_from_lid($lid) {
  1407. if ($lid) {
  1408. $query = FALSE;
  1409. if (module_exists('getlocations_fields')) {
  1410. $nid = getlocations_get_nid_from_lid($lid);
  1411. if ($nid) {
  1412. return $nid;
  1413. }
  1414. }
  1415. elseif (module_exists('location')) {
  1416. $query = db_select('location_instance', 'i')->fields('i', array('nid'))->condition('i.lid', $lid);
  1417. }
  1418. if ($query) {
  1419. $row = $query->execute()->fetchAssoc();
  1420. return (isset($row['nid']) && $row['nid'] ? $row['nid'] : FALSE);
  1421. }
  1422. }
  1423. return FALSE;
  1424. }
  1425. /**
  1426. * Function to get the term identifier if available
  1427. *
  1428. * @param int $lid
  1429. *
  1430. * @return
  1431. * Returns tid.
  1432. */
  1433. // NOT IN USE
  1434. function getdirections_get_tid_from_lid($lid) {
  1435. $tid = FALSE;
  1436. if (module_exists('getlocations_fields')) {
  1437. $tid = getlocations_get_tid_from_lid($lid);
  1438. }
  1439. if ($tid) {
  1440. return $tid;
  1441. }
  1442. return FALSE;
  1443. }
  1444. /**
  1445. * Function to get the location name if available
  1446. *
  1447. * @param int $lid
  1448. *
  1449. * @return
  1450. * Returns name.
  1451. */
  1452. function getdirections_get_lid_title($lid) {
  1453. if ($lid) {
  1454. $query = FALSE;
  1455. if (module_exists('getlocations_fields')) {
  1456. $query = db_select('getlocations_fields', 'i')->fields('i', array('name'))->condition('i.glid', $lid);
  1457. }
  1458. elseif (module_exists('location')) {
  1459. $query = db_select('location', 'i')->fields('i', array('name'))->condition('i.lid', $lid);
  1460. }
  1461. if ($query) {
  1462. $row = $query->execute()->fetchAssoc();
  1463. return (isset($row['name']) && $row['name'] ? $row['name'] : FALSE);
  1464. }
  1465. }
  1466. return FALSE;
  1467. }
  1468. /**
  1469. *
  1470. *
  1471. */
  1472. function getdirections_load_latlon_defaults() {
  1473. $getdirections_defaults = getdirections_defaults();
  1474. return $getdirections_defaults['latlong'];
  1475. }
  1476. /**
  1477. * Check if the config has been run
  1478. *
  1479. */
  1480. function getdirections_check() {
  1481. $check = variable_get('getdirections_default', 'xxx');
  1482. if ($check == 'xxx') {
  1483. return FALSE;
  1484. }
  1485. return TRUE;
  1486. }
  1487. /**
  1488. * Function to check a lat,lon string
  1489. *
  1490. * @param string $latlon
  1491. *
  1492. * @return
  1493. * Returns true or false
  1494. */
  1495. function getdirections_latlon_check($latlon) {
  1496. if (! empty($latlon) && preg_match("/[0-9.\-],[0-9.\-]/", $latlon)) {
  1497. $ll = explode(',', $latlon);
  1498. if (isset($ll[0]) && is_numeric($ll[0]) && $ll[0] <> 0 && isset($ll[1]) && is_numeric($ll[1]) && $ll[1] <> 0) {
  1499. return $latlon;
  1500. }
  1501. }
  1502. return FALSE;
  1503. }
  1504. /**
  1505. * for colorbox and suchlike
  1506. *
  1507. */
  1508. function getdirections_direction_box() {
  1509. $a1 = FALSE;
  1510. $a2 = FALSE;
  1511. $a3 = FALSE;
  1512. $a4 = FALSE;
  1513. if (arg(1)) {
  1514. $a1 = arg(1);
  1515. }
  1516. if (arg(2)) {
  1517. $a2 = arg(2);
  1518. }
  1519. if (arg(3)) {
  1520. $a3 = arg(3);
  1521. }
  1522. if (arg(4)) {
  1523. $a4 = arg(4);
  1524. }
  1525. if ($a1 == 'location' && ($a2 == 'from' || $a2 == 'to') && is_numeric($a3) ) {
  1526. $content = getdirections_node_setlocation($a2, $a3);
  1527. }
  1528. elseif ($a1 == 'locations' && is_numeric($a2) && is_numeric($a3)) {
  1529. $content = getdirections_node_setlocations($a2, $a3);
  1530. }
  1531. elseif ($a1 == 'locations_via' && $a2) {
  1532. $content = getdirections_node_setlocations_via($a2);
  1533. }
  1534. elseif ($a1 == 'locations_user_via' && $a2) {
  1535. $content = getdirections_user_setlocations_via($a2);
  1536. }
  1537. elseif ($a1 == 'location_user' && ($a2 == 'from' || $a2 == 'to') && is_numeric($a3)) {
  1538. $content = getdirections_user_setlocation($a2, $a3);
  1539. }
  1540. elseif ($a1 == 'locations_users' && is_numeric($a2) && is_numeric($a3)) {
  1541. $content = getdirections_user_setlocations($a2, $a3);
  1542. }
  1543. elseif ($a1 == 'location_n2u' && is_numeric($a2) && is_numeric($a3)) {
  1544. $content = getdirections_n2u_setlocation($a2, $a3);
  1545. }
  1546. elseif ($a1 == 'location_u2n' && is_numeric($a2) && is_numeric($a3)) {
  1547. $content = getdirections_u2n_setlocation($a2, $a3);
  1548. }
  1549. elseif ($a1 == 'latlon' && ($a2 == 'from' || $a2 == 'to')) {
  1550. $content = getdirections_latlon($a2, $a3, $a4);
  1551. }
  1552. elseif ($a1 == 'latlons' && $a2) {
  1553. $content = getdirections_latlons($a2);
  1554. }
  1555. elseif ($a1 == 'location_id' && ($a2 == 'from' || $a2 == 'to')) {
  1556. $content = getdirections_setlocation_id($a2, $a3);
  1557. }
  1558. elseif ($a1 == 'location_term' && ($a2 == 'from' || $a2 == 'to')) {
  1559. $content = getdirections_term_setlocation($a2, $a3);
  1560. }
  1561. elseif ($a1 == 'location_comment' && ($a2 == 'from' || $a2 == 'to')) {
  1562. $content = getdirections_comment_setlocation($a2, $a3);
  1563. }
  1564. elseif ( getdirections_check_entity_type($a1) && ($a2 == 'from' || $a2 == 'to') && is_numeric($a3) ) {
  1565. $content = getdirections_entity_setlocation($a1, $a2, $a3);
  1566. }
  1567. elseif (getdirections_check_entity_type($a1) && is_numeric($a2) && getdirections_check_entity_type($a3) && is_numeric($a4)) {
  1568. $content = getdirections_entity_setlocations($a1, $a2, $a3, $a4);
  1569. }
  1570. else {
  1571. $content = getdirections_direction();
  1572. }
  1573. $output = theme('getdirections_box', array('content' => $content));
  1574. print $output;
  1575. exit;
  1576. }
  1577. /**
  1578. * Load one or more locations
  1579. *
  1580. * @param int $entity_id
  1581. * @param string $entity_type
  1582. *
  1583. * @return array
  1584. *
  1585. */
  1586. function getdirections_load_locations($entity_id, $entity_type) {
  1587. $locations = '';
  1588. $module = getdirections_get_current_supported_module();
  1589. if ($module == 'getlocations_fields') {
  1590. $entity_get_info = entity_get_info($entity_type);
  1591. $entity_key = $entity_get_info['entity keys']['id']; // nid, cid, uid etc
  1592. $locations = getlocations_fields_load_locations($entity_id, $entity_key);
  1593. }
  1594. elseif ($module == 'location_node' || $module == 'location_cck' ) {
  1595. $entity_get_info = entity_get_info($entity_type);
  1596. $entity_key = $entity_get_info['entity keys']['id']; // nid, cid, uid etc
  1597. $locations = location_load_locations($entity_id, $entity_key);
  1598. }
  1599. elseif ($module == 'geofield') {
  1600. $locations = getdirections_other_load_locations($entity_id, $entity_type, 'geofield');
  1601. }
  1602. elseif ($module == 'geolocation') {
  1603. $locations = getdirections_other_load_locations($entity_id, $entity_type, 'geolocation');
  1604. }
  1605. return $locations;
  1606. }
  1607. /**
  1608. * Load a location
  1609. *
  1610. * @param int $lid
  1611. *
  1612. * @return array
  1613. *
  1614. */
  1615. function getdirections_load_location($lid) {
  1616. $location = '';
  1617. if (module_exists('getlocations_fields')) {
  1618. $location = getlocations_fields_load_location($lid);
  1619. }
  1620. elseif (module_exists('location')) {
  1621. $location = location_load_location($lid);
  1622. }
  1623. return $location;
  1624. }
  1625. /**
  1626. * Load one or more locations
  1627. * For Geofield and Geolocation modules
  1628. *
  1629. * @param int $entity_id
  1630. * @param string $entity_type
  1631. *
  1632. * @return array
  1633. *
  1634. */
  1635. function getdirections_other_load_locations($entity_id, $entity_type, $module = '') {
  1636. global $language;
  1637. $locations = array();
  1638. if (empty($module)) {
  1639. return $locations;
  1640. }
  1641. $entity_get_info = entity_get_info($entity_type);
  1642. $load_hook = $entity_get_info['load hook'];
  1643. $obj = $load_hook($entity_id);
  1644. $entity_title = '';
  1645. if (isset($entity_get_info['entity keys']['label'])) {
  1646. $entity_title = $entity_get_info['entity keys']['label'];
  1647. }
  1648. elseif ($entity_type == 'user') {
  1649. $entity_title = 'name';
  1650. }
  1651. $entity_key = $entity_get_info['entity keys']['id']; // nid, cid, uid etc
  1652. $location_name = '';
  1653. if (isset($obj->{$entity_title})) {
  1654. $location_name = $obj->{$entity_title};
  1655. }
  1656. // get the field_xxx names
  1657. $objfields = array();
  1658. foreach ($obj AS $k => $therest) {
  1659. if (preg_match("/^field_/", $k)) {
  1660. $objfields[] = $k;
  1661. }
  1662. }
  1663. if (empty($objfields)) {
  1664. return $locations;
  1665. }
  1666. // find a geofield
  1667. if ($module == 'geofield') {
  1668. $type = 'geofield';
  1669. $geofields = getdirections_get_fieldname($type, $module, $entity_type);
  1670. if (! empty($geofields)) {
  1671. $geofield = '';
  1672. foreach ($objfields AS $field) {
  1673. if (in_array($field, $geofields)) {
  1674. $geofield = $field;
  1675. }
  1676. }
  1677. if ( empty($geofield)) {
  1678. return $locations;
  1679. }
  1680. // got one
  1681. $geo = $obj->{$geofield};
  1682. $geo_keys = array_keys($geo);
  1683. foreach ($geo_keys AS $lang) {
  1684. if ($lang == $language->language || (isset($obj->language) && $lang == $obj->language) || $lang == 'und') {
  1685. $ct = 0;
  1686. foreach ($geo[$lang] AS $g) {
  1687. $locations[$ct]['latitude'] = $g['lat'];
  1688. $locations[$ct]['longitude'] = $g['lon'];
  1689. $locations[$ct]['entity_key'] = $entity_key;
  1690. $locations[$ct]['entity_id'] = $entity_id;
  1691. $locations[$ct]['entity_type'] = $entity_type;
  1692. $locations[$ct]['name'] = $location_name;
  1693. $ct++;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. elseif ($module == 'geolocation') {
  1700. $type = 'geolocation_latlng';
  1701. $geolocationfields = getdirections_get_fieldname($type, $module, $entity_type);
  1702. if (! empty($geolocationfields)) {
  1703. $geolocationfield = '';
  1704. foreach ($objfields AS $field) {
  1705. // test for geolocationfields
  1706. if (in_array($field, $geolocationfields)) {
  1707. $geolocationfield = $field;
  1708. }
  1709. }
  1710. if (empty($geolocationfield)) {
  1711. return $locations;
  1712. }
  1713. // got one
  1714. $geo = $obj->{$geolocationfield};
  1715. $geo_keys = array_keys($geo);
  1716. foreach ($geo_keys AS $lang) {
  1717. if ($lang == $language->language || (isset($obj->language) && $lang == $obj->language) || $lang == 'und') {
  1718. $ct = 0;
  1719. foreach ($geo[$lang] AS $g) {
  1720. $locations[$ct]['latitude'] = $g['lat'];
  1721. $locations[$ct]['longitude'] = $g['lng'];
  1722. $locations[$ct]['entity_key'] = $entity_key;
  1723. $locations[$ct]['entity_id'] = $entity_id;
  1724. $locations[$ct]['entity_type'] = $entity_type;
  1725. $locations[$ct]['name'] = $location_name;
  1726. $ct++;
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. // sanity check
  1733. if (empty($locations)) {
  1734. return $locations;
  1735. }
  1736. // addressfield
  1737. if (module_exists('addressfield')) {
  1738. // find an addressfield
  1739. $type = 'addressfield';
  1740. $addressfields = getdirections_get_fieldname($type, 'addressfield', $entity_type);
  1741. if (! empty($addressfields)) {
  1742. $addressfield = '';
  1743. foreach ($objfields AS $field) {
  1744. if (in_array($field, $addressfields)) {
  1745. $addressfield = $field;
  1746. }
  1747. }
  1748. if (empty($addressfield)) {
  1749. return $locations;
  1750. }
  1751. // got one
  1752. $addr = $obj->{$addressfield};
  1753. $addr_keys = array_keys($addr);
  1754. foreach ($addr_keys AS $lang) {
  1755. if ($lang == $language->language || (isset($obj->language) && $lang == $obj->language) || $lang == 'und') {
  1756. $ct = 0;
  1757. foreach ($addr[$lang] AS $a) {
  1758. if (isset($locations[$ct])) {
  1759. $locations[$ct] += getdirections_addressfield_convert($a);
  1760. }
  1761. $ct++;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. return $locations;
  1768. }
  1769. /**
  1770. * Get field names
  1771. *
  1772. * @param string $type
  1773. * @param string $module
  1774. * @param string $entity_type
  1775. *
  1776. * @return array field names
  1777. *
  1778. */
  1779. function getdirections_get_fieldname($type, $module, $entity_type = '') {
  1780. $query = db_select('field_config', 'fc');
  1781. $query->fields('fc', array('field_name'));
  1782. $query->join('field_config_instance', 'i', 'fc.id = i.field_id');
  1783. $query->condition('fc.module', $module);
  1784. $query->condition('fc.type', $type);
  1785. $query->condition('fc.active', 1);
  1786. $query->condition('fc.storage_active', 1);
  1787. if (! empty($entity_type)) {
  1788. $query->condition('i.entity_type', $entity_type);
  1789. }
  1790. $rows = $query->execute();
  1791. $field_names = array();
  1792. foreach ($rows AS $row) {
  1793. $field_names[] = $row->field_name;
  1794. }
  1795. return $field_names;
  1796. }
  1797. /**
  1798. * Get the javascript paths
  1799. *
  1800. * @return array paths
  1801. *
  1802. */
  1803. function getdirections_paths_get($reset = FALSE) {
  1804. $defaults = array(
  1805. 'getdirections_v3_path' => GETDIRECTIONS_PATH . '/js/getdirections_v3.js',
  1806. 'getdirections_v3a_path' => GETDIRECTIONS_PATH . '/js/getdirections_v3a.js',
  1807. 'getdirections_v3b_path' => GETDIRECTIONS_PATH . '/js/getdirections_v3b.js',
  1808. 'getdirections_preview_path' => GETDIRECTIONS_PATH . '/js/getdirections_preview.js',
  1809. );
  1810. if ($reset) {
  1811. return $defaults;
  1812. }
  1813. $getdirections_paths = variable_get('getdirections_paths', $defaults);
  1814. $newdefaults = getdirections_adjust_vars($defaults, $getdirections_paths);
  1815. return $newdefaults;
  1816. }
  1817. /**
  1818. * Fetch a timestamp
  1819. *
  1820. * @return array json
  1821. *
  1822. */
  1823. function getdirections_get_datestamp() {
  1824. $d = $_GET['d'];
  1825. $t = $_GET['t'];
  1826. $date = $d . ' ' . $t;
  1827. $time = strtotime($date);
  1828. drupal_json_output(array('content' => ($time * 1000)));
  1829. }
  1830. /**
  1831. *
  1832. *
  1833. */
  1834. function getdirections_is_mobile() {
  1835. $getdirections_misc_defaults = getdirections_misc_defaults();
  1836. if (! $getdirections_misc_defaults['geolocation_mobile_check']) {
  1837. return TRUE;
  1838. }
  1839. $getdirections_ua = getdirections_ua_get();
  1840. $str = "/" . $getdirections_ua['ua_string'] . "/i";
  1841. $is_mobile = FALSE;
  1842. $ua = $_SERVER['HTTP_USER_AGENT'];
  1843. if (preg_match($str, $ua)) {
  1844. $is_mobile = TRUE;
  1845. }
  1846. return $is_mobile;
  1847. }
  1848. /**
  1849. * @return
  1850. * Returns a string of mobile compatible user agents
  1851. */
  1852. function getdirections_ua_get() {
  1853. $default = array('ua_string' => "iphone|ipad|android|blackberry|blazer|bolt|symbian|mobile safari|fennec|gobrowser|iemobile|maemo browser|profile midp|minimo|kindle|opera mini|opera mobi|skyfire|teashark|uzardweb");
  1854. $getdirections_ua = variable_get('getdirections_ua', $default);
  1855. return $getdirections_ua;
  1856. }
  1857. /**
  1858. * @return
  1859. * Returns location array
  1860. *
  1861. */
  1862. function getdirections_smart_ip() {
  1863. if (module_exists('smart_ip')) {
  1864. global $user;
  1865. $location = FALSE;
  1866. if ($user->uid > 0 && isset($user->data['geoip_location'])) {
  1867. $location = $user->data['geoip_location'];
  1868. }
  1869. elseif (isset($_SESSION['smart_ip']['location'])) {
  1870. $location = $_SESSION['smart_ip']['location'];
  1871. }
  1872. drupal_json_output($location);
  1873. }
  1874. exit;
  1875. }
  1876. /**
  1877. * @return
  1878. * Returns location array
  1879. *
  1880. */
  1881. function getdirections_ip_geoloc() {
  1882. if (module_exists('ip_geoloc')) {
  1883. $location = FALSE;
  1884. if (isset($_SESSION['ip_geoloc']['location'])) {
  1885. $location = $_SESSION['ip_geoloc']['location'];
  1886. }
  1887. drupal_json_output($location);
  1888. }
  1889. exit;
  1890. }
  1891. /**
  1892. * @return
  1893. * Returns an array of supported modules
  1894. */
  1895. function getdirections_supported_modules() {
  1896. return array(
  1897. 'getlocations_fields',
  1898. 'geofield',
  1899. 'geolocation',
  1900. 'location_node',
  1901. 'location_cck',
  1902. );
  1903. }
  1904. /**
  1905. *
  1906. *
  1907. */
  1908. function getdirections_get_current_supported_module() {
  1909. $modules = getdirections_supported_modules();
  1910. foreach ($modules AS $module) {
  1911. if (module_exists($module)) {
  1912. return $module;
  1913. }
  1914. }
  1915. return FALSE;
  1916. }
  1917. /**
  1918. * Recursively merge the defaults with the current settings
  1919. *
  1920. * @param array $defaults
  1921. *
  1922. * @param array $settings
  1923. *
  1924. * @return array The merged settings
  1925. *
  1926. */
  1927. function getdirections_adjust_vars($defaults, $settings) {
  1928. $newdefaults = array();
  1929. foreach ($defaults AS $k => $v) {
  1930. if (isset($settings[$k])) {
  1931. if (is_array($v)) {
  1932. $newdefaults[$k] = getdirections_adjust_vars($v, $settings[$k]);
  1933. }
  1934. else {
  1935. $newdefaults[$k] = $settings[$k];
  1936. }
  1937. }
  1938. else {
  1939. $newdefaults[$k] = $v;
  1940. }
  1941. }
  1942. return $newdefaults;
  1943. }
  1944. /**
  1945. * Default settings form
  1946. * @return array form
  1947. *
  1948. */
  1949. function getdirections_default_settings($defaults, $parent = 'getdirections_default') {
  1950. $form = array();
  1951. $form['width'] = array(
  1952. '#type' => 'textfield',
  1953. '#title' => t('Default width'),
  1954. '#default_value' => $defaults['width'],
  1955. '#size' => 25,
  1956. '#maxlength' => 25,
  1957. '#description' => t('The default width of a Google map, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
  1958. '#required' => TRUE,
  1959. );
  1960. $form['height'] = array(
  1961. '#type' => 'textfield',
  1962. '#title' => t('Default height'),
  1963. '#default_value' => $defaults['height'],
  1964. '#size' => 25,
  1965. '#maxlength' => 25,
  1966. '#description' => t('The default height of a Google map, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
  1967. '#required' => TRUE,
  1968. );
  1969. $form['latlong'] = array(
  1970. '#type' => 'textfield',
  1971. '#title' => t('Map center'),
  1972. '#default_value' => $defaults['latlong'],
  1973. '#size' => 50,
  1974. '#maxlength' => 255,
  1975. '#description' => t('The default center coordinates of Google map, expressed as a decimal latitude and longitude, separated by a comma.'),
  1976. '#required' => TRUE,
  1977. );
  1978. $form['zoom'] = array(
  1979. '#type' => 'select',
  1980. '#title' => t('Zoom'),
  1981. '#default_value' => $defaults['zoom'],
  1982. '#options' => drupal_map_assoc(range(0, 17)),
  1983. '#description' => t('The default zoom level of a Google map.'),
  1984. );
  1985. // v3
  1986. $opts = array(
  1987. 'none' => t('None'),
  1988. 'default' => t('Default'),
  1989. 'small' => t('Small'),
  1990. 'large' => t('Large'),
  1991. );
  1992. $form['controltype'] = array(
  1993. '#type' => 'select',
  1994. '#title' => t('Zoom Control type'),
  1995. '#options' => $opts,
  1996. '#default_value' => $defaults['controltype'],
  1997. );
  1998. $form['pancontrol'] = array(
  1999. '#type' => 'checkbox',
  2000. '#title' => t('Show Pan control'),
  2001. '#default_value' => $defaults['pancontrol'],
  2002. '#return_value' => 1,
  2003. );
  2004. $opts2 = array(
  2005. 'none' => t('None'),
  2006. 'standard' => t('Horizontal bar'),
  2007. 'menu' => t('Dropdown'),
  2008. );
  2009. $form['mtc'] = array(
  2010. '#type' => 'select',
  2011. '#title' => t('Map Control Type'),
  2012. '#options' => $opts2,
  2013. '#default_value' => $defaults['mtc'],
  2014. );
  2015. $options = array();
  2016. $layers = array(
  2017. 'Map' => t('Standard street map'),
  2018. 'Satellite' => t('Standard satellite map'),
  2019. 'Hybrid' => t('Hybrid satellite map'),
  2020. 'Physical' => t('Terrain map'),
  2021. 'OpenStreetMap' => t('OpenStreet map'),
  2022. );
  2023. foreach ($layers AS $key => $layer) {
  2024. if ($defaults['baselayers'][$key]) {
  2025. $options[$key] = $layer;
  2026. }
  2027. }
  2028. $form['maptype'] = array(
  2029. '#type' => 'select',
  2030. '#title' => t('Default map type'),
  2031. '#default_value' => $defaults['maptype'],
  2032. '#options' => $options,
  2033. );
  2034. $form['baselayers'] = array(
  2035. '#type' => 'fieldset',
  2036. '#title' => t('Enable map types'),
  2037. '#description' => t('Select which maps you want to be available.'),
  2038. '#collapsible' => TRUE,
  2039. '#collapsed' => FALSE,
  2040. );
  2041. $form['baselayers']['Map'] = array(
  2042. '#type' => 'checkbox',
  2043. '#title' => t('Standard street map'),
  2044. '#description' => t('The standard default street map.'),
  2045. '#default_value' => $defaults['baselayers']['Map'],
  2046. '#return_value' => 1,
  2047. );
  2048. $form['baselayers']['Satellite'] = array(
  2049. '#type' => 'checkbox',
  2050. '#title' => t('Standard satellite map'),
  2051. '#description' => t('Satellite view without street overlay.'),
  2052. '#default_value' => $defaults['baselayers']['Satellite'],
  2053. '#return_value' => 1,
  2054. );
  2055. $form['baselayers']['Hybrid'] = array(
  2056. '#type' => 'checkbox',
  2057. '#title' => t('Hybrid satellite map'),
  2058. '#description' => t('Satellite view with street overlay.'),
  2059. '#default_value' => $defaults['baselayers']['Hybrid'],
  2060. '#return_value' => 1,
  2061. );
  2062. $form['baselayers']['Physical'] = array(
  2063. '#type' => 'checkbox',
  2064. '#title' => t('Terrain map'),
  2065. '#description' => t('Map with physical data (terrain, vegetation.)'),
  2066. '#default_value' => $defaults['baselayers']['Physical'],
  2067. '#return_value' => 1,
  2068. );
  2069. $form['baselayers']['OpenStreetMap'] = array(
  2070. '#type' => 'checkbox',
  2071. '#title' => t('OpenStreet map'),
  2072. '#description' => t('Map from the OpenStreetMap Foundation.'),
  2073. '#default_value' => $defaults['baselayers']['OpenStreetMap'],
  2074. '#return_value' => 1,
  2075. );
  2076. $form['unitsystem'] = array(
  2077. '#type' => 'select',
  2078. '#title' => t('Default distance units'),
  2079. '#description' => t("Units to display distances in."),
  2080. '#default_value' => $defaults['unitsystem'],
  2081. '#options' => array(
  2082. 'metric' => t('Metric'),
  2083. 'imperial' => t('Imperial'),
  2084. ),
  2085. );
  2086. $form['scale'] = array(
  2087. '#type' => 'checkbox',
  2088. '#title' => t('Scale'),
  2089. '#description' => t('Show scale'),
  2090. '#default_value' => $defaults['scale'],
  2091. '#return_value' => 1,
  2092. );
  2093. $form['overview'] = array(
  2094. '#type' => 'checkbox',
  2095. '#title' => t('Overview map'),
  2096. '#description' => t('Show overview map'),
  2097. '#default_value' => $defaults['overview'],
  2098. '#return_value' => 1,
  2099. );
  2100. $form['overview_opened'] = array(
  2101. '#type' => 'checkbox',
  2102. '#title' => t('Overview map state'),
  2103. '#description' => t('Show overview map as open by default'),
  2104. '#default_value' => $defaults['overview_opened'],
  2105. '#return_value' => 1,
  2106. );
  2107. $form['scrollwheel'] = array(
  2108. '#type' => 'checkbox',
  2109. '#title' => t('Scrollwheel'),
  2110. '#description' => t('Enable scrollwheel zooming'),
  2111. '#default_value' => $defaults['scrollwheel'],
  2112. '#return_value' => 1,
  2113. );
  2114. $form['draggable'] = array(
  2115. '#type' => 'checkbox',
  2116. '#title' => t('Draggable'),
  2117. '#description' => t('Enable dragging on the map'),
  2118. '#default_value' => $defaults['draggable'],
  2119. '#return_value' => 1,
  2120. );
  2121. $form['nokeyboard'] = array(
  2122. '#type' => 'checkbox',
  2123. '#title' => t('Disable keyboard shortcuts'),
  2124. '#description' => t('Enabling this will disable keyboard shortcuts on the map.'),
  2125. '#default_value' => $defaults['nokeyboard'],
  2126. '#return_value' => 1,
  2127. );
  2128. $form['nodoubleclickzoom'] = array(
  2129. '#type' => 'checkbox',
  2130. '#title' => t('Disable Doubleclick zoom'),
  2131. '#description' => t('Enabling this will disable doubleclick zooming on the map.'),
  2132. '#default_value' => $defaults['nodoubleclickzoom'],
  2133. '#return_value' => 1,
  2134. );
  2135. $form['streetview_show'] = array(
  2136. '#type' => 'checkbox',
  2137. '#title' => t('Show streetview button'),
  2138. '#default_value' => $defaults['streetview_show'],
  2139. '#return_value' => 1,
  2140. );
  2141. $form['travelmode_show'] = array(
  2142. '#type' => 'checkbox',
  2143. '#title' => t('Show travel mode'),
  2144. '#description' => t('Enable travel mode selector.'),
  2145. '#default_value' => $defaults['travelmode_show'],
  2146. '#return_value' => 1,
  2147. );
  2148. if (module_exists('date_popup')) {
  2149. $form['transit_dates'] = array(
  2150. '#type' => 'checkbox',
  2151. '#title' => t('Show Public transport Dates'),
  2152. '#description' => t('When "Public transport" has been selected as travel mode, allow user to enter a date and time.'),
  2153. '#default_value' => $defaults['transit_dates'],
  2154. '#return_value' => 1,
  2155. '#prefix' => '<div id="getdirections_transit_dates_wrapper">',
  2156. );
  2157. $form['transit_date_format'] = array(
  2158. '#type' => 'select',
  2159. '#title' => t('Date format'),
  2160. '#default_value' => $defaults['transit_date_format'],
  2161. '#options' => array(
  2162. 'int' => t('International Format'),
  2163. 'usa' => t('American Format')
  2164. ),
  2165. '#suffix' => '</div>'
  2166. );
  2167. }
  2168. else {
  2169. $form['transit_dates'] = array('#type' => 'value', '#value' => 0);
  2170. $form['transit_date_format'] = array('#type' => 'value', '#value' => 'int');
  2171. }
  2172. $form['travelextras_show'] = array(
  2173. '#type' => 'checkbox',
  2174. '#title' => t('Show travel extras'),
  2175. '#description' => t('Enable travel extras checkboxes.'),
  2176. '#default_value' => $defaults['travelextras_show'],
  2177. '#return_value' => 1,
  2178. );
  2179. $form['map_backgroundcolor'] = array(
  2180. '#type' => 'textfield',
  2181. '#title' => t('Map background color'),
  2182. '#default_value' => $defaults['map_backgroundcolor'],
  2183. '#description' => t('Can be a color name or HTML hex, eg #FF0000. Leave empty for the default color.'),
  2184. '#size' => 10,
  2185. );
  2186. $form['from_width'] = array(
  2187. '#type' => 'textfield',
  2188. '#title' => t('Width of From box'),
  2189. '#default_value' => $defaults['from_width'],
  2190. '#size' => 5,
  2191. '#description' => t("The width of the Get directions 'From' box."),
  2192. '#required' => TRUE,
  2193. // need this to get validation to work
  2194. #'#parents' => array($parent, 'from_width'),
  2195. );
  2196. if ($parent) {
  2197. $form['from_width']['#parents'] = array($parent, 'from_width');
  2198. }
  2199. $form['to_width'] = array(
  2200. '#type' => 'textfield',
  2201. '#title' => t('Width of To box'),
  2202. '#default_value' => $defaults['to_width'],
  2203. '#size' => 5,
  2204. '#description' => t("The width of the Get directions 'To' box."),
  2205. '#required' => TRUE,
  2206. // need this to get validation to work
  2207. #'#parents' => array($parent, 'to_width'),
  2208. );
  2209. if ($parent) {
  2210. $form['to_width']['#parents'] = array($parent, 'to_width');
  2211. }
  2212. if (module_exists('location') || module_exists('getlocations_fields')) {
  2213. $form['use_country_dropdown'] = array(
  2214. '#type' => 'checkbox',
  2215. '#title' => t('Use Country dropdown'),
  2216. '#description' => t('Use a dropdown list of countries on the form.'),
  2217. '#default_value' => $defaults['use_country_dropdown'],
  2218. '#return_value' => 1,
  2219. );
  2220. }
  2221. else {
  2222. $form['use_country_dropdown'] = array('#type' => 'value', '#value' => 0);
  2223. }
  2224. $form['use_advanced'] = array(
  2225. '#type' => 'checkbox',
  2226. '#title' => t('Use advanced features'),
  2227. '#description' => t('Advanced features include a clickable map, waypoints or draggable route.'),
  2228. '#default_value' => $defaults['use_advanced'],
  2229. '#return_value' => 1,
  2230. );
  2231. $waypoints_opts = range(0, GETDIRECTIONS_WAYPOINTS_MAX);
  2232. $waypoints_opts[0] = t('None');
  2233. $form['waypoints'] = array(
  2234. '#type' => 'select',
  2235. '#title' => t('Number of waypoints'),
  2236. '#description' => t('The number of waypoints to display on the map.'),
  2237. '#default_value' => $defaults['waypoints'],
  2238. '#options' => $waypoints_opts,
  2239. '#prefix' => '<div id="wrap-waypoints">',
  2240. );
  2241. $form['advanced_autocomplete_via'] = array(
  2242. '#type' => 'checkbox',
  2243. '#title' => t('Waypoints Autocomplete'),
  2244. '#description' => t('Provides Autocomplete box for waypoints. Requires "Use Google Autocomplete" to be enabled.'),
  2245. '#default_value' => $defaults['advanced_autocomplete_via'],
  2246. '#return_value' => 1,
  2247. );
  2248. $form['advanced_autocomplete_via_width'] = array(
  2249. '#type' => 'textfield',
  2250. '#title' => t('Width of Waypoints box'),
  2251. '#default_value' => $defaults['advanced_autocomplete_via_width'],
  2252. '#size' => 5,
  2253. '#description' => t("The width of the Waypoints Autocomplete box."),
  2254. '#required' => TRUE,
  2255. // need this to get validation to work
  2256. #'#parents' => array($parent, 'advanced_autocomplete_via_width'),
  2257. );
  2258. if ($parent) {
  2259. $form['advanced_autocomplete_via_width']['#parents'] = array($parent, 'advanced_autocomplete_via_width');
  2260. }
  2261. $form['waypoints_optimise'] = array(
  2262. '#type' => 'checkbox',
  2263. '#title' => t('Optimise Waypoints'),
  2264. '#description' => t("Re-orders the waypoints to minimize overall cost of the route."),
  2265. '#default_value' => $defaults['waypoints_optimise'],
  2266. '#return_value' => 1,
  2267. );
  2268. $form['waypoint_color'] = array(
  2269. '#type' => 'select',
  2270. '#title' => t('Color of waypoint markers'),
  2271. '#description' => t('The color of waypoint markers used on the map.'),
  2272. '#default_value' => $defaults['waypoint_color'],
  2273. '#options' => array(
  2274. 'black' => t('Black'),
  2275. 'blue' => t('Blue'),
  2276. 'brown' => t('Brown'),
  2277. 'gray' => t('Gray'),
  2278. 'green' => t('Green'),
  2279. 'orange' => t('Orange'),
  2280. 'purple' => t('Purple'),
  2281. 'red' => t('Red'),
  2282. 'white' => t('White'),
  2283. 'yellow' => t('Yellow'),
  2284. ),
  2285. );
  2286. $form['advanced_alternate'] = array(
  2287. '#type' => 'checkbox',
  2288. '#title' => t('Use draggable route'),
  2289. '#description' => t('An alternative to waypoints.'),
  2290. '#default_value' => $defaults['advanced_alternate'],
  2291. '#return_value' => 1,
  2292. );
  2293. $form['advanced_autocomplete'] = array(
  2294. '#type' => 'checkbox',
  2295. '#title' => t('Use Google Autocomplete'),
  2296. '#description' => t('An alternative method for collecting starting point and destination.'),
  2297. '#default_value' => $defaults['advanced_autocomplete'],
  2298. '#return_value' => 1,
  2299. );
  2300. $form['advanced_autocomplete_bias'] = array(
  2301. '#type' => 'checkbox',
  2302. '#title' => t('Enable Viewport bias'),
  2303. '#description' => t('Bias the Google Autocomplete results to the area on the map.'),
  2304. '#default_value' => $defaults['advanced_autocomplete_bias'],
  2305. '#return_value' => 1,
  2306. '#suffix' => '</div>',
  2307. );
  2308. $form['region_bias'] = array(
  2309. '#type' => 'select',
  2310. '#title' => t('Regional bias'),
  2311. '#description' => t('Bias the maps to a particular country'),
  2312. '#default_value' => $defaults['region_bias'],
  2313. '#options' => array('' => t('None')) + getdirections_get_countries_list(),
  2314. );
  2315. global $is_https;
  2316. $form['use_https'] = array(
  2317. '#type' => 'value',
  2318. '#value' => ($is_https ? 1 : 0) ,
  2319. );
  2320. return $form;
  2321. }
  2322. /**
  2323. * Configure returnlinks
  2324. *
  2325. */
  2326. function getdirections_returnlink_settings($defaults) {
  2327. $form = array();
  2328. $entity_types = getdirections_get_enabled_entity_types();
  2329. if (in_array('node', $entity_types)) {
  2330. $form['node_enable'] = array(
  2331. '#type' => 'checkbox',
  2332. '#title' => t('Enable Page Return Link'),
  2333. '#default_value' => $defaults['node_enable'],
  2334. '#return_value' => 1,
  2335. );
  2336. $form['node_link'] = array(
  2337. '#type' => 'textfield',
  2338. '#title' => t('Text of page return link'),
  2339. '#description' => t('Use %n to insert the page title'),
  2340. '#default_value' => $defaults['node_link'],
  2341. '#size' => 30,
  2342. // need this to get validation to work
  2343. '#parents' => array('getdirections_returnlink', 'node_link'),
  2344. '#prefix' => '<div id="wrap-node-link">',
  2345. '#suffix' => '</div>',
  2346. );
  2347. }
  2348. # else {
  2349. # $form['node_enable'] = array('#type' => 'value', '#value' => 0);
  2350. # $form['node_link'] = array('#type' => 'value', '#value' => $defaults['node_link']);
  2351. # }
  2352. if (in_array('user', $entity_types)) {
  2353. $form['user_enable'] = array(
  2354. '#type' => 'checkbox',
  2355. '#title' => t('Enable User Return Link'),
  2356. '#default_value' => $defaults['user_enable'],
  2357. '#return_value' => 1,
  2358. );
  2359. $form['user_link'] = array(
  2360. '#type' => 'textfield',
  2361. '#title' => t('Text of user return link'),
  2362. '#description' => t('Use %n to insert the user name'),
  2363. '#default_value' => $defaults['user_link'],
  2364. '#size' => 30,
  2365. // need this to get validation to work
  2366. '#parents' => array('getdirections_returnlink', 'user_link'),
  2367. '#prefix' => '<div id="wrap-user-link">',
  2368. '#suffix' => '</div>',
  2369. );
  2370. }
  2371. # else {
  2372. # $form['user_enable'] = array('#type' => 'value', '#value' => 0);
  2373. # $form['user_link'] = array('#type' => 'value', '#value' => $defaults['user_link']);
  2374. # }
  2375. if (in_array('taxonomy_term', $entity_types)) {
  2376. $form['taxonomy_term_enable'] = array(
  2377. '#type' => 'checkbox',
  2378. '#title' => t('Enable Term Return Link'),
  2379. '#default_value' => $defaults['taxonomy_term_enable'],
  2380. '#return_value' => 1,
  2381. );
  2382. $form['taxonomy_term_link'] = array(
  2383. '#type' => 'textfield',
  2384. '#title' => t('Text of Term return link'),
  2385. '#description' => t('Use %n to insert the term name'),
  2386. '#default_value' => $defaults['taxonomy_term_link'],
  2387. '#size' => 30,
  2388. // need this to get validation to work
  2389. '#parents' => array('getdirections_returnlink', 'taxonomy_term_link'),
  2390. '#prefix' => '<div id="wrap-term-link">',
  2391. '#suffix' => '</div>',
  2392. );
  2393. }
  2394. # else {
  2395. # $form['taxonomy_term_enable'] = array('#type' => 'value', '#value' => 0);
  2396. # $form['taxonomy_term_link'] = array('#type' => 'value', '#value' => $defaults['taxonomy_term_link']);
  2397. # }
  2398. if (in_array('comment', $entity_types)) {
  2399. $form['comment_enable'] = array(
  2400. '#type' => 'checkbox',
  2401. '#title' => t('Enable Comment Return Link'),
  2402. '#default_value' => $defaults['comment_enable'],
  2403. '#return_value' => 1,
  2404. );
  2405. $form['comment_link'] = array(
  2406. '#type' => 'textfield',
  2407. '#title' => t('Text of Comment return link'),
  2408. '#description' => t('Use %n to insert the comment subject'),
  2409. '#default_value' => $defaults['comment_link'],
  2410. '#size' => 30,
  2411. // need this to get validation to work
  2412. '#parents' => array('getdirections_returnlink', 'comment_link'),
  2413. '#prefix' => '<div id="wrap-comment-link">',
  2414. '#suffix' => '</div>',
  2415. );
  2416. }
  2417. # else {
  2418. # $form['comment_enable'] = array('#type' => 'value', '#value' => 0);
  2419. # $form['comment_link'] = array('#type' => 'value', '#value' => $defaults['comment_link']);
  2420. # }
  2421. return $form;
  2422. }
  2423. /**
  2424. * Colorbox settings form
  2425. *
  2426. */
  2427. function getdirections_colorbox_settings($defaults) {
  2428. $form = array();
  2429. $form['enable'] = array(
  2430. '#type' => 'checkbox',
  2431. '#title' => t('Enable Colorbox'),
  2432. '#default_value' => $defaults['enable'],
  2433. '#return_value' => 1,
  2434. '#description' => t('Show Getdirections in a Colorbox.'),
  2435. );
  2436. $form['width'] = array(
  2437. '#type' => 'textfield',
  2438. '#title' => t('Colorbox width'),
  2439. '#default_value' => $defaults['width'],
  2440. '#size' => 5,
  2441. '#required' => TRUE,
  2442. // need this to get validation to work
  2443. '#parents' => array('getdirections_colorbox', 'width'),
  2444. '#prefix' => '<div id="wrap-getdirections-colorbox">',
  2445. );
  2446. $form['height'] = array(
  2447. '#type' => 'textfield',
  2448. '#title' => t('Colorbox height'),
  2449. '#default_value' => $defaults['height'],
  2450. '#size' => 5,
  2451. '#required' => TRUE,
  2452. // need this to get validation to work
  2453. '#parents' => array('getdirections_colorbox', 'height'),
  2454. '#suffix' => '</div>',
  2455. );
  2456. return $form;
  2457. }
  2458. /**
  2459. * Miscellaneous settings form
  2460. *
  2461. */
  2462. function getdirections_misc_settings($defaults, $config = TRUE, $extras = TRUE) {
  2463. if ((module_exists('location') || module_exists('getlocations_fields')) && $config) {
  2464. $form['keep_title'] = array(
  2465. '#type' => 'checkbox',
  2466. '#title' => t('Show original title'),
  2467. '#description' => t("Show the node title or user name when using 'to' or 'from'."),
  2468. '#default_value' => $defaults['keep_title'],
  2469. '#return_value' => 1,
  2470. );
  2471. }
  2472. else {
  2473. $form['getdirections_misc']['keep_title'] = array('#type' => 'value', '#value' => 0);
  2474. }
  2475. $form['show_distance'] = array(
  2476. '#type' => 'checkbox',
  2477. '#title' => t('Show total distance'),
  2478. '#default_value' => $defaults['show_distance'],
  2479. '#return_value' => 1,
  2480. );
  2481. $form['show_duration'] = array(
  2482. '#type' => 'checkbox',
  2483. '#title' => t('Show total duration'),
  2484. '#default_value' => $defaults['show_duration'],
  2485. '#return_value' => 1,
  2486. );
  2487. $form['geolocation_enable'] = array(
  2488. '#type' => 'checkbox',
  2489. '#title' => t('Enable geolocation options'),
  2490. '#default_value' => $defaults['geolocation_enable'],
  2491. '#return_value' => 1,
  2492. '#description' => t('For use on mobile devices.'),
  2493. );
  2494. $form['geolocation_mobile_check'] = array(
  2495. '#type' => 'checkbox',
  2496. '#title' => t('Enable check for mobiles'),
  2497. '#default_value' => $defaults['geolocation_mobile_check'],
  2498. '#return_value' => 1,
  2499. '#description' => t('Enable geolocation for mobile devices only.'),
  2500. '#prefix' => '<div id="wrap-getdirections-geolocation-options">',
  2501. );
  2502. $geo_opts = array(1 => t('Browser based geocoding'));
  2503. if (module_exists('smart_ip')) {
  2504. $geo_opts[2] = t('Smart IP based geocoding');
  2505. }
  2506. if (module_exists('ip_geoloc')) {
  2507. $geo_opts[3] = t('IP Geolocation based geocoding');
  2508. }
  2509. $form['geolocation_option'] = array(
  2510. '#type' => 'radios',
  2511. '#title' => t('Geolocation option'),
  2512. '#default_value' => $defaults['geolocation_option'],
  2513. '#options' => $geo_opts,
  2514. '#suffix' => '</div>',
  2515. );
  2516. $form['trafficinfo'] = array(
  2517. '#type' => 'checkbox',
  2518. '#title' => t('Enable Traffic information'),
  2519. '#default_value' => $defaults['trafficinfo'],
  2520. '#description' => t('Google trafficinfo layer, limited availability.'),
  2521. '#return_value' => 1,
  2522. );
  2523. $form['trafficinfo']['#suffix'] = '<div id="wrap-getdirections-trafficinfo">';
  2524. $form['trafficinfo_state'] = array(
  2525. '#type' => 'checkbox',
  2526. '#title' => t('Activate Traffic information'),
  2527. '#default_value' => $defaults['trafficinfo_state'],
  2528. '#description' => t('Activate Traffic layer when map is first displayed'),
  2529. '#return_value' => 1,
  2530. );
  2531. $form['trafficinfo_state']['#suffix'] = '</div>';
  2532. $form['bicycleinfo'] = array(
  2533. '#type' => 'checkbox',
  2534. '#title' => t('Enable Bicycling information'),
  2535. '#default_value' => $defaults['bicycleinfo'],
  2536. '#description' => t('Google bicycling layer, limited availability.'),
  2537. '#return_value' => 1,
  2538. );
  2539. $form['bicycleinfo']['#suffix'] = '<div id="wrap-getdirections-bicycleinfo">';
  2540. $form['bicycleinfo_state'] = array(
  2541. '#type' => 'checkbox',
  2542. '#title' => t('Activate Bicycling information'),
  2543. '#default_value' => $defaults['bicycleinfo_state'],
  2544. '#description' => t('Activate Bicycling layer when map is first displayed'),
  2545. '#return_value' => 1,
  2546. );
  2547. $form['bicycleinfo_state']['#suffix'] = '</div>';
  2548. $form['transitinfo'] = array(
  2549. '#type' => 'checkbox',
  2550. '#title' => t('Enable Public transport information'),
  2551. '#default_value' => $defaults['transitinfo'],
  2552. '#description' => t('Google transit layer, limited availability.'),
  2553. '#return_value' => 1,
  2554. );
  2555. $form['transitinfo']['#suffix'] = '<div id="wrap-getdirections-transitinfo">';
  2556. $form['transitinfo_state'] = array(
  2557. '#type' => 'checkbox',
  2558. '#title' => t('Activate Transit information'),
  2559. '#default_value' => $defaults['transitinfo_state'],
  2560. '#description' => t('Activate Transit layer when map is first displayed'),
  2561. '#return_value' => 1,
  2562. );
  2563. $form['transitinfo_state']['#suffix'] = '</div>';
  2564. if ($config) {
  2565. $form['panoramio_use'] = array(
  2566. '#type' => 'checkbox',
  2567. '#title' => t('Load Panoramio Library'),
  2568. '#default_value' => $defaults['panoramio_use'],
  2569. '#description' => t('Provide Google panoramio library to all maps.'),
  2570. '#return_value' => 1,
  2571. );
  2572. $form['panoramio_use']['#suffix'] = '<div id="wrap-getdirections-panoramio-use">';
  2573. $form['panoramio_show'] = array(
  2574. '#type' => 'checkbox',
  2575. '#title' => t('Enable Panoramio'),
  2576. '#default_value' => $defaults['panoramio_show'],
  2577. '#description' => t('Google panoramio picture links.'),
  2578. '#return_value' => 1,
  2579. );
  2580. $form['panoramio_show']['#suffix'] = '<div id="wrap-getdirections-panoramio">';
  2581. $form['panoramio_state'] = array(
  2582. '#type' => 'checkbox',
  2583. '#title' => t('Activate Panoramio'),
  2584. '#default_value' => $defaults['panoramio_state'],
  2585. '#description' => t('Activate Panoramio layer when map is first displayed'),
  2586. '#return_value' => 1,
  2587. );
  2588. $form['panoramio_state']['#suffix'] = '</div></div>';
  2589. }
  2590. elseif ($defaults['panoramio_use']) {
  2591. $form['panoramio_show'] = array(
  2592. '#type' => 'checkbox',
  2593. '#title' => t('Enable Panoramio'),
  2594. '#default_value' => $defaults['panoramio_show'],
  2595. '#description' => t('Google panoramio picture links.'),
  2596. '#return_value' => 1,
  2597. );
  2598. $form['panoramio_show']['#suffix'] = '<div id="wrap-getdirections-panoramio">';
  2599. $form['panoramio_state'] = array(
  2600. '#type' => 'checkbox',
  2601. '#title' => t('Activate Panoramio'),
  2602. '#default_value' => $defaults['panoramio_state'],
  2603. '#description' => t('Activate Panoramio layer when map is first displayed'),
  2604. '#return_value' => 1,
  2605. );
  2606. $form['panoramio_state']['#suffix'] = '</div>';
  2607. }
  2608. if ($config) {
  2609. // weather
  2610. $form['weather_use'] = array(
  2611. '#type' => 'checkbox',
  2612. '#title' => t('Load Weather Library'),
  2613. '#default_value' => $defaults['weather_use'],
  2614. '#description' => t('Provide Google Weather library to all maps.'),
  2615. '#return_value' => 1,
  2616. );
  2617. $form['weather_use']['#suffix'] = '<div id="wrap-getdirections-weather-use">';
  2618. $form['weather_show'] = array(
  2619. '#type' => 'checkbox',
  2620. '#title' => t('Enable Weather information'),
  2621. '#default_value' => $defaults['weather_show'],
  2622. '#description' => t('Google Weather information.'),
  2623. '#return_value' => 1,
  2624. );
  2625. $form['weather_show']['#suffix'] = '<div id="wrap-getdirections-weather">';
  2626. $form['weather_state'] = array(
  2627. '#type' => 'checkbox',
  2628. '#title' => t('Activate Weather information'),
  2629. '#default_value' => $defaults['weather_state'],
  2630. '#description' => t('Activate Weather information when map is first displayed.'),
  2631. '#return_value' => 1,
  2632. );
  2633. $form['weather_temp'] = array(
  2634. '#type' => 'select',
  2635. '#title' => t('Temperature units'),
  2636. '#default_value' => $defaults['weather_temp'],
  2637. '#options' => array(1 => t('Celsius'), 2 => t('Fahrenheit')),
  2638. );
  2639. $form['weather_speed'] = array(
  2640. '#type' => 'select',
  2641. '#title' => t('Windspeed units'),
  2642. '#default_value' => $defaults['weather_speed'],
  2643. '#options' => array(1 => t('Kilometers per hour'), 2 => t('Meters per second'), 3 => t('Miles per hour')),
  2644. );
  2645. $form['weather_label'] = array(
  2646. '#type' => 'select',
  2647. '#title' => t('Label colour'),
  2648. '#default_value' => $defaults['weather_label'],
  2649. '#options' => array(0 => ('Auto'), 1 => t('Black'), 2 => t('White')),
  2650. );
  2651. $form['weather_clickable'] = array(
  2652. '#type' => 'checkbox',
  2653. '#title' => t('Enable clicking on maps'),
  2654. '#default_value' => $defaults['weather_clickable'],
  2655. '#return_value' => 1,
  2656. );
  2657. $form['weather_info'] = array(
  2658. '#type' => 'checkbox',
  2659. '#title' => t('Enable weather InfoWindows'),
  2660. '#default_value' => $defaults['weather_info'],
  2661. '#return_value' => 1,
  2662. );
  2663. $form['weather_info']['#suffix'] = '</div>';
  2664. $form['weather_cloud'] = array(
  2665. '#type' => 'checkbox',
  2666. '#title' => t('Enable Cloud Layer'),
  2667. '#default_value' => $defaults['weather_cloud'],
  2668. '#description' => t('Google Cloud information.'),
  2669. '#return_value' => 1,
  2670. );
  2671. $form['weather_cloud']['#suffix'] = '<div id="wrap-getdirections-weather-cloud">';
  2672. $form['weather_cloud_state'] = array(
  2673. '#type' => 'checkbox',
  2674. '#title' => t('Activate Cloud Layer'),
  2675. '#default_value' => $defaults['weather_cloud_state'],
  2676. '#description' => t('Activate Cloud layer when map is first displayed.'),
  2677. '#return_value' => 1,
  2678. );
  2679. $form['weather_cloud_state']['#suffix'] = '</div></div>';
  2680. }
  2681. elseif ($defaults['weather_use']) {
  2682. $form['weather_show'] = array(
  2683. '#type' => 'checkbox',
  2684. '#title' => t('Enable Weather information'),
  2685. '#default_value' => $defaults['weather_show'],
  2686. '#description' => t('Google Weather information.'),
  2687. '#return_value' => 1,
  2688. );
  2689. $form['weather_show']['#suffix'] = '<div id="wrap-getdirections-weather">';
  2690. $form['weather_state'] = array(
  2691. '#type' => 'checkbox',
  2692. '#title' => t('Activate Weather information'),
  2693. '#default_value' => $defaults['weather_state'],
  2694. '#description' => t('Activate Weather information when map is first displayed.'),
  2695. '#return_value' => 1,
  2696. );
  2697. $form['weather_state']['#suffix'] = '</div>';
  2698. $form['weather_cloud'] = array(
  2699. '#type' => 'checkbox',
  2700. '#title' => t('Enable Cloud Layer'),
  2701. '#default_value' => $defaults['weather_cloud'],
  2702. '#description' => t('Google Cloud information.'),
  2703. '#return_value' => 1,
  2704. );
  2705. $form['weather_cloud']['#suffix'] = '<div id="wrap-getdirections-weather-cloud">';
  2706. $form['weather_cloud_state'] = array(
  2707. '#type' => 'checkbox',
  2708. '#title' => t('Activate Cloud Layer'),
  2709. '#default_value' => $defaults['weather_cloud_state'],
  2710. '#description' => t('Activate Cloud layer when map is first displayed.'),
  2711. '#return_value' => 1,
  2712. );
  2713. $form['weather_cloud_state']['#suffix'] = '</div>';
  2714. }
  2715. if ($extras) {
  2716. if (! $defaults['use_advanced']) {
  2717. $form['switchfromto'] = array(
  2718. '#type' => 'checkbox',
  2719. '#title' => t('Enable From/To Switch'),
  2720. '#default_value' => $defaults['switchfromto'],
  2721. '#return_value' => 1,
  2722. );
  2723. }
  2724. else {
  2725. $form['switchfromto'] = array('#type' => 'value', '#value' => 0);
  2726. }
  2727. }
  2728. return $form;
  2729. }
  2730. /**
  2731. * Convert an addressfield
  2732. *
  2733. */
  2734. function getdirections_addressfield_convert($address) {
  2735. $location = theme('getdirections_addressfield_convert', array('address' => $address));
  2736. return $location;
  2737. }
  2738. /**
  2739. * Check that an entity type is location enabled.
  2740. *
  2741. */
  2742. function getdirections_check_entity_type($entity_type = '', $bundle = '') {
  2743. if ($entity_type == 'term') {
  2744. $entity_type = 'taxonomy_term';
  2745. }
  2746. $module = getdirections_get_current_supported_module();
  2747. if ($module) {
  2748. $query = db_select('field_config', 'f');
  2749. $query->fields('f', array('id'));
  2750. $query->join('field_config_instance', 'i', 'f.id=i.field_id');
  2751. $query->condition('f.module', $module);
  2752. if ($entity_type) {
  2753. $query->condition('i.entity_type', $entity_type);
  2754. }
  2755. if ($bundle) {
  2756. $query->condition('i.bundle', $bundle);
  2757. }
  2758. $query->condition('f.active', 1);
  2759. $number_of_rows = $query->countQuery()->execute()->fetchField();
  2760. if ($number_of_rows) {
  2761. return TRUE;
  2762. }
  2763. }
  2764. return FALSE;
  2765. }
  2766. /**
  2767. * Return fieldable entities
  2768. *
  2769. */
  2770. function getdirections_get_fieldable_entity_types() {
  2771. $entity_get_info = entity_get_info();
  2772. $fieldables = array();
  2773. foreach ($entity_get_info AS $entity_type => $info) {
  2774. if (isset($entity_get_info[$entity_type]['fieldable']) && $entity_get_info[$entity_type]['fieldable']) {
  2775. $fieldables[] = $entity_type;
  2776. }
  2777. }
  2778. return $fieldables;
  2779. }
  2780. /**
  2781. * Return fieldable entities
  2782. *
  2783. */
  2784. function getdirections_get_enabled_entity_types() {
  2785. $entity_types = array();
  2786. $fieldables = getdirections_get_fieldable_entity_types();
  2787. foreach ($fieldables AS $entity_type) {
  2788. if (getdirections_check_entity_type($entity_type)) {
  2789. $entity_types[] = $entity_type;
  2790. }
  2791. }
  2792. return $entity_types;
  2793. }
  2794. /**
  2795. * Provide an array of vocabularies.
  2796. *
  2797. */
  2798. function getdirections_get_vocabularies() {
  2799. if (module_exists('taxonomy')) {
  2800. $vocabularies = taxonomy_get_vocabularies();
  2801. $options = array();
  2802. if (count($vocabularies)) {
  2803. foreach ($vocabularies as $vid => $vocabulary) {
  2804. if (getdirections_check_vocabulary($vocabulary->machine_name)) {
  2805. $options[$vid] = $vocabulary->name;
  2806. }
  2807. }
  2808. return $options;
  2809. }
  2810. }
  2811. return FALSE;
  2812. }
  2813. /**
  2814. * Check that a taxonomy type is fieldable.
  2815. *
  2816. */
  2817. function getdirections_check_vocabulary($machine_name) {
  2818. if (module_exists('taxonomy')) {
  2819. return getdirections_check_entity_type('taxonomy_term', $machine_name);
  2820. }
  2821. return FALSE;
  2822. }
  2823. /**
  2824. * Fetch a list of the core Drupal list of countries.
  2825. * from location module
  2826. *
  2827. * @param bool $upper Default uppercase
  2828. *
  2829. * @return array The countries array
  2830. */
  2831. function getdirections_get_countries_list($upper = TRUE, $only_continents = '', $only_countries = '') {
  2832. if (module_exists('countries')) {
  2833. $filter = array('enabled' => COUNTRIES_ENABLED);
  2834. if ($only_countries) {
  2835. $only_countries = drupal_strtoupper($only_countries);
  2836. $oc = explode(',', $only_countries);
  2837. if (! empty($oc)) {
  2838. $filter['countries'] = $oc;
  2839. }
  2840. }
  2841. elseif (is_array($only_continents)) {
  2842. $oc = array();
  2843. foreach ($only_continents AS $v) {
  2844. $oc[] = $v;
  2845. }
  2846. if (! empty($oc)) {
  2847. $filter['continents'] = $oc;
  2848. }
  2849. }
  2850. $countries = countries_get_countries('name', $filter);
  2851. }
  2852. else {
  2853. include_once DRUPAL_ROOT . '/includes/locale.inc';
  2854. // Statically cache a version of the core Drupal list of countries
  2855. $countries = &drupal_static(__FUNCTION__);
  2856. if (! isset($countries) || empty($countries)) {
  2857. $countries = country_get_list();
  2858. }
  2859. }
  2860. if (! $upper) {
  2861. $countries = array_change_key_case($countries, CASE_LOWER);
  2862. }
  2863. return $countries;
  2864. }
  2865. /**
  2866. * Implements hook_theme().
  2867. *
  2868. * This lets us tell Drupal about our theme functions and their variables.
  2869. */
  2870. function getdirections_theme() {
  2871. return array(
  2872. 'getdirections_show' => array(
  2873. 'variables' => array(
  2874. 'form' => NULL,
  2875. 'mapid' => '',
  2876. 'width' => '',
  2877. 'height' => '',
  2878. 'entity_id' => 0,
  2879. 'entity_type' => '',
  2880. 'lid' => 0,
  2881. 'type' => '',
  2882. ),
  2883. ),
  2884. 'getdirections_show_locations' => array(
  2885. 'variables' => array(
  2886. 'mapid' => '',
  2887. 'width' => '',
  2888. 'height' => '',
  2889. 'fromlocs' => '',
  2890. 'tolocs' => '',
  2891. ),
  2892. ),
  2893. 'getdirections_show_locations_via' => array(
  2894. 'variables' => array(
  2895. 'mapid' => '',
  2896. 'width' => '',
  2897. 'height' => '',
  2898. 'locs' => NULL,
  2899. ),
  2900. ),
  2901. 'getdirections_direction_form' => array(
  2902. 'render element' => 'form',
  2903. ),
  2904. 'getdirections_box' => array(
  2905. 'variables' => array('content' => NULL),
  2906. 'template' => 'getdirections_box',
  2907. ),
  2908. 'getdirections_loadaddress' => array(
  2909. 'variables' => array(
  2910. 'location' => array(),
  2911. 'addcountry' => FALSE,
  2912. ),
  2913. ),
  2914. 'getdirections_addressfield_loadaddress' => array(
  2915. 'variables' => array(
  2916. 'address' => array(),
  2917. 'addcountry' => FALSE,
  2918. ),
  2919. ),
  2920. 'getdirections_addressfield_convert' => array(
  2921. 'variables' => array(
  2922. 'address' => array(),
  2923. ),
  2924. ),
  2925. 'getdirections_settings_form' => array(
  2926. 'render element' => 'form',
  2927. ),
  2928. );
  2929. }
  2930. /**
  2931. * Theme to use for when one or no locations are supplied.
  2932. *
  2933. */
  2934. function theme_getdirections_show($variables) {
  2935. $form = $variables['form'];
  2936. $width = $variables['width'];
  2937. $height = $variables['height'];
  2938. $entity_id = $variables['entity_id'];
  2939. $entity_type = $variables['entity_type'];
  2940. $mapid = $variables['mapid'];
  2941. $lid = $variables['lid'];
  2942. $type = $variables['type'];
  2943. $output = '';
  2944. $getdirections_returnlink_default = getdirections_returnlink_defaults();
  2945. $getdirections_returnlink = variable_get('getdirections_returnlink', $getdirections_returnlink_default);
  2946. if ($type !== 'location') {
  2947. // entity way
  2948. // permissions first
  2949. if ($entity_id) {
  2950. if (isset($getdirections_returnlink[$entity_type . '_enable']) && $getdirections_returnlink[$entity_type . '_enable'] ) {
  2951. $linktext = $getdirections_returnlink[$entity_type . '_link'];
  2952. $entity_get_info = entity_get_info($entity_type);
  2953. $load_hook = $entity_get_info['load hook'];
  2954. $obj = $load_hook($entity_id);
  2955. $uri_func = $entity_get_info['uri callback'];
  2956. $uri = $uri_func($obj);
  2957. $entity_title = '';
  2958. if (isset($entity_get_info['entity keys']['label'])) {
  2959. $entity_title = $entity_get_info['entity keys']['label'];
  2960. }
  2961. elseif ($entity_type == 'user') {
  2962. $entity_title = 'name';
  2963. }
  2964. if ($entity_title && isset($obj->{$entity_title})) {
  2965. $linktext = preg_replace("/%n/", $obj->{$entity_title}, $linktext);
  2966. $l = l($linktext, $uri['path']);
  2967. $output .= '<div class="getdirections_returnlink">' . $l . '</div>';
  2968. }
  2969. }
  2970. }
  2971. }
  2972. $output .= $form;
  2973. $getdirections_defaults = getdirections_defaults();
  2974. $getdirections_misc = getdirections_misc_defaults();
  2975. if ($getdirections_misc['show_distance']) {
  2976. $output .= '<div id="getdirections_show_distance_' . $mapid . '"></div>';
  2977. }
  2978. if ($getdirections_misc['show_duration']) {
  2979. $output .= '<div id="getdirections_show_duration_' . $mapid . '"></div>';
  2980. }
  2981. $help = '';
  2982. if ($getdirections_defaults['use_advanced']) {
  2983. if ($getdirections_defaults['waypoints'] > 0 && ! $getdirections_defaults['advanced_alternate'] ) {
  2984. $help = t('Drag <img src="http://labs.google.com/ridefinder/images/mm_20_!c.png"> to activate a waypoint', array('!c' => $getdirections_defaults['waypoint_color']));
  2985. if ($getdirections_defaults['advanced_autocomplete'] && $getdirections_defaults['advanced_autocomplete_via'] ) {
  2986. $help .= ' ' . t('or use the Autocomplete boxes');
  2987. }
  2988. }
  2989. elseif ($getdirections_defaults['advanced_alternate']) {
  2990. $help = t('You can drag the route to change it');
  2991. }
  2992. }
  2993. $output .= '<div id="getdirections_help_' . $mapid . '">' . $help . '</div>';
  2994. $header = array();
  2995. $rows[] = array(
  2996. array(
  2997. 'data' => '<div id="getdirections_map_canvas_' . $mapid . '" style="width: ' . $width . '; height: ' . $height . '" ></div>',
  2998. 'valign' => 'top',
  2999. 'align' => 'center',
  3000. 'class' => array('getdirections-map'),
  3001. ),
  3002. array(
  3003. 'data' => ($getdirections_defaults['use_advanced'] && $getdirections_defaults['advanced_alternate'] ? '<button id="getdirections-undo-' . $mapid . '">' . t('Undo') . '</button>' : '') . '<div id="getdirections_directions_' . $mapid . '"></div>',
  3004. 'valign' => 'top' ,
  3005. 'align' => 'left',
  3006. 'class' => array('getdirections-list'),
  3007. ),
  3008. );
  3009. $output .= '<div class="getdirections">' . theme('table', array('header' => $header, 'rows' => $rows)) . '</div>';
  3010. return $output;
  3011. }
  3012. /**
  3013. * Theme to use for when both locations are supplied.
  3014. *
  3015. */
  3016. function theme_getdirections_show_locations($variables) {
  3017. $width = $variables['width'];
  3018. $height = $variables['height'];
  3019. $fromlocs = $variables['fromlocs'];
  3020. $tolocs = $variables['tolocs'];
  3021. $mapid = $variables['mapid'];
  3022. $output = "";
  3023. $output .= "<div class='getdirections_display'><label>" . t('From') . ":</label> " . $fromlocs . "</div>";
  3024. $output .= "<div class='getdirections_display'><label>" . t('To') . ":</label> " . $tolocs . "</div>";
  3025. $getdirections_misc = getdirections_misc_defaults();
  3026. if ($getdirections_misc['show_distance']) {
  3027. $output .= '<div id="getdirections_show_distance_' . $mapid . '"></div>';
  3028. }
  3029. if ($getdirections_misc['show_duration']) {
  3030. $output .= '<div id="getdirections_show_duration_' . $mapid . '"></div>';
  3031. }
  3032. $header = array();
  3033. $rows[] = array(
  3034. array(
  3035. 'data' => '<div id="getdirections_map_canvas_' . $mapid . '" style="width: ' . $width . '; height: ' . $height . '" ></div>',
  3036. 'valign' => 'top',
  3037. 'align' => 'center',
  3038. 'class' => array('getdirections-map'),
  3039. ),
  3040. array(
  3041. 'data' => '<div id="getdirections_directions_' . $mapid . '"></div>',
  3042. 'valign' => 'top' ,
  3043. 'align' => 'left',
  3044. 'class' => array('getdirections-list'),
  3045. ),
  3046. );
  3047. $output .= '<div class="getdirections">' . theme('table', array('header' => $header, 'rows' => $rows)) . '</div>';
  3048. return $output;
  3049. }
  3050. /**
  3051. * Theme to use for when both locations are supplied with waypoints.
  3052. *
  3053. */
  3054. function theme_getdirections_show_locations_via($variables) {
  3055. $width = $variables['width'];
  3056. $height = $variables['height'];
  3057. $locs = $variables['locs'];
  3058. $mapid = $variables['mapid'];
  3059. $output = "";
  3060. foreach ($locs AS $key => $loc) {
  3061. if ($key == 0) {
  3062. $label = t('From');
  3063. }
  3064. elseif ($key == count($locs)-1) {
  3065. $label = t('To');
  3066. }
  3067. else {
  3068. $label = t('Via');
  3069. }
  3070. $output .= "<div class='getdirections_display'><label>" . $label . ":</label> " . $loc . "</div>";
  3071. }
  3072. $getdirections_misc = getdirections_misc_defaults();
  3073. if ($getdirections_misc['show_distance']) {
  3074. $output .= '<div id="getdirections_show_distance_' . $mapid . '"></div>';
  3075. }
  3076. if ($getdirections_misc['show_duration']) {
  3077. $output .= '<div id="getdirections_show_duration_' . $mapid . '"></div>';
  3078. }
  3079. $header = array();
  3080. $rows[] = array(
  3081. array(
  3082. 'data' => '<div id="getdirections_map_canvas_' . $mapid . '" style="width: ' . $width . '; height: ' . $height . '" ></div>',
  3083. 'valign' => 'top',
  3084. 'align' => 'center',
  3085. 'class' => array('getdirections-map'),
  3086. ),
  3087. array(
  3088. 'data' => '<div id="getdirections_directions_' . $mapid . '"></div>',
  3089. 'valign' => 'top' ,
  3090. 'align' => 'left',
  3091. 'class' => array('getdirections-list'),
  3092. ),
  3093. );
  3094. $output .= '<div class="getdirections">' . theme('table', array('header' => $header, 'rows' => $rows)) . '</div>';
  3095. return $output;
  3096. }
  3097. /**
  3098. * Themes the getdirections form.
  3099. *
  3100. */
  3101. function theme_getdirections_direction_form($variables) {
  3102. $form = $variables['form'];
  3103. $mapid = $form['mapid']['#value'];
  3104. unset($form['mapid']);
  3105. $getdirections_defaults = getdirections_defaults();
  3106. $getdirections_misc = getdirections_misc_defaults();
  3107. if (isset($form['settings']['#value'])) {
  3108. $settings = $form['settings']['#value'];
  3109. $getdirections_defaults = $settings['default'];
  3110. $getdirections_misc = $settings['misc'];
  3111. unset($form['settings']);
  3112. }
  3113. $output = '';
  3114. // if you want to do fancy things with the form, do it here ;-)
  3115. if (isset($form['mto'])) {
  3116. $form['mto']['#prefix'] = '<div class="container-inline getdirections_display">';
  3117. $form['mto']['#suffix'] = '</div>';
  3118. }
  3119. if (isset($form['mfrom'])) {
  3120. $form['mfrom']['#prefix'] = '<div class="container-inline getdirections_display">';
  3121. $form['mfrom']['#suffix'] = '</div>';
  3122. }
  3123. if (isset($form['travelmode_' . $mapid])) {
  3124. $form['travelmode_' . $mapid]['#prefix'] = '<div class="container-inline getdirections_display">';
  3125. $form['travelmode_' . $mapid]['#suffix'] = '</div>';
  3126. }
  3127. if (isset($form['travelextras_' . $mapid])) {
  3128. $form['travelextras_' . $mapid]['#prefix'] = '<div class="container-inline getdirections_display">';
  3129. $form['travelextras_' . $mapid]['#suffix'] = '</div>';
  3130. }
  3131. if (! $getdirections_defaults['advanced_autocomplete']) {
  3132. if ($getdirections_misc['geolocation_enable'] && getdirections_is_mobile()) {
  3133. if ($getdirections_misc['geolocation_option'] == 1) {
  3134. // html5 geolocation
  3135. $geolocation_button = '<input type="button" value="' . t('Find Location') . '" title="' . t('Get the latitude and longitude for your current position from the browser') . '" id="getdirections_geolocation_button_from_' . $mapid . '" class="form-submit" />';
  3136. $geolocation_button .= '<span id="getdirections_geolocation_status_from_' . $mapid . '" ></span>';
  3137. $form['from_' . $mapid]['#field_suffix'] = '&nbsp;&nbsp;&nbsp;' . $geolocation_button;
  3138. }
  3139. elseif ($getdirections_misc['geolocation_option'] == 2 && module_exists('smart_ip')) {
  3140. // smart ip
  3141. $geolocation_button = '<input type="button" value="' . t('Locate by Smart IP') . '" title="' . t('Get the latitude and longitude for your current position from Smart IP') . '" id="getdirections_geolocation_button_from_' . $mapid . '" class="form-submit" />';
  3142. $geolocation_button .= '<span id="getdirections_geolocation_status_from_' . $mapid . '" ></span>';
  3143. $form['from_' . $mapid]['#field_suffix'] = '&nbsp;&nbsp;&nbsp;' . $geolocation_button;
  3144. }
  3145. elseif ($getdirections_misc['geolocation_option'] == 3 && module_exists('ip_geoloc')) {
  3146. // ip_geoloc
  3147. $geolocation_button = '<input type="button" value="' . t('Locate by IP Geolocation') . '" title="' . t('Get the latitude and longitude for your current position from IP Geolocation') . '" id="getdirections_geolocation_button_from_' . $mapid . '" class="form-submit" />';
  3148. $geolocation_button .= '<span id="getdirections_geolocation_status_from_' . $mapid . '" ></span>';
  3149. $form['from_' . $mapid]['#field_suffix'] = '&nbsp;&nbsp;&nbsp;' . $geolocation_button;
  3150. }
  3151. }
  3152. }
  3153. if ($getdirections_defaults['use_advanced']) {
  3154. $desc = t('Fill in the form below.');
  3155. $desc .= '<br />';
  3156. $desc .= t('You can also click on the map and move the marker.');
  3157. if (isset($form['country_from_' . $mapid])) {
  3158. $desc = t('Select a country first, then type in a town.');
  3159. $desc .= '<br />';
  3160. $desc .= t('You can also click on the map and move the marker.');
  3161. $form['country_from_' . $mapid]['#prefix'] = '<div id="getdirections_start_' . $mapid . '"><div class="container-inline getdirections_display">';
  3162. $form['country_from_' . $mapid]['#suffix'] = '</div>';
  3163. }
  3164. if (isset($form['from_' . $mapid])
  3165. && $form['from_' . $mapid]['#type'] == 'textfield'
  3166. && (module_exists('location') || module_exists('getlocations_fields'))
  3167. && ! $getdirections_defaults['advanced_autocomplete']
  3168. && isset($form['country_from_' . $mapid])
  3169. ) {
  3170. $form['from_' . $mapid]['#suffix'] = '</div><div class="getdirections_start_info" id="getdirections_start_info_' . $mapid . '"></div>';
  3171. }
  3172. if (isset($form['country_to_' . $mapid])) {
  3173. $form['country_to_' . $mapid]['#prefix'] = '<div id="getdirections_end_' . $mapid . '"><div class="container-inline getdirections_display">';
  3174. $form['country_to_' . $mapid]['#suffix'] = '</div>';
  3175. }
  3176. if (isset($form['to_' . $mapid])
  3177. && $form['to_' . $mapid]['#type'] == 'textfield'
  3178. && (module_exists('location') || module_exists('getlocations_fields'))
  3179. && ! $getdirections_defaults['advanced_autocomplete']
  3180. && isset($form['country_to_' . $mapid])
  3181. ) {
  3182. $form['to_' . $mapid]['#suffix'] = '</div><div class="getdirections_end_info" id="getdirections_end_info_' . $mapid . '"></div>';
  3183. }
  3184. if ($getdirections_defaults['advanced_autocomplete'] && $getdirections_defaults['waypoints'] > 0 && $getdirections_defaults['advanced_autocomplete_via'] && ! $getdirections_defaults['advanced_alternate'] ) {
  3185. for ($ct = 1; $ct <= $getdirections_defaults['waypoints']; $ct++) {
  3186. if ($ct == 1) {
  3187. $form['via_autocomplete_' . $mapid . '_' . $ct]['#prefix'] = '<div id="autocomplete_via_wrapper_' . $mapid . '"><div class="container-inline getdirections_display">';
  3188. $form['via_autocomplete_' . $mapid . '_' . $ct]['#suffix'] = '</div>';
  3189. }
  3190. elseif ($ct == $getdirections_defaults['waypoints']) {
  3191. $form['via_autocomplete_' . $mapid . '_' . $ct]['#prefix'] = '<div class="container-inline getdirections_display">';
  3192. $form['via_autocomplete_' . $mapid . '_' . $ct]['#suffix'] = '</div></div>';
  3193. }
  3194. else {
  3195. $form['via_autocomplete_' . $mapid . '_' . $ct]['#prefix'] = '<div class="container-inline getdirections_display">';
  3196. $form['via_autocomplete_' . $mapid . '_' . $ct]['#suffix'] = '</div>';
  3197. }
  3198. }
  3199. }
  3200. }
  3201. else {
  3202. if (isset($form['country_from_' . $mapid])) {
  3203. $form['country_from_' . $mapid]['#prefix'] = '<div class="container-inline getdirections_display">';
  3204. $form['country_from_' . $mapid]['#suffix'] = '</div>';
  3205. }
  3206. if (isset($form['country_to_' . $mapid])) {
  3207. $form['country_to_' . $mapid]['#prefix'] = '<div class="container-inline getdirections_display">';
  3208. $form['country_to_' . $mapid]['#suffix'] = '</div>';
  3209. }
  3210. $desc = t('Fill in the form below.');
  3211. }
  3212. if (isset($form['switchfromto_' . $mapid])) {
  3213. $form['switchfromto_' . $mapid]['#prefix'] = '<div id="getdirections_switchfromto_' . $mapid . '">';
  3214. $form['switchfromto_' . $mapid]['#suffix'] = '</div>';
  3215. }
  3216. if (isset($form['next_' . $mapid])) {
  3217. $form['next_' . $mapid]['#prefix'] = '<div id="getdirections_nextbtn_' . $mapid . '">';
  3218. $form['next_' . $mapid]['#suffix'] = '</div>';
  3219. }
  3220. if (isset($form['submit_' . $mapid])) {
  3221. $form['submit_' . $mapid]['#prefix'] = '<div id="getdirections_btn_' . $mapid . '">';
  3222. $form['submit_' . $mapid]['#suffix'] = '</div>';
  3223. }
  3224. $output .= '<p class="description">' . $desc . '</p>';
  3225. $output .= drupal_render_children($form);
  3226. // buttons
  3227. $buttons = array();
  3228. $output_buttons = '';
  3229. if ($getdirections_misc['trafficinfo']) {
  3230. $buttons[] = '<input type="button" value="' . t('Traffic Info !t', array('!t' => ($getdirections_misc['trafficinfo_state'] ? t('Off') : t('On')))) . '" title="' . t('Limited Availability') . '" id="getdirections_toggleTraffic_' . $mapid . '" class="form-submit" />';
  3231. }
  3232. if ($getdirections_misc['bicycleinfo']) {
  3233. $buttons[] = '<input type="button" value="' . t('Bicycle Info !t', array('!t' => ($getdirections_misc['bicycleinfo_state'] ? t('Off') : t('On')))) . '" title="' . t('Limited Availability') . '" id="getdirections_toggleBicycle_' . $mapid . '" class="form-submit" />';
  3234. }
  3235. if ($getdirections_misc['transitinfo']) {
  3236. $buttons[] = '<input type="button" value="' . t('Transit Info !t', array('!t' => ($getdirections_misc['transitinfo_state'] ? t('Off') : t('On')))) . '" title="' . t('Limited Availability') . '" id="getdirections_toggleTransit_' . $mapid . '" class="form-submit" />';
  3237. }
  3238. if ($getdirections_misc['panoramio_use'] && $getdirections_misc['panoramio_show']) {
  3239. $buttons[] = '<input type="button" value="' . t('Panoramio !t', array('!t' => ($getdirections_misc['panoramio_state'] ? t('Off') : t('On')))) . '" id="getdirections_togglePanoramio_' . $mapid . '" class="form-submit" />';
  3240. }
  3241. if ($getdirections_misc['weather_use']) {
  3242. if ($getdirections_misc['weather_use'] && $getdirections_misc['weather_show']) {
  3243. $buttons[] = '<input type="button" value="' . t('Weather !t', array('!t' => ($getdirections_misc['weather_state'] ? t('Off') : t('On')))) . '" id="getdirections_toggleWeather_' . $mapid . '" class="form-submit" />';
  3244. }
  3245. if ($getdirections_misc['weather_cloud']) {
  3246. $buttons[] = '<input type="button" value="' . t('Clouds !t', array('!t' => ($getdirections_misc['weather_cloud_state'] ? t('Off') : t('On')))) . '" id="getdirections_toggleCloud_' . $mapid . '" class="form-submit" />';
  3247. }
  3248. }
  3249. if (count($buttons)) {
  3250. $output_buttons .= '<div class="getdirections_map_buttons container-inline">';
  3251. $output_buttons .= implode('&nbsp;', $buttons);
  3252. $output_buttons .= '</div>';
  3253. }
  3254. $output .= $output_buttons;
  3255. return $output;
  3256. }
  3257. /**
  3258. * For use with colorbox.
  3259. *
  3260. */
  3261. function template_preprocess_getdirections_box(&$variables) {
  3262. if (module_exists('admin_menu')) {
  3263. admin_menu_suppress();
  3264. }
  3265. drupal_add_js(GETDIRECTIONS_PATH . '/js/getdirections_box.js');
  3266. // Construct page title
  3267. if (drupal_get_title()) {
  3268. $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
  3269. }
  3270. else {
  3271. $head_title = array(variable_get('site_name', 'Drupal'));
  3272. if (variable_get('site_slogan', '')) {
  3273. $head_title[] = variable_get('site_slogan', '');
  3274. }
  3275. }
  3276. $variables['head_title'] = implode(' | ', $head_title);
  3277. $variables['base_path'] = base_path();
  3278. $variables['head'] = drupal_get_html_head();
  3279. $variables['language'] = $GLOBALS['language'];
  3280. $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
  3281. $variables['css'] = drupal_add_css();
  3282. $variables['styles'] = drupal_get_css();
  3283. $variables['scripts'] = drupal_get_js();
  3284. $variables['title'] = drupal_get_title();
  3285. // Closure should be filled last.
  3286. $variables['closure'] = theme('closure');
  3287. // Compile a list of classes that are going to be applied to the body element.
  3288. // This allows advanced theming based on context (home page, node of certain type, etc.).
  3289. $body_classes = array();
  3290. // Add a class that tells us whether we're on the front page or not.
  3291. $body_classes[] = $variables['is_front'] ? 'front' : 'not-front';
  3292. // Add a class that tells us whether the page is viewed by an authenticated user or not.
  3293. $body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
  3294. $body_classes[] = 'no-sidebars';
  3295. // Implode with spaces.
  3296. $variables['body_classes'] = implode(' ', $body_classes);
  3297. }
  3298. /**
  3299. * Manipulates the address.
  3300. *
  3301. */
  3302. function theme_getdirections_loadaddress($variables) {
  3303. $location = $variables['location'];
  3304. $addcountry = $variables['addcountry'];
  3305. $loc = array();
  3306. # if (isset($location['name']) && $location['name']) {
  3307. # $loc[] = $location['name'];
  3308. # }
  3309. if (isset($location['street']) && $location['street']) {
  3310. $loc[] = $location['street'];
  3311. }
  3312. if (isset($location['additional']) && $location['additional']) {
  3313. $loc[] = $location['additional'];
  3314. }
  3315. if (isset($location['city']) && $location['city']) {
  3316. $loc[] = $location['city'];
  3317. }
  3318. if (isset($location['province_name']) && $location['province_name']) {
  3319. $loc[] = $location['province_name'];
  3320. }
  3321. if (isset($location['postal_code']) && $location['postal_code']) {
  3322. $loc[] = $location['postal_code'];
  3323. }
  3324. if ($addcountry) {
  3325. if (isset($location['country']) && $location['country']) {
  3326. $loc[] = drupal_strtoupper($location['country']);
  3327. }
  3328. }
  3329. $output = implode(', ', $loc);
  3330. return $output;
  3331. }
  3332. /**
  3333. * Handles addressfield
  3334. *
  3335. */
  3336. function theme_getdirections_addressfield_loadaddress($variables) {
  3337. $address = $variables['address'];
  3338. $addcountry = $variables['addcountry'];
  3339. $location = getdirections_addressfield_convert($address);
  3340. return theme('getdirections_loadaddress', array('location' => $location, 'addcountry' => $addcountry));
  3341. }
  3342. /**
  3343. * Manipulates addressfield to make it compatible with $location
  3344. *
  3345. */
  3346. function theme_getdirections_addressfield_convert($variables) {
  3347. $address = $variables['address'];
  3348. $location = array();
  3349. if (is_array($address) && ! empty($address)) {
  3350. $name = array();
  3351. if (isset($address['name_line']) && $address['name_line']) {
  3352. $name[] = $address['name_line'];
  3353. }
  3354. if (isset($address['first_name']) && $address['first_name']) {
  3355. if (isset($address['last_name']) && $address['last_name']) {
  3356. $name[] = $address['first_name'] . ' ' . $address['last_name'];
  3357. }
  3358. else {
  3359. $name[] = $address['first_name'];
  3360. }
  3361. }
  3362. elseif (isset($address['last_name']) && $address['last_name']) {
  3363. $name[] = $address['last_name'];
  3364. }
  3365. if (isset($address['organisation_name']) && $address['organisation_name']) {
  3366. $name[] = $address['organisation_name'];
  3367. }
  3368. $location['name'] = (count($name) ? implode(", ", $name) : '');
  3369. $location['street'] = (isset($address['thoroughfare']) ? $address['thoroughfare'] : '');
  3370. $additional = array();
  3371. if (isset($address['premise']) && $address['premise']) {
  3372. $additional[] = $address['premise'];
  3373. }
  3374. if (isset($address['sub_premise']) && $address['sub_premise']) {
  3375. $additional[] = $address['sub_premise'];
  3376. }
  3377. $location['additional'] = (count($additional) ? implode(", ", $additional) : '');
  3378. $city = array();
  3379. if (isset($address['dependent_locality']) && $address['dependent_locality']) {
  3380. $city[] = $address['dependent_locality'];
  3381. }
  3382. if (isset($address['locality']) && $address['locality']) {
  3383. $city[] = $address['locality'];
  3384. }
  3385. $location['city'] = (count($city) ? implode(", ", $city) : '');
  3386. $admin_area = array();
  3387. if (isset($address['sub_administrative_area']) && $address['sub_administrative_area']) {
  3388. $admin_area[] = $address['sub_administrative_area'];
  3389. }
  3390. if (isset($address['administrative_area']) && $address['administrative_area']) {
  3391. $admin_area[] = $address['administrative_area'];
  3392. }
  3393. $location['province_name'] = (count($admin_area) ? implode(", ", $admin_area) :'');
  3394. $location['postal_code'] = (isset($address['postal_code']) ? drupal_strtoupper($address['postal_code']) : '');
  3395. $location['country_name'] = (isset($address['country_name']) ? $address['country_name'] : $address['country']);
  3396. $location['country'] = $address['country'];
  3397. }
  3398. return $location;
  3399. }
  3400. function theme_getdirections_settings_form($variables) {
  3401. $form = $variables['form'];
  3402. $output = '';
  3403. $getdirections_defaults = getdirections_defaults();
  3404. $getdirections_misc = getdirections_misc_defaults();
  3405. $getdirections_defaults['preview_map'] = 1;
  3406. getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  3407. $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  3408. $mapid = getdirections_get_key();
  3409. drupal_add_js(array('getdirections_preview' => array($mapid => $getdirections_settings)), 'setting');
  3410. if (empty($width)) {
  3411. $width = $getdirections_defaults['width'];
  3412. }
  3413. if (empty($height)) {
  3414. $height = $getdirections_defaults['height'];
  3415. }
  3416. $preview_map = '<div id="getdirections_preview_map_canvas_' . $mapid . '" style="width:' . $width . '; height:' . $height . ';" ></div>';
  3417. // buttons
  3418. $buttons = array();
  3419. $output_buttons = '';
  3420. if ($getdirections_misc['trafficinfo']) {
  3421. $buttons[] = '<input type="button" value="' . t('Traffic Info !t', array('!t' => ($getdirections_misc['trafficinfo_state'] ? t('Off') : t('On')))) . '" title="' . t('Limited Availability') . '" id="getdirections_toggleTraffic_' . $mapid . '" class="form-submit" />';
  3422. }
  3423. if ($getdirections_misc['bicycleinfo']) {
  3424. $buttons[] = '<input type="button" value="' . t('Bicycle Info !t', array('!t' => ($getdirections_misc['bicycleinfo_state'] ? t('Off') : t('On')))) . '" title="' . t('Limited Availability') . '" id="getdirections_toggleBicycle_' . $mapid . '" class="form-submit" />';
  3425. }
  3426. if ($getdirections_misc['transitinfo']) {
  3427. $buttons[] = '<input type="button" value="' . t('Transit Info !t', array('!t' => ($getdirections_misc['transitinfo_state'] ? t('Off') : t('On')))) . '" title="' . t('Limited Availability') . '" id="getdirections_toggleTransit_' . $mapid . '" class="form-submit" />';
  3428. }
  3429. if ($getdirections_misc['panoramio_use'] && $getdirections_misc['panoramio_show']) {
  3430. $buttons[] = '<input type="button" value="' . t('Panoramio !t', array('!t' => ($getdirections_misc['panoramio_state'] ? t('Off') : t('On')))) . '" id="getdirections_togglePanoramio_' . $mapid . '" class="form-submit" />';
  3431. }
  3432. if ($getdirections_misc['weather_use']) {
  3433. if ($getdirections_misc['weather_use'] && $getdirections_misc['weather_show']) {
  3434. $buttons[] = '<input type="button" value="' . t('Weather !t', array('!t' => ($getdirections_misc['weather_state'] ? t('Off') : t('On')))) . '" id="getdirections_toggleWeather_' . $mapid . '" class="form-submit" />';
  3435. }
  3436. if ($getdirections_misc['weather_cloud']) {
  3437. $buttons[] = '<input type="button" value="' . t('Clouds !t', array('!t' => ($getdirections_misc['weather_cloud_state'] ? t('Off') : t('On')))) . '" id="getdirections_toggleCloud_' . $mapid . '" class="form-submit" />';
  3438. }
  3439. }
  3440. if (count($buttons)) {
  3441. $output_buttons .= '<div class="getdirections_map_buttons container-inline">';
  3442. $output_buttons .= implode('&nbsp;', $buttons);
  3443. $output_buttons .= '</div>';
  3444. }
  3445. $preview_map .= $output_buttons;
  3446. $form['getdirections_preview']['preview_map']['#markup'] = '<div id="getdirections_preview_map">' . $preview_map . '</div>';
  3447. $output .= drupal_render_children($form);
  3448. return $output;
  3449. }