? engines Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/qr_codes/Attic/README.txt,v retrieving revision 1.1.2.1 diff -u -p -r1.1.2.1 README.txt --- README.txt 4 May 2010 19:38:33 -0000 1.1.2.1 +++ README.txt 26 Jun 2010 14:44:10 -0000 @@ -2,10 +2,12 @@ $Id: Description =========== -This modules allows for the creation of two dimensional (2D) QR barcodes using the Google Charts API. +This modules allows for the creation of two dimensional (2D) QR barcodes. "QR codes are a popular type of two-dimensional barcode. They are also known as hardlinks or physical world hyperlinks. QR Codes store up to 4,296 alphanumeric characters of arbitrary text. This text can be anything, for example URL, contact information, a telephone number, even a poem! QR codes can be read by an optical device with the appropriate software. Such devices range from dedicated QR code readers to mobile phones." Learn more at http://code.google.com/apis/chart/docs/gallery/qr_codes.html. -The module exposes an API for creating your own barcodes, a theme function for returning the images, and a block for displaying configurable node data as a qr code. QR code images are cached locally for faster performance and further manipulation. The module plays well with Imagecache and Token, which are recommended but not required. \ No newline at end of file +The module exposes an API for creating your own barcodes, a theme function for returning the images, and a block for displaying configurable node data as a qr code. QR code images are cached locally for faster performance and further manipulation. The module plays well with Imagecache and Token, which are recommended but not required. + +You should enable the module and at least one engine module that provides QR encoding. \ No newline at end of file Index: qr_codes.admin.inc =================================================================== RCS file: qr_codes.admin.inc diff -N qr_codes.admin.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ qr_codes.admin.inc 26 Jun 2010 14:44:10 -0000 @@ -0,0 +1,45 @@ + 'select', + '#title' => t('Select the QR encoding engine'), + '#description' => '

'. t('Select which engine/API is used to generate QR Code images. The following options are available as enabled modules:') .'

'. theme('item_list', module_invoke_all('qr_codes', 'description')) .'

'. t('If your option is not in the list, you should enable the appropriate sub-module. Additionaly you can plug other engines/APIs by implementing hook_qr_codes() in your module.') .'

', + '#options' => $options, + '#default_value' => variable_get('qr_codes_engine', 'qr_codes_google_chart:google_chart'), + ); + return system_settings_form($form); + } + else { + $form['warning'] = array( + '#type' => 'markup', + '#value' => '

'. t('No QR Codes encoder is enabled! You should enable at least one engine module. Those modules are placed under sites/all/modules/qr_codes/engines directory.') .'

'. t('Visit the Modules page to enable one or more engine modules. Alternatively you can implement additional engines in other modules using hook_qr_codes().') .'

', + ); + return $form; + } +} + +/** + * Page callback for 'admin/settings/qr_codes/' path. + * + * @param $form_state + * Associative FAPI array. + * @param $module + * String containing the module name. + * @param $engine_id + * String containing the engine ID. + * + * @return + * FAPI Array. + */ +function qr_codes_engine_settings($form_state, $module, $engine_id) { + return system_settings_form(module_invoke($module, 'qr_codes', 'config', $engine_id)); +} Index: qr_codes.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/qr_codes/qr_codes.info,v retrieving revision 1.2.2.1 diff -u -p -r1.2.2.1 qr_codes.info --- qr_codes.info 13 Jun 2010 21:15:34 -0000 1.2.2.1 +++ qr_codes.info 26 Jun 2010 14:44:10 -0000 @@ -1,4 +1,4 @@ -; $Id: +; $Id$ name = "QR Codes" -description = "This modules allows for the creation of two dimensional (2D) QR barcodes using the Google Charts API." +description = "This modules allows for the creation of two dimensional (2D) QR barcodes." core = "6.x" Index: qr_codes.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/qr_codes/qr_codes.module,v retrieving revision 1.2.2.1 diff -u -p -r1.2.2.1 qr_codes.module --- qr_codes.module 5 May 2010 17:42:35 -0000 1.2.2.1 +++ qr_codes.module 26 Jun 2010 14:44:10 -0000 @@ -1,5 +1,5 @@ MENU_NORMAL_ITEM, + 'title' => 'QR Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('qr_codes_settings'), + 'access arguments' => array('administer qr_codes'), + 'file' => 'qr_codes.admin.inc', + ); + $items['admin/settings/qr_codes/default'] = array( + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'title' => 'Global Settings', + 'access arguments' => array('administer qr_codes'), + ); + + // Build engine tabs. + foreach (module_invoke_all('qr_codes', 'list') as $key => $name) { + list($module, $id) = explode(':', $key, 2); + if (count(module_invoke($module, 'qr_codes', 'config', $id))) { + $items['admin/settings/qr_codes/'. $id] = array( + 'type' => MENU_LOCAL_TASK, + 'title' => $name, + 'page callback' => 'drupal_get_form', + 'page arguments' => array('qr_codes_engine_settings', $module, $id), + 'access arguments' => array('administer qr_codes'), + 'file' => 'qr_codes.admin.inc', + 'weight' => 1, + ); + } + } + + return $items; +} + +/** * Returns the file path of a qr code image * - * @param string $data - * @param string $width - * @param string $height - * @param string $margin - * @param string $attributes + * @param string $data + * @param string $width + * @param string $height + * @param string $margin + * @param string $attributes + * * @return file path */ function qr_codes_generate($data, $width, $height, $margin = 0) { - // create a unique file name using all image attributes + // Create a unique file name using all image attributes. $imagename = md5($data . $width . $height . $margin) .'.png'; $dir = file_directory_path() . '/qr_codes/'; $file = $dir . $imagename; - - // cache locally + + // Cache locally. if (!file_exists($file)) { - if(!file_check_directory($dir, FILE_CREATE_DIRECTORY)){ + if (!file_check_directory($dir, FILE_CREATE_DIRECTORY)) { drupal_set_message(t('Failed to create the qr_codes directory.')); return ''; } - - $url = CHART_URI . sprintf('?cht=qr&chl=%s&chs=%dx%d&chld=%d', $data, $width, $height, $margin); - $image = drupal_http_request($url); - file_save_data($image->data, $file, FILE_EXISTS_REPLACE); + + // Find out which module is handling the image generation. + list($module, ) = explode(':', variable_get('qr_codes_engine', 'qr_codes_google_chart:google_chart'), 2); + + // Invoke the right module for file generation. + module_invoke($module, 'qr_codes', 'generate', $file, $data, $width, $height, $margin); } - + return $file; } /** * Return a themed image tag of a qr code * - * @param string $data - * @param string $width - * @param string $height - * @param string $margin - * @param string $attributes + * @param string $data + * @param string $width + * @param string $height + * @param string $margin + * @param string $attributes * @return image tag */ -function theme_qr_codes($data, $width = 150, $height = 150, $margin = 0, $imagecache_preset = '', $attributes = array()) { +function theme_qr_codes($data, $width = 150, $height = 150, $margin = 0, $alt = '', $title = '', $imagecache_preset = '', $attributes = array()) { $file = qr_codes_generate($data, $width, $height, $margin, $attributes); if (!empty($file)) { if (function_exists('theme_imagecache') && !empty($imagecache_preset)) { - return theme('imagecache', $imagecache_preset, $file); - } else { - return theme('image', $file); + return theme('imagecache', $imagecache_preset, $file, $alt, $title, $attributes); + } + else { + return theme('image', $file, $alt, $title, $attributes); } } } @@ -79,7 +132,7 @@ function qr_codes_block($op = 'list', $d '#title' => t('QR Codes Node Block'), '#collapsible' => FALSE, ); - + $form['qr_codes']['qr_codes_block_data'] = array( '#type' => 'textarea', '#title' => t('Enter the text to embed in your barcode'), @@ -94,18 +147,18 @@ function qr_codes_block($op = 'list', $d '#collapsible' => TRUE, '#collapsed' => TRUE, ); - + $form['qr_codes']['tokens']['help'] = array( '#value' => theme('token_help', 'node'), ); } - + if(function_exists('imagecache_presets')){ $options = array(''); foreach((array)imagecache_presets() as $preset){ $options[$preset['presetname']] = $preset['presetname']; } - + $form['qr_codes']['qr_codes_block_imagecache_preset'] = array( '#type' => 'select', '#title' => t('Select an Imagecache preset'), @@ -114,7 +167,7 @@ function qr_codes_block($op = 'list', $d '#options' => $options, '#default_value' => variable_get('qr_codes_block_imagecache_preset', -1), ); - + } } return $form; @@ -129,7 +182,7 @@ function qr_codes_block($op = 'list', $d case 'view': if ($delta == 0) { $block['subject'] = t('QR Codes'); - + $data = variable_get('qr_codes_block_data', ''); // use token replacement if available for nodes and users @@ -146,8 +199,5 @@ function qr_codes_block($op = 'list', $d } return $block; - } + } } - - -?> \ No newline at end of file Index: qr_codes_google_chart.info =================================================================== RCS file: engines/qr_codes_google_chart.info diff -N qr_codes_google_chart.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ qr_codes_google_chart.info 26 Jun 2010 14:44:10 -0000 @@ -0,0 +1,5 @@ +; $Id$ +name = "QR Codes - Google Chart API" +description = "Implements Google Chart API as engine for builing QR Codes" +core = 6.x +dependencies[] = qr_codes Index: qr_codes_google_chart.module =================================================================== RCS file: engines/qr_codes_google_chart.module diff -N qr_codes_google_chart.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ qr_codes_google_chart.module 26 Jun 2010 14:44:10 -0000 @@ -0,0 +1,30 @@ + t('Google Chart API')); + + case 'description': + return t('Google Chart API. See http://code.google.com/apis/chart/docs/gallery/qr_codes.html'); + + case 'config': + $form['qr_codes_google_chart_url'] = array( + '#type' => 'textfield', + '#title' => t('Google Chart API URI'), + '#description' => t('Enter the URI for the Google Chart API service.'), + '#default_value' => variable_get('qr_codes_google_chart_url', 'http://chart.apis.google.com/chart'), + ); + return $form; + + case 'generate': + $url = variable_get('qr_codes_google_chart_url', 'http://chart.apis.google.com/chart') . sprintf('?cht=qr&chl=%s&chs=%dx%d&chld=%d', $data, $width, $height, $margin); + $image = drupal_http_request($url); + file_save_data($image->data, $a2, FILE_EXISTS_REPLACE); + + } +} \ No newline at end of file