Skip to content

Commit fa6113c

Browse files
committed
Merge branch 'release-1.0'
2 parents 82c5ae4 + 1addee5 commit fa6113c

File tree

3 files changed

+116
-29
lines changed

3 files changed

+116
-29
lines changed

AdLibWS.class.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
define('ADLIB_JOBTYPE_PDF', 0);
99
define('ADLIB_JOBTYPE_HTML', 1);
10-
define('ADLIB_DISABLED', $_SERVER['SERVER_ADDR'] != '10.255.1.46');
11-
//define('ADLIB_DISABLED', TRUE);
10+
define('ADLIB_DISABLED', !variable_get('os2web_adlib_api_is_allowed', 0));
11+
1212

1313
/**
1414
* Description of AdLibWS
@@ -108,7 +108,7 @@ class AdLibWS {
108108
<JOB:SETTINGS>
109109
<JOB:HEADER ENABLED="Yes" TEXTRIGHT="&amp;[Page] of &amp;[Pages]" LAYER="Foreground" />
110110
<JOB:NATIVEAPPSETTINGS>
111-
<JOB:MSOUTLOOK CONVERSIONMODE="IFTS" />
111+
<JOB:MSOUTLOOK CONVERSIONMODE="IFTS" PROCESSATTACHMENTS="No"/>
112112
</JOB:NATIVEAPPSETTINGS>
113113
</JOB:SETTINGS>
114114
</JOB>
@@ -120,7 +120,7 @@ class AdLibWS {
120120
'!outfolder' => self::$basePath . $file_info['out_folder'],
121121
'!jobtype' => ($type == ADLIB_JOBTYPE_HTML ? 'HTML' : 'PDF'),
122122
));
123-
$result = simplexml_load_string($this->client->addJob(array('job_info' => $job_info, 'job_ticket' => $job_ticket))->AddJobResult);
123+
$result = simplexml_load_string($this->client->addJob(array('jobInfo' => $job_info, 'jobTicket' => $job_ticket))->AddJobResult);
124124
if (is_object($result) && isset($result->JobSettings['JobID'])) {
125125
return $result;
126126
}

os2web_adlib_api.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ core = 7.x
1919
; Basic
2020

2121
projects[features][subdir] = "contrib"
22-
projects[features][version] = "2.0-beta1"
22+
projects[features][version] = "2.0-beta2"

os2web_adlib_api.module

Lines changed: 111 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @file
45
* Implements API to convert files to PDF or HTML through AdLib.
@@ -43,6 +44,23 @@ function os2web_adlib_api_menu() {
4344
return $items;
4445
}
4546

47+
/**
48+
* Implements hook_FORM_alter().
49+
*/
50+
function os2web_adlib_api_form_os2web_settings_settings_form_alter(&$form, &$form_state) {
51+
// Adlib API configuration.
52+
53+
$form['os2web_adlib_api_config_group'] = array(
54+
'#type' => 'fieldset',
55+
'#title' => t('AdLib Configuration'),
56+
);
57+
$form['os2web_adlib_api_config_group']['os2web_adlib_api_allowed_ip_host'] = array(
58+
'#type' => 'checkbox',
59+
'#title' => 'Enable AdLib conversion from this site!',
60+
'#default_value' => variable_get('os2web_adlib_api_is_allowed', 0),
61+
);
62+
}
63+
4664
/**
4765
* Ajax callback to update job status.
4866
*
@@ -167,7 +185,7 @@ function _os2web_adlib_api_reprocess_nid($nid, &$context = array()) {
167185

168186
if (isset($node->field_enclosures['und'])) {
169187
foreach ($node->field_enclosures['und'] as $file) {
170-
if (file_exists(drupal_realpath($file['uri'])) && !_os2web_adlib_api_is_file_pdf($file['fid'])) {
188+
if (file_exists(drupal_realpath($file['uri'])) && _os2web_adlib_api_is_filetype_approved($file['fid'])) {
171189
if (os2web_adlib_api_convert_to_pdf($file['fid'])) {
172190
watchdog('adlib_api', 'readded fid to conversion queue:' . $file['fid'], NULL, WATCHDOG_DEBUG);
173191
}
@@ -189,10 +207,22 @@ function os2web_adlib_api_status() {
189207
drupal_goto('admin/config/os2web/adlibstatus');
190208
}
191209
if (isset($_GET['reset'])) {
210+
$file = db_select('os2web_adlib_api_doc_files', 'df')
211+
->fields('df')
212+
->condition('fid', $_GET['reset'])
213+
->execute()
214+
->fetchObject();
215+
192216
$query = db_delete('os2web_adlib_api_doc_files');
193217
$query = $query->condition('fid', $_GET['reset']);
194218
$query->execute();
195-
os2web_adlib_api_convert_to_pdf($_GET['reset']);
219+
220+
if (is_object($file) && !empty($file->did)) {
221+
os2web_adlib_api_convert_to_pdf($_GET['reset'], $file->did);
222+
}
223+
else {
224+
os2web_adlib_api_convert_to_pdf($_GET['reset']);
225+
}
196226
drupal_goto('admin/config/os2web/adlibstatus');
197227
}
198228
if (isset($_GET['process'])) {
@@ -232,7 +262,7 @@ function os2web_adlib_api_status() {
232262
);
233263
}
234264
}
235-
drupal_add_js(drupal_get_path('module', 'os2web_adlib_api') . '/js/os2web_adlib_api.js', 'file');
265+
drupal_add_js(drupal_get_path('module', 'os2web_adlib_api') . '/os2web_adlib_api.js', 'file');
236266
$html = '<h2>Connector information</h2>';
237267
$html .= theme('table', array('header' => $head, 'rows' => $rows));
238268
$head = array('Fid', 'Job-id', 'Status', 'action');
@@ -298,15 +328,15 @@ function os2web_adlib_api_cron() {
298328
_os2web_adlib_api_do_processing();
299329

300330
// Add set up queue for adlib requeueing.
301-
// $queue = DrupalQueue::get('os2web_adlib_reprocess');
302-
// if ($queue->numberOfItems() == 0) {
303-
// $items = _os2web_adlib_api_bulletpoint_nid();
304-
// $chunk_size = max(min((int) sqrt(count($items)), 25), 1);
305-
// $items = array_chunk($items, $chunk_size);
306-
// foreach ($items as $item) {
307-
// $queue->createItem($item);
308-
// }
309-
// }
331+
$queue = DrupalQueue::get('os2web_adlib_reprocess');
332+
if ($queue->numberOfItems() == 0) {
333+
$items = _os2web_adlib_api_bulletpoint_nid();
334+
$chunk_size = max(min((int) sqrt(count($items)), 25), 1);
335+
$items = array_chunk($items, $chunk_size);
336+
foreach ($items as $item) {
337+
$queue->createItem($item);
338+
}
339+
}
310340
}
311341

312342
/**
@@ -380,7 +410,7 @@ function os2web_adlib_api_convert_to_pdf($fid, $docref = NULL) {
380410
// file_delete($file);
381411
return FALSE;
382412
}
383-
if (!_os2web_adlib_api_is_file_pdf($fid)) {
413+
if (_os2web_adlib_api_is_filetype_approved($fid)) {
384414
if (0 === db_query('SELECT fid from {os2web_adlib_api_doc_files} where fid = :fid AND jobtype = :jobtype', array(':fid' => $fid, ':jobtype' => 0))->rowCount()) {
385415
$record = array(
386416
'fid' => $fid,
@@ -417,10 +447,15 @@ function os2web_adlib_api_convert_to_pdf($fid, $docref = NULL) {
417447
* Reference for the file
418448
*
419449
* @return int
420-
* File id
450+
* File id, false if none.
421451
*/
422452
function os2web_adlib_api_get_fid($ref) {
423-
return (int) db_query('SELECT fid FROM {os2web_adlib_api_doc_files} WHERE did=:did', array(':did' => $ref))->fetchField();
453+
454+
$fid = db_query('SELECT fid FROM {os2web_adlib_api_doc_files} WHERE did=:did ORDER BY fid DESC', array(':did' => $ref))->fetchField();
455+
if ($fid) {
456+
return $fid;
457+
}
458+
return false;
424459
}
425460

426461
/**
@@ -443,14 +478,16 @@ function _os2web_adlib_api_get_instance() {
443478
*/
444479
function _os2web_adlib_api_do_processing() {
445480
// Add set up queue for adlib processing.
481+
//
482+
// Disable auto queue of missing files
446483
$queue = DrupalQueue::get('os2web_adlib_process');
447484
if ($queue->numberOfItems() == 0) {
448485
$items = db_select('os2web_adlib_api_doc_files', 'f')
449486
->fields('f')
450487
->condition(db_or()->condition('job_id', 'Complete', '!=')->isNull('job_id'))
451488
->execute()
452489
->fetchAll();
453-
$chunk_size = max(min((int) sqrt(count($items)), 5), 1);
490+
$chunk_size = max(min((int) sqrt(count($items)), 25), 1);
454491
$items = array_chunk($items, $chunk_size);
455492
foreach ($items as $item) {
456493
if ($item->job_id != 'Complete') {
@@ -512,6 +549,7 @@ function _os2web_adlib_api_process_file($file) {
512549
$fdata = file_load($file->fid);
513550
if (!file_exists(drupal_realpath($fdata->uri)) || file_uri_scheme($fdata->uri) == '' || $fdata->filemime == 'application/pdf') {
514551
if ($fdata->filemime == 'application/pdf') {
552+
515553
$record = array(
516554
'fid' => $fdata->fid,
517555
'jobtype' => $fdata->jobtype,
@@ -698,7 +736,7 @@ function _os2web_adlib_api_process_html($data, $base_url) {
698736
function _os2web_adlib_api_queue_file($file) {
699737
$file->file = file_load($file->fid);
700738

701-
if (is_file(drupal_realpath($file->file->uri)) && !_os2web_adlib_api_is_file_pdf($file->file->fid)) {
739+
if (is_file(drupal_realpath($file->file->uri)) && _os2web_adlib_api_is_filetype_approved($file->file->fid)) {
702740
$adlib = _os2web_adlib_api_get_instance();
703741
$upload = $adlib->uploadData($file->file->filename, file_get_contents(drupal_realpath($file->file->uri)));
704742
if ($upload) {
@@ -730,7 +768,7 @@ function _os2web_adlib_api_queue_file($file) {
730768
}
731769
}
732770
else {
733-
if (_os2web_adlib_api_is_file_pdf($file->file->fid)) {
771+
if (!_os2web_adlib_api_is_filetype_approved($file->file->fid)) {
734772
$jobinfo = array(
735773
'fid' => $file->fid,
736774
'jobtype' => $file->jobtype,
@@ -749,27 +787,60 @@ function _os2web_adlib_api_queue_file($file) {
749787
}
750788

751789
/**
752-
* Helper function, check if file is already PDF.
790+
* Helper function, check if file type is correct.
753791
* @access protected
754792
*
755793
* @param int $fid
756794
* File id
757795
*
758-
* @return boolean
759-
* True if file is pdf.
796+
* @return bool
797+
* True if file is approved for processing.
760798
*/
761-
function _os2web_adlib_api_is_file_pdf($fid) {
799+
function _os2web_adlib_api_is_filetype_approved($fid) {
800+
801+
// Filetypes which are approved for processing.
802+
$approved_files = array(
803+
'docx',
804+
'docm',
805+
'doc',
806+
'dotx',
807+
'dotm',
808+
'xps',
809+
'rtf',
810+
'xlsx',
811+
'odt',
812+
'xlsm',
813+
'xlsb',
814+
'xls',
815+
'xltx',
816+
'xltm',
817+
'xlt',
818+
'xps',
819+
'ods',
820+
'wps',
821+
'pptx',
822+
'pptm',
823+
'ppt',
824+
'potx',
825+
'potm',
826+
'ppsx',
827+
'ppsm',
828+
'pps',
829+
'odp',
830+
'msg',
831+
);
832+
762833
if (is_array($fid)) {
763834
$result = array();
764835
$files = file_load_multiple($fid);
765836
foreach ($files as $file) {
766-
$result[$file->fid]['is_pdf'] = strcasecmp(pathinfo($file->filename, PATHINFO_EXTENSION), 'pdf') === 0;
837+
$result[$file->fid]['is_pdf'] = in_array(strtolower(pathinfo(file_load($fid)->filename, PATHINFO_EXTENSION)), $approved_files);
767838
$result[$file->fid]['file'] = $file;
768839
}
769840
return $result;
770841
}
771842
else {
772-
return strcasecmp(pathinfo(file_load($fid)->filename, PATHINFO_EXTENSION), 'pdf') === 0;
843+
return in_array(strtolower(pathinfo(file_load($fid)->filename, PATHINFO_EXTENSION)), $approved_files);
773844
}
774845
}
775846

@@ -819,3 +890,19 @@ function os2web_adlib_api_destroy_job($job_id) {
819890
watchdog('adlib_api', 'Deleted job for %fid', array('%fid' => $job_id));
820891
}
821892
}
893+
894+
/**
895+
* Implements hook_os2web_help().
896+
*/
897+
function os2web_adlib_api_os2web_help($sections) {
898+
899+
// List of content.
900+
$sections['list_of_content'] = t('<a href="#os2web_adlib_api">Adlib file conversion</a><br />');
901+
902+
// Module specific.
903+
$sections['os2web_adlib_api'] = t('<h2 id="os2web_adlib_api">Adlib file conversion:</h2>');
904+
$sections['os2web_adlib_api'] .= t('<p><b>Description:</b><br />Adlib is a file conversion unit on your network. This module is often used to convert misc files to either .html or .pdf files.<br />See the status of the current queue of files at the <a href="@status" target="_blank">adlib status page</a>.<br />You can requeue files for conversion at the <a href="@requeue" target="_blank">requeue page</a>.</p>', array('@status' => url('admin/config/os2web/adlibstatus'), '@requeue' => url('admin/config/os2web/reprocess')));
905+
$sections['os2web_adlib_api'] .= t('<p><b>Configuration:</b><br /> Setup your AdLib server at the <a href="@settings" target="_blank">OS2web Settings Page</a>. Enter the AdLib service endpoint address.</p>', array('@settings' => url('admin/config/os2web/adlibstatus')));
906+
907+
return $sections;
908+
}

0 commit comments

Comments
 (0)