View source
<?php
function sheetnode_phpexcel_views_api() {
return array(
'api' => 2,
);
}
function sheetnode_phpexcel_sheetnode_phpexcel_plugins() {
return array(
'xls' => array(
'content-type' => 'application/vnd.ms-excel',
'php-excel-type' => 'Excel5',
'input' => TRUE,
'output' => TRUE,
'short-name' => t('XLS'),
'long-name' => t('Microsoft Excel 5 (XLS)'),
),
'xlsx' => array(
'content-type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'php-excel-type' => 'Excel2007',
'input' => TRUE,
'output' => TRUE,
'short-name' => t('XLSX'),
'long-name' => t('Microsoft Excel 2007 (XLSX)'),
),
'ods' => array(
'content-type' => 'application/vnd.oasis.opendocument.spreadsheet',
'php-excel-type' => 'OOCalc',
'input' => TRUE,
'output' => FALSE,
'short-name' => t('ODS'),
'long-name' => t('OpenOffice.org Calc (ODS)'),
),
'pdf' => array(
'content-type' => 'application/pdf',
'php-excel-type' => 'PDF',
'input' => FALSE,
'output' => TRUE,
'short-name' => t('PDF'),
'long-name' => t('Adobe Acrobat (PDF)'),
),
);
}
function sheetnode_phpexcel_get_plugins($dir = 'all') {
$plugins = module_invoke_all('sheetnode_phpexcel_plugins');
if ($dir != 'all') {
foreach ($plugins as $format => $plugin) {
if (empty($plugin[$dir])) {
unset($plugins[$format]);
}
}
}
return $plugins;
}
function sheetnode_phpexcel_link($type, $node = NULL, $teaser = FALSE) {
if ($type != 'node' || $node->type != 'sheetnode') {
return array();
}
foreach (sheetnode_phpexcel_get_plugins('output') as $format => $plugin) {
$links[$format] = array(
'title' => t('Save as !format', array(
'!format' => $plugin['short-name'],
)),
'href' => "sheetnode/{$format}/{$node->nid}",
);
}
return $links;
}
require_once drupal_get_path('module', 'sheetnode_phpexcel') . '/sheetnode_phpexcel.export.inc';
require_once drupal_get_path('module', 'sheetnode_phpexcel') . '/sheetnode_phpexcel.import.inc';
function sheetnode_phpexcel_menu($may_cache) {
$items = array();
if ($may_cache) {
foreach (sheetnode_phpexcel_get_plugins('output') as $format => $plugin) {
$items[] = array(
'path' => "sheetnode/{$format}",
'title' => t('Save as !format', array(
'!format' => $plugin['short-name'],
)),
'access' => user_access('access content'),
'callback' => '_sheetnode_phpexcel_export',
'callback arguments' => array(
$format,
),
'type' => MENU_CALLBACK,
);
}
foreach (sheetnode_phpexcel_get_plugins('input') as $format => $plugin) {
$items[] = array(
'path' => "node/add/{$format}",
'title' => t('Sheetnode import from !format', array(
'!format' => $plugin['short-name'],
)),
'access' => user_access('create sheetnode'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'_sheetnode_phpexcel_import_form',
$format,
),
'description' => t('Create a new sheetnode with content from an existing spreadsheet.'),
);
}
$items[] = array(
'path' => 'admin/settings/sheetnode/phpexcel',
'title' => t('PHPExcel'),
'access' => user_access('administer site configuration'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'_sheetnode_phpexcel_settings',
),
'description' => t('Administer settings for Sheetnode PHPExcel.'),
'type' => MENU_LOCAL_TASK,
);
}
return $items;
}
function _sheetnode_phpexcel_settings() {
$form['sheetnode_phpexcel_library_path'] = array(
'#type' => 'textfield',
'#title' => t('PHPExcel path'),
'#description' => t('Enter the location of the extracted PHPExcel package.'),
'#default_value' => variable_get('sheetnode_phpexcel_library_path', ''),
);
return system_settings_form($form);
}
function _sheetnode_phpexcel_settings_validate($form, $form_values) {
$path = rtrim($form_values['sheetnode_phpexcel_library_path'], '/');
if (!is_dir($path) || !is_file($path . '/Classes/PHPExcel.php')) {
form_set_error('sheetnode_phpexcel_library_path', t('The path you entered does not point to a valid location. Please enter the location of the extracted PHPExcel package.'));
return;
}
}