You are here

function patterns_io_get_pattern_service in Patterns 7

Same name and namespace in other branches
  1. 7.2 includes/io/io.inc \patterns_io_get_pattern_service()

Menu callback, returns source code of the requested pattern if the pattern is public.

Parameters

integer $pid: The ID of the Pattern to be displayed.

1 string reference to 'patterns_io_get_pattern_service'
patterns_menu in ./patterns.module
Implements hook_menu().

File

includes/io/io.inc, line 15
Functions related to input/output operations.

Code

function patterns_io_get_pattern_service($pattern) {

  // TODO: handling correctly different formats
  $content_type = 'text/plain';
  drupal_add_http_header('Content-Type', $content_type . '; charset=utf-8');

  // GET service is available only if settings allows it
  if (!variable_get('patterns_allow_publish', PATTERNS_ALLOW_PUBLISH_DEFAULT)) {
    print 'Patterns GET service not available. Please try later.';
    exit;
  }
  $pattern = patterns_get_pattern($pattern);
  if (!$pattern) {
    print 'Invalid pattern identifier.';
    exit;
  }

  // Make sure pattern is public (published).
  if (!$pattern->public) {
    print 'Requested pattern is not available through GET service';
    exit;
  }

  // Finally
  print file_get_contents($pattern->file);
  exit;
}