function webform2pdf_update_7401 in Webform2PDF 7.4
Rewrite token replacement system to use D7 tokens.
File
- ./
webform2pdf.install, line 324 - Webform2pdf module install/schema hooks.
Code
function webform2pdf_update_7401(&$sandbox) {
// Define replacements.
$patterns = array(
'%username',
'%useremail',
'%uid',
'%date',
'%ip_address',
'%site',
'%nid',
'%title',
'%email_values',
'%submission_url',
'%sid',
'%server[REQUEST_URI]',
'][',
);
$replacements = array(
'[current-user:name]',
'[current-user:mail]',
'[current-user:uid]',
'[submission:date:long]',
'[current-user:ip-address]',
'[site:name]',
'[node:nid]',
'[node:title]',
'[submission:values]',
'[submission:url]',
'[submission:sid]',
'[current-page:url]',
':',
);
$dpatterns = array(
'/%get\\[([^\\]]+)\\]/m',
'/%email\\[([^% \\n\\r\\t]+)?\\]/m',
'/%value\\[([^% \\n\\r\\t]+)?\\]/m',
'/%profile\\[([^\\]]+)\\]/m',
'/\\[submission:values(:(?!nolabel)[a-z_]+)+\\]/m',
'/\\[submission:values(:([a-z_:]+))?:nolabel\\]/m',
'/%label_nl\\[([^% \\n\\r\\t]+)?\\]/m',
'/%label_all\\[([^% \\n\\r\\t]+)?\\]/m',
'/%label_all_nl\\[([^% \\n\\r\\t]+)?\\]/m',
'/%nl\\[([^% \\n\\r\\t]+)?\\]/m',
'/%all\\[([^% \\n\\r\\t]+)?\\]/m',
'/%all_nl\\[([^% \\n\\r\\t]+)?\\]/m',
);
$dreplacements = array(
'[current-page:query:$1]',
'[submission:values:$1]',
'[submission:values:$1:nolabel]',
'[current-user:$1]',
'[submission:values$1:withlabel]',
'[submission:values$1]',
'[submission:nl:$1:withlabel]',
'[submission:all:$1:withlabel]',
'[submission:all-nl:$1:withlabel]',
'[submission:nl:$1:nolabel]',
'[submission:all:$1:nolabel]',
'[submission:all-nl:$1:nolabel]',
);
$limit = variable_get('webform_update_batch_size', 100);
$processed_count = _webform2pdf_update_7401_batch($sandbox, $patterns, $replacements, $dpatterns, $dreplacements, $limit);
// If less than limit was processed, the update process is finished.
if ($processed_count < $limit || $sandbox['progress'] == $sandbox['max']) {
$finished = TRUE;
}
// If there's no max value then there's nothing to update and we're finished.
if (empty($sandbox['max']) || isset($finished)) {
return t('Replaced tokens using [submission:values:x] with [submission:values:x:withlabel].');
}
else {
// Indicate our current progress to the batch update system.
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
}
}