You are here

function getlocations_regenerate_markers in Get Locations 7

Same name and namespace in other branches
  1. 6.2 getlocations.module \getlocations_regenerate_markers()
  2. 6 getlocations.module \getlocations_regenerate_markers()
  3. 7.2 getlocations.module \getlocations_regenerate_markers()

Regenerate the markerdata file. adapted from gmap

2 calls to getlocations_regenerate_markers()
getlocations_flush_caches in ./getlocations.module
Implements hook_flush_caches().
_getlocations_rebuild_marker_js_submit in ./getlocations.admin.inc
Rebuild marker js.

File

./getlocations.module, line 2209
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_regenerate_markers() {

  // This often fails in cli mode, so bail.
  if (drupal_is_cli()) {
    return;
  }
  $icons = getlocations_get_icondata(TRUE);
  if ($icons) {
    $contents = '';
    $contents .= "// Getlocations marker image data.\n";
    $contents .= "Drupal.getlocations.iconpath = " . drupal_json_encode(base_path()) . ";\n";
    $contents .= "Drupal.getlocations.icondata = " . drupal_json_encode($icons) . ";\n";

    // Create the js/ within the files folder.
    $jspath = getlocations_get_markerfile(TRUE, FALSE);
    $jsfile = getlocations_get_markerfile(FALSE, FALSE);
    if ($jspath && $jsfile && file_prepare_directory($jspath, FILE_CREATE_DIRECTORY) && file_unmanaged_save_data($contents, $jsfile, FILE_EXISTS_REPLACE)) {

      // Also regenerate the cached marker titles array
      getlocations_get_marker_titles(TRUE);
    }
    else {

      // failed
      drupal_set_message(t('Getlocations is unable to save the marker configuration, so the markers will not work. Please check file system permissions of %filepath!', array(
        '%filepath' => $jsfile,
      )), 'error');
      watchdog('getlocations', 'Getlocations write error when saving the marker configuration to %filepath.', array(
        '%filepath' => $jsfile,
      ), WATCHDOG_ERROR);
      return FALSE;
    }
  }
  else {

    // no markers found
    drupal_set_message(t('No markers found, you need to install some markers, please see the project page for details.'), 'error');
    watchdog('getlocations', 'No markers found.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  return TRUE;
}