Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit d3dd3674537d907cff37ffb76270a832d7541deb unknown committed Jul 20, 2012
Showing with 91 additions and 0 deletions.
  1. +6 −0 digital_strategy.info
  2. +50 −0 digital_strategy.install
  3. +35 −0 digital_strategy.module
@@ -0,0 +1,6 @@
+
+name = Digital Strategy
+description = Creates 3 page nodes for digital strategy progess on enable. Also creates menu callbacks which load the page nodes and output just the body with the appropriate content type headers.
+core = 6.x
+package = Digital Strategy
+dependencies[] = path
@@ -0,0 +1,50 @@
+<?php
+function digital_strategy_install() {
+ variable_set('digital_strategy_types', array("xml", "json", "jsonp"));
+ digital_strategy_create_nodes();
+}
+
+function digital_strategy_enable() {
+ variable_set('digital_strategy_types', array("xml", "json", "jsonp"));
+ digital_strategy_create_nodes();
+}
+
+function digital_strategy_disable() {
+ foreach (variable_get('digital_strategy_types', array("xml", "json", "jsonp")) as $type) {
+ $alias = "digital-strategy/progress-" . $type;
+ $path = drupal_lookup_path("source", $alias);
+ $node = menu_get_object("node", 1, $path);
+
+ if ($node) {
+ node_delete($node->nid);
+ } else {
+ drupal_set_message(t('@alias not deleted, it did not exist.', array('@alias' => $alias)), 'warning');
+ }
+ }
+
+ variable_del('strategy_types');
+}
+
+function digital_strategy_create_nodes() {
+ foreach (variable_get('digital_strategy_types', array("xml", "json", "jsonp")) as $type) {
+ $node = new stdClass();
+
+ $node->name = "Digital Strategy Progess - " . $type;
+ $node->title = $node->name;
+ $node->body = "";
+ $node->type = "page";
+ $node->created = time();
+ $node->changed = $node->created;
+ $node->status = 0;
+ $node->promote = 0;
+ $node->sticky = 0;
+ $node->format = 2;
+ $node->uid = 1;
+
+ $node->path = "digital-strategy/progress-" . $type;
+
+ if ($node = node_submit($node)) {
+ node_save($node);
+ }
+ } // end foreach
+}
@@ -0,0 +1,35 @@
+<?php
+function digital_strategy_menu() {
+ $items = array();
+
+ foreach (variable_get('digital_strategy_types', array("xml", "json", "jsonp")) as $type) {
+ $items['digital-strategy/' . $type] = array(
+ 'access arguments' => array('access content'),
+ 'page callback' => 'digital_strategy_themeless',
+ 'page arguments' => array($type),
+ 'title' => $type,
+ 'type' => MENU_CALLBACK,
+ );
+
+ } // end foreach
+
+ return $items;
+}
+
+function digital_strategy_themeless ($type = '') {
+ // get the node based on the path
+ // we know the path because we created it
+ $alias = "digital-strategy/progress-" . $type;
+ $path = drupal_lookup_path("source", $alias);
+ $node = menu_get_object("node", 1, $path);
+
+ // set correct content type header
+ $content_type = 'application/json';
+ if ($type == 'xml') {
+ $content_type = 'text/xml';
+ }
+ drupal_set_header("Content-Type: " . $content_type . "; charset=utf-8");
+
+ // output the body only, no theme
+ echo $node->body;
+}

0 comments on commit d3dd367

Please sign in to comment.