View source
<?php
function _asset_include() {
if (module_exists('views')) {
require_once drupal_get_path('module', 'asset') . '/inc/asset_views.inc';
}
$files = drupal_system_listing('asset_.*\\.inc$', drupal_get_path('module', 'asset') . '/inc/modules', 'name', 0);
foreach ($files as $file) {
$module = substr_replace($file->name, '', 0, 6);
if (module_exists($module)) {
require_once $file->filename;
}
}
}
function asset_formatter_options($type = '*', $filename = null) {
$pos = strrpos($filename, '.');
if ($pos === false) {
$ext = $filename;
}
else {
$ext = substr($filename, $pos + 1);
}
$formatters = asset_get_formatters();
$options = array();
if (is_array($formatters[$type][$ext])) {
foreach ($formatters[$type][$ext] as $formatter) {
$options[$formatter['module'] . ':' . $formatter['format']] = $formatter['name'];
}
}
if (is_array($formatters[$type]['*'])) {
foreach ($formatters[$type]['*'] as $formatter) {
$options[$formatter['module'] . ':' . $formatter['format']] = $formatter['name'];
}
}
if (is_array($formatters['*']['*'])) {
foreach ($formatters['*']['*'] as $formatter) {
$options[$formatter['module'] . ':' . $formatter['format']] = $formatter['name'];
}
}
return $options;
}
function asset_get_default_formatter($type, $ext, $teaser = FALSE) {
$prefix = 'asset_default_formatter_' . ($teaser ? 'teaser_' : '');
$vars = array(
$prefix . $type . '_' . $ext,
$prefix . $type . '_*',
$prefix . '*_*',
);
foreach ($vars as $var) {
if ($formatter = variable_get($var, false)) {
break;
}
}
if (!$formatter) {
$formatters = asset_get_formatters();
if (isset($formatters[$type][$ext][0])) {
$format = $formatters[$type][$ext][0];
}
elseif (isset($formatters[$type]['*'][0])) {
$format = $formatters[$type]['*'][0];
}
else {
$format = $formatters['*']['*'][0];
}
$formatter = $format['module'] . ':' . $format['format'];
}
return $formatter;
}
function asset_img_output($src) {
ob_end_clean();
$mimes = array(
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/x-png',
);
$info = pathinfo($src);
if (!$mimes[$info['extension']]) {
return drupal_not_found();
}
header('Content-type: ' . $mimes[$info['extension']]);
if ($fd = fopen($src, 'rb')) {
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($fd);
}
else {
drupal_not_found();
}
exit;
}
function asset_check_directory(&$directory, $mode = 0, $form_item = NULL, $form_values = array()) {
$return = file_check_directory(file_create_path($directory), $mode, $form_item);
if ($return && $mode && !empty($form_values)) {
$asset = asset_load(array(
'dirname' => $form_values['parent'],
'filename' => $form_values['title'],
));
if (!$asset) {
$asset = new stdClass();
$asset->filepath = $directory;
$asset->filesize = 0;
$asset->type = 'directory';
asset_save($asset, $form_values);
}
}
return $return;
}
function asset_build_query($data) {
foreach ($data as $k => $v) {
$items[] = "{$k}={$v}";
}
return join('&', $items);
}
function asset_pathinfo($path) {
$path = trim(str_replace(file_directory_path(), '', $path), '/');
$info = pathinfo($path);
if ($info['dirname'] == '.') {
$info['dirname'] = '';
}
return $info;
}