function mobile_codes_generate in Mobile Codes 5
Same name and namespace in other branches
- 6.2 mobile_codes.module \mobile_codes_generate()
- 6 mobile_codes.module \mobile_codes_generate()
- 7.2 mobile_codes.module \mobile_codes_generate()
Generate a mobile code
2 calls to mobile_codes_generate()
- mobile_codes_field_formatter in ./
mobile_codes.formatter.inc - theme_mobilecode in ./
mobile_codes.module - Theme function for displaying Mobile Codes
File
- ./
mobile_codes.module, line 116 - Mobile Codes core functions
Code
function mobile_codes_generate($data, &$arguments = array()) {
$values = mobile_codes_process_arguments($arguments);
if (($file = mobile_codes_load_mobile_code($data, $arguments)) === FALSE) {
$dir = '/mobile_codes/' . $arguments['preset'];
$file = file_directory_path() . $dir . '/' . time() . rand(1000, 9999) . '.png';
if ($arguments['data'] == 'link' && ($arguments['tinyurl'] == 1 || drupal_strlen($data) > 60)) {
$headers = array(
'Content-type' => 'application/x-www-form-urlencoded',
);
$tinyurl = drupal_http_request('http://tinyurl.com/api-create.php?url=' . urlencode($data), $headers, 'POST', NULL);
if ($tinyurl->code == 200) {
$data = $tinyurl->data;
}
}
$url = 'http://mobilecodes.nokia.com/' . $arguments['type'] . '?' . $values['text']['data'] . '=' . urlencode($data) . '&' . $values['text']['size'] . '=' . $values['size'][$arguments['type']] . '&name=' . $arguments['name'] . $values['text']['margin_encoding'] . '&type=' . $arguments['data'] . '&MODE=' . $values['mode'] . '&a=create';
mobile_codes_directory_check($dir);
$image = drupal_http_request($url);
file_save_data($image->data, $file, FILE_EXISTS_REPLACE);
mobile_codes_save_mobile_code($data, $arguments, $file);
}
return $file;
}