You are here

function patterns_d2d_push_patterns_client in Patterns 7.2

Same name and namespace in other branches
  1. 7 patterns_d2d/includes/patterns_d2d.srpc.inc \patterns_d2d_push_patterns_client()
1 call to patterns_d2d_push_patterns_client()
patterns_d2d_patterns_publish in patterns_d2d/patterns_d2d.module

File

patterns_d2d/includes/patterns_d2d.srpc.inc, line 46
Code related to send pattern to server / receive pattern as server.

Code

function patterns_d2d_push_patterns_client($patterns) {
  $url = variable_get('patterns_d2d_server', PATTERNS_D2D_SERVER);
  $friend = patterns_d2d_get_friend($url);
  if ($friend === FALSE) {
    drupal_set_message(t('Patterns server not listed as friend instance.'), 'error');
    return;
  }
  $upload_patterns = array();
  foreach ($patterns as $pattern) {

    //drupal_set_message(var_export($pattern, TRUE));
    $name = $pattern->name;
    $format = $pattern->format;

    /*
    $raw_pattern = $pattern->pattern;
    $dumped_pattern = patterns_parser_dump($raw_pattern, $format);
    */
    $content = file_get_contents($pattern->file);
    if ($content === FALSE) {
      drupal_set_message(t('Pattern') . ' ' . check_plain($name) . ' ' . t('could not be processed'), 'error');

      // TODO: proper t()
      continue;
    }
    $imploded_pattern = drupaltodrupal_implode(array(
      'name' => $name,
      'format' => $format,
      'content' => $content,
    ));
    if ($imploded_pattern !== FALSE) {
      $upload_patterns[] = $imploded_pattern;
    }
  }
  $error_string = '';
  $imploded_patterns = drupaltodrupal_implode($upload_patterns);
  if ($imploded_patterns === FALSE) {
    $res = FALSE;
    $error_string = t('Internal error while collecting patterns to be sent.');
  }
  else {
    $res = drupaltodrupal_call_secure_rpc($friend, 'patterns_d2d_push_patterns', array(
      'patterns' => $imploded_patterns,
    ), $error_string);
  }
  if ($res === FALSE) {
    drupal_set_message(check_plain($url) . ' - ' . check_plain($error_string), 'error');
  }
  else {
    drupal_set_message('Upload to server successful.<br/>' . check_plain($url) . ' - ' . check_plain($res));

    // TODO: proper t()
  }
}