? arialbd.ttf
Index: barcode.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/barcode/barcode.info,v
retrieving revision 1.1
diff -u -p -r1.1 barcode.info
--- barcode.info	17 Nov 2008 21:30:35 -0000	1.1
+++ barcode.info	25 Sep 2009 20:32:46 -0000
@@ -1,7 +1,6 @@
 ;$Id: barcode.info,v 1.1 2008/11/17 21:30:35 skyredwang Exp $
 name = Barcode
-description = Generate a barcode image on the fly. It supports EAN-13,EAN-8,UPC-A,UPC-E,ISBN ,2 of 5 Symbologies(std,ind,interleaved),postnet,codabar,code128,code39,code93 symbologies.
-dependencies[] = content
+description = This module provides an API for other modules to use to create barcodes.
 package = CCK
 core = 6.x
 
Index: barcode.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/barcode/barcode.install,v
retrieving revision 1.1
diff -u -p -r1.1 barcode.install
--- barcode.install	17 Nov 2008 21:30:35 -0000	1.1
+++ barcode.install	25 Sep 2009 20:32:46 -0000
@@ -1,41 +1,25 @@
 <?php
 // $Id: barcode.install,v 1.1 2008/11/17 21:30:35 skyredwang Exp $
 
-/**
- * @file
- * Implementation of hook_install().
- */
-function barcode_install() {
-  drupal_load('module', 'content');
-  content_notify('install', 'barcode');
-}
+function barcode_update_6000() {
+  $ret[] = update_sql("UPDATE {content_node_field_instance} SET widget_type = 'barcode_cck_textfield', widget_module = 'barcode_cck' WHERE widget_module = 'barcode'");
 
-/**
- * Implementation of hook_uninstall().
- */
-function barcode_uninstall() {
-  drupal_load('module', 'content');
-  content_notify('uninstall', 'barcode');
-}
+  $ret[] = update_sql('DELETE FROM {cache}');
 
-/**
- * Implementation of hook_enable().
- *
- * Notify content module when this module is enabled.
- */
-function barcode_enable() {
-  drupal_load('module', 'content');
-  content_notify('enable', 'barcode');
+  return $ret;
 }
 
 /**
- * Implementation of hook_disable().
- *
- * Notify content module when this module is disabled.
+ * Implementation of hook_uninstall().
  */
-function barcode_disable() {
-  drupal_load('module', 'content');
-  content_notify('disable', 'barcode');
+function barcode_uninstall() {
+  variable_del('barcode_encoding');
+  variable_del('barcode_height');
+  variable_del('barcode_scale');
+  variable_del('barcode_bcolor');
+  variable_del('barcode_barcolor');
+  variable_del('barcode_font');
+  variable_del('barcode_default_path');
 }
 
 /**
@@ -43,6 +27,7 @@ function barcode_disable() {
  */
 function barcode_requirements($phase) {
   $requirements = array();
+drupal_set_message("Here " . $phase);
   if ($phase == 'runtime') {
      // File paths
     $barcode_path = file_create_path(rtrim(variable_get('barcode_default_path', 'barcodes')));
Index: barcode.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/barcode/barcode.module,v
retrieving revision 1.1
diff -u -p -r1.1 barcode.module
--- barcode.module	17 Nov 2008 21:30:35 -0000	1.1
+++ barcode.module	25 Sep 2009 20:32:46 -0000
@@ -2,254 +2,6 @@
 
 // $Id: barcode.module,v 1.1 2008/11/17 21:30:35 skyredwang Exp $
 
-
-/**
- * Implementation of hook_theme().
- */
-function barcode_theme() {
-  return array(
-    'barcode_formatter_plain' => array(
-      'arguments' => array('element' => NULL),
-    ),
-    'barcode_formatter_default' => array(
-      'arguments' => array('element' => NULL),
-    ),
-    'barcode_textfield' => array(
-      'arguments' => array('element' => NULL),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_field_info().
- */
-function barcode_field_info() {
-  return array(
-    'barcode' => array(
-      'label' => 'Bar Code',
-      'callbacks' => array(
-        'tables' => CONTENT_CALLBACK_DEFAULT,
-        'arguments' => CONTENT_CALLBACK_DEFAULT,
-      ),
-    ),
-  );
-}
-
-
-/**
- * Implementation of hook_field_settings().
- */
-function barcode_field_settings($op, $field) {
-  switch ($op) {
-    case 'form':
-      $form = array(
-        '#theme' => 'barcode_field_settings',
-      );
-
-      $title_options = array(
-        'optional' => t('Optional Title'),
-        'required' => t('Required Title'),
-        'none' => t('No Title'),
-      );
-
-      $form['title'] = array(
-        '#type' => 'radios',
-        '#title' => t('Bar Code Title'),
-        '#default_value' => isset($field['title']) ? $field['title'] : 'optional',
-        '#options' => $title_options,
-        '#description' => t('If the barcode title is optional or required, a field will be displayed to the end user.'),
-      );
-      return $form;
-
-    case 'save':
-      return array('title','title_value');
-
-    case 'database columns':
-      return array(
-        'barcode' => array('type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE),
-        'title' => array('type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE),
-      );
-
-    //Todo develop Views2 support
-  }
-}
-
-/**
- * Implementation of hook_field().
- */
-function barcode_field($op, &$node, $field, &$items, $teaser, $page) {
-  switch ($op) {
-    case 'sanitize':
-      foreach ($items as $delta => $item) {
-        $items[$delta]['bar'] = check_plain($item['barcode']);
-        $items[$delta]['title'] = check_plain($item['title']);
-      }
-      break;
-  }
-}
-
-/**
- * Implementation of hook_content_is_empty().
- */
-function barcode_content_is_empty($item, $field) {
-  if (empty($item['barcode'])) {
-    return TRUE;
-  }
-  return FALSE;
-}
-
-/**
- * Implementation of hook_field_formatter_info().
- *
- */
-function barcode_field_formatter_info() {
-  $formats = array(
-    'default' => array(
-      'label' => t('Barcode Image'),
-      'field types' => array('barcode','title'),
-      'multiple values' => CONTENT_HANDLE_CORE,
-    ),
-    'plain' => array(
-      'label' => t('Barcode Text'),
-      'field types' => array('barcode','title'),
-      'multiple values' => CONTENT_HANDLE_CORE,
-    ),
-  );
-  return $formats;
-}
-
-/**
- * Theme function for 'plain' barcode field formatter.
- */
-function theme_barcode_formatter_plain($element) {
-  if (!empty($element['#item']['title'])){
-        return $element['#item']['title'].': '.$element['#item']['bar'];
-     }else return $element['#item']['bar'];
-}
-
-/**
- * Theme function for 'default' barcode field formatter.
- */
-function theme_barcode_formatter_default($element) {
-  if(!empty($element['#item']['bar'])){
-     // First to check if the images has been generated from preview request
-     $path = variable_get('barcode_default_path', 'barcodes');
-     $encoding = variable_get('barcode_encoding', array('EAN-13'));
-     $filename = file_create_path($path).'/'.$element['#item']['bar'].$encoding.'.png';
-     if (!file_exists($filename)) {
-        include_once drupal_get_path('module', 'barcode') . '/barcode.inc.php';
-        $bar= new BARCODE();
-        $type = 'png';
-        $bar->setSymblogy($encoding);
-        $bar->setHeight(variable_get('barcode_height', 30));
-        $bar->setScale(variable_get('barcode_scale', 2.0));
-        $bar->setHexColor(variable_get('barcode_bcolor', '#000000'),variable_get('barcode_barcolor', '#FFFFFF'));
-        $bar->setFont(variable_get('barcode_font', drupal_get_path('module', 'barcode') ."/arialbd.ttf"));
-        $bar->genBarCode($element['#item']['bar'],$type,file_create_path($path).'/'.$element['#item']['bar'].$encoding);
-        drupal_set_message(t('The barcode image for %barcode has been generated, using %encoding.', array('%barcode'=>$element['#item']['bar'],'%encoding'=>$encoding)));
-     }
-     $path = variable_get('barcode_default_path', 'barcodes');
-     if (!empty($element['#item']['title'])){
-        return $element['#item']['title'].':<img src="/'.$filename.'">';
-     }else return '<img src="/'.$filename.'">';
-  }else return '';
-}
-
-/**
- * Implementation of hook_widget_info().
- */
-function barcode_widget_info() {
-  return array(
-    'barcode_textfield' => array(
-      'label' => t('Text field'),
-      'field types' => array('barcode'),
-      'multiple values' => CONTENT_HANDLE_CORE,
-      'callbacks' => array(
-        'default value' => CONTENT_CALLBACK_DEFAULT,
-      ),
-    ),
-  );
-}
-
-/**
- * Implementation of FAPI hook_elements().
- */
-function barcode_elements() {
-  return array(
-    'barcode_textfield' => array(
-      '#input' => TRUE,
-      '#columns' => array('barcode','title'),
-      //'#delta' => 0,
-      '#process' => array('barcode_process'),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_widget().
- */
-function barcode_widget(&$form, &$form_state, $field, $items, $delta = 0) {
-  $element = array(
-    '#type' => $field['widget']['type'],
-    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
-  );
-  return $element;
-}
-
-/**
- * Process an individual element.
- */
-function barcode_process($element, $edit, $form_state, $form) {
-  $field = $form['#field_info'][$element['#field_name']];
-  $field_key = $element['#columns'][0]; //here $field_key is barcode
-  $delta = $element['#delta'];
-  if ($field['title'] != 'none' && $field['title'] != 'value') {
-     $element['title'] = array(
-       '#type' => 'textfield',
-       '#maxlength' => '20',
-       '#size' => '20',
-       '#title' => t('Title'),
-       '#required' => ($field['title'] == 'required' && !empty($element['#value'][$field_key])) ? TRUE : FALSE,
-       '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
-     );
-   }
-  $element[$field_key] = array(
-    '#type' => 'textfield',
-    '#maxlength' => '20',
-    '#size' => '20',
-    '#title' => t($field['widget']['label']),
-    '#description' => t($field['widget']['description']),
-    '#required' => $element['#required'],
-    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
-  );
-  return $element;
-}
-
-/**
- * FAPI theme for an individual text elements.
- */
-function theme_barcode_textfield($element) {
-  drupal_add_css(drupal_get_path('module', 'barcode') .'/barcode.css');
-  // Prefix single value barcode fields with the name of the field.
-  if (empty($element['#field']['multiple'])) {
-    if (isset($element['barcode']) && isset($element['title'])) {
-      $element['barcode']['#title'] = $element['#title'] .' '. $element['barcode']['#title'];
-      $element['title']['#title'] = $element['#title'] .' '. $element['title']['#title'];
-    }
-    elseif($element['barcode']) {
-      $element['barcode']['#title'] = $element['#title'];
-    }
-  }
-  $output = '';
-  $output .= '<div class="barcode-field-subrow clear-block">';
-  if (isset($element['title'])) {
-    $output .= '<div class="barcode-field-title barcode-field-column">' . theme('textfield', $element['title']) . '</div>';
-  }
-  $output .= '<div class="barcode-field-url' . (isset($element['title']) ? ' barcode-field-column' : '') . '">' . theme('textfield', $element['barcode']) . '</div>';
-  $output .= '</div>';
-  return $output;
-}
-
 /**
   * Implementation of hook_menu()
   * Configuration
@@ -332,3 +84,61 @@ function barcode_settings(){
   );
   return system_settings_form($form);
 }
+
+/**
+ * Theme function for 'default' barcode field formatter.
+ */
+function barcode_build_image($barcode, $encoding = NULL, $type = 'png', $height = NULL, $scale = NULL, $bcolor = NULL, $barcolor = NULL, $fontfile = NULL) {
+  // First to check if the images has been generated from preview request
+  $path = variable_get('barcode_default_path', 'barcodes');
+
+  if($encoding == NULL) {
+    $encoding = variable_get('barcode_encoding', 'EAN-13');
+  }
+
+  $filename = file_create_path($path) .'/'. $barcode . $encoding .'.'. $type;
+
+  if (!file_exists($filename)) {
+    include_once drupal_get_path('module', 'barcode') . '/barcode.inc.php';
+    $bar = new BARCODE();
+
+    $bar->setSymblogy($encoding);
+
+    if($height == NULL) {
+      $height = variable_get('barcode_height', 30);
+    }
+    $bar->setHeight($height);
+
+    if($scale == NULL) {
+      $scale = variable_get('barcode_scale', 2.0);
+    }
+    $bar->setScale($scale);
+
+    if($bcolor == NULL) {
+      $bcolor = variable_get('barcode_bcolor', '#000000');
+    }
+
+    if($barcolor == NULL) {
+      $barcolor = variable_get('barcode_barcolor', '#FFFFFF');
+    }
+    $bar->setHexColor($bcolor, $barcolor);
+
+    if($fontfile == NULL) {
+      $fontfile = variable_get('barcode_font', drupal_get_path('module', 'barcode')
+ ."/arialbd.ttf");
+    }
+    $bar->setFont($fontfile);
+
+    $bar->genBarCode($barcode, $type, file_create_path($path) .'/'. $barcode . $encoding);
+
+    if(!$bar->_error) {
+      drupal_set_message(t('The barcode image for %barcode has been generated, using %encoding.', array('%barcode'=>$barcode,'%encoding'=>$encoding)));
+    } else { 
+      /* TODO: Error message, watchdog? */
+    }
+ 
+    return $filename;
+  } else {
+   return $filename;
+  }
+}
Index: barcode_cck.info
===================================================================
RCS file: barcode_cck.info
diff -N barcode_cck.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ barcode_cck.info	25 Sep 2009 20:32:46 -0000
@@ -0,0 +1,8 @@
+;$Id$
+name = Barcode CCK
+description = Uses Barcode API to provide a CCK field which generates a barcode image on the fly.
+dependencies[] = content
+dependencies[] = barcode
+package = CCK
+core = 6.x
+
Index: barcode_cck.install
===================================================================
RCS file: barcode_cck.install
diff -N barcode_cck.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ barcode_cck.install	25 Sep 2009 20:32:46 -0000
@@ -0,0 +1,39 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implementation of hook_install().
+ */
+function barcode_cck_install() {
+  drupal_load('module', 'content');
+  content_notify('install', 'barcode_cck');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function barcode_cck_uninstall() {
+  drupal_load('module', 'content');
+  content_notify('uninstall', 'barcode_cck');
+}
+
+/**
+ * Implementation of hook_enable().
+ *
+ * Notify content module when this module is enabled.
+ */
+function barcode_cck_enable() {
+  drupal_load('module', 'content');
+  content_notify('enable', 'barcode_cck');
+}
+
+/**
+ * Implementation of hook_disable().
+ *
+ * Notify content module when this module is disabled.
+ */
+function barcode_cck_disable() {
+  drupal_load('module', 'content');
+  content_notify('disable', 'barcode_cck');
+}
Index: barcode_cck.module
===================================================================
RCS file: barcode_cck.module
diff -N barcode_cck.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ barcode_cck.module	25 Sep 2009 20:32:47 -0000
@@ -0,0 +1,239 @@
+<?php
+
+// $Id$
+
+/**
+ * Implementation of hook_theme().
+ */
+function barcode_cck_theme() {
+  return array(
+    'barcode_cck_formatter_plain' => array(
+      'arguments' => array('element' => NULL),
+    ),
+    'barcode_cck_formatter_default' => array(
+      'arguments' => array('element' => NULL),
+    ),
+    'barcode_cck_textfield' => array(
+      'arguments' => array('element' => NULL),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_field_info().
+ */
+function barcode_cck_field_info() {
+  return array(
+    'barcode' => array(
+      'label' => 'Bar Code',
+      'callbacks' => array(
+        'tables' => CONTENT_CALLBACK_DEFAULT,
+        'arguments' => CONTENT_CALLBACK_DEFAULT,
+      ),
+    ),
+  );
+}
+
+
+/**
+ * Implementation of hook_field_settings().
+ */
+function barcode_cck_field_settings($op, $field) {
+  switch ($op) {
+    case 'form':
+      $form = array(
+        '#theme' => 'barcode_cck_field_settings',
+      );
+
+      $title_options = array(
+        'optional' => t('Optional Title'),
+        'required' => t('Required Title'),
+        'none' => t('No Title'),
+      );
+
+      $form['title'] = array(
+        '#type' => 'radios',
+        '#title' => t('Bar Code Title'),
+        '#default_value' => isset($field['title']) ? $field['title'] : 'optional',
+        '#options' => $title_options,
+        '#description' => t('If the barcode title is optional or required, a field will be displayed to the end user.'),
+      );
+      return $form;
+
+    case 'save':
+      return array('title','title_value');
+
+    case 'database columns':
+      return array(
+        'barcode' => array('type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE),
+        'title' => array('type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE),
+      );
+
+    //Todo develop Views2 support
+  }
+}
+
+/**
+ * Implementation of hook_field().
+ */
+function barcode_cck_field($op, &$node, $field, &$items, $teaser, $page) {
+  switch ($op) {
+    case 'sanitize':
+      foreach ($items as $delta => $item) {
+        $items[$delta]['bar'] = check_plain($item['barcode']);
+        $items[$delta]['title'] = check_plain($item['title']);
+      }
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_content_is_empty().
+ */
+function barcode_cck_content_is_empty($item, $field) {
+  if (empty($item['barcode'])) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
+ * Implementation of hook_field_formatter_info().
+ *
+ */
+function barcode_cck_field_formatter_info() {
+  $formats = array(
+    'default' => array(
+      'label' => t('Barcode Image'),
+      'field types' => array('barcode','title'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
+    'plain' => array(
+      'label' => t('Barcode Text'),
+      'field types' => array('barcode','title'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
+  );
+  return $formats;
+}
+
+/**
+ * Theme function for 'plain' barcode field formatter.
+ */
+function theme_barcode_cck_formatter_plain($element) {
+  if (!empty($element['#item']['title'])){
+        return $element['#item']['title'].': '.$element['#item']['bar'];
+     }else return $element['#item']['bar'];
+}
+
+/**
+ * Theme function for 'default' barcode field formatter.
+ */
+function theme_barcode_cck_formatter_default($element) {
+  if(!empty($element['#item']['bar'])){
+    $filename = barcode_build_image($element['#item']['bar']);
+
+    if (!empty($element['#item']['title'])){
+      return $element['#item']['title'].':<img src="/'.$filename.'">';
+    } else {
+      return '<img src="/'.$filename.'">';
+    }
+  } else {
+    return '';
+  }
+}
+
+/**
+ * Implementation of hook_widget_info().
+ */
+function barcode_cck_widget_info() {
+  return array(
+    'barcode_cck_textfield' => array(
+      'label' => t('Text field'),
+      'field types' => array('barcode'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+      'callbacks' => array(
+        'default value' => CONTENT_CALLBACK_DEFAULT,
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of FAPI hook_elements().
+ */
+function barcode_cck_elements() {
+  return array(
+    'barcode_cck_textfield' => array(
+      '#input' => TRUE,
+      '#columns' => array('barcode','title'),
+      //'#delta' => 0,
+      '#process' => array('barcode_cck_process'),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_widget().
+ */
+function barcode_cck_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+  $element = array(
+    '#type' => $field['widget']['type'],
+    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
+  );
+  return $element;
+}
+
+/**
+ * Process an individual element.
+ */
+function barcode_cck_process($element, $edit, $form_state, $form) {
+  $field = $form['#field_info'][$element['#field_name']];
+  $field_key = $element['#columns'][0]; //here $field_key is barcode
+  $delta = $element['#delta'];
+  if ($field['title'] != 'none' && $field['title'] != 'value') {
+     $element['title'] = array(
+       '#type' => 'textfield',
+       '#maxlength' => '20',
+       '#size' => '20',
+       '#title' => t('Title'),
+       '#required' => ($field['title'] == 'required' && !empty($element['#value'][$field_key])) ? TRUE : FALSE,
+       '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
+     );
+   }
+  $element[$field_key] = array(
+    '#type' => 'textfield',
+    '#maxlength' => '20',
+    '#size' => '20',
+    '#title' => t($field['widget']['label']),
+    '#description' => t($field['widget']['description']),
+    '#required' => $element['#required'],
+    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
+  );
+  return $element;
+}
+
+/**
+ * FAPI theme for an individual text elements.
+ */
+function theme_barcode_cck_textfield($element) {
+  drupal_add_css(drupal_get_path('module', 'barcode') .'/barcode.css');
+  // Prefix single value barcode fields with the name of the field.
+  if (empty($element['#field']['multiple'])) {
+    if (isset($element['barcode']) && isset($element['title'])) {
+      $element['barcode']['#title'] = $element['#title'] .' '. $element['barcode']['#title'];
+      $element['title']['#title'] = $element['#title'] .' '. $element['title']['#title'];
+    }
+    elseif($element['barcode']) {
+      $element['barcode']['#title'] = $element['#title'];
+    }
+  }
+  $output = '';
+  $output .= '<div class="barcode-field-subrow clear-block">';
+  if (isset($element['title'])) {
+    $output .= '<div class="barcode-field-title barcode-field-column">' . theme('textfield', $element['title']) . '</div>';
+  }
+  $output .= '<div class="barcode-field-url' . (isset($element['title']) ? ' barcode-field-column' : '') . '">' . theme('textfield', $element['barcode']) . '</div>';
+  $output .= '</div>';
+  return $output;
+}
