View source
<?php
define('FLASHNODE_TEASER_AND_BODY', 0);
define('FLASHNODE_TEASER_ONLY', 1);
define('FLASHNODE_BODY_ONLY', 2);
define('FLASHNODE_DO_NOT_DISPLAY', 3);
define('FLASHNODE_DEFAULT_HTML_ALT', 'You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialise correctly.');
define('FLASHNODE_DEFAULT_WEIGHT', -0.1);
define('FLASHNODE_DEFAULT_IMPORT_STATUS', 0);
define('FLASHNODE_DEFAULT_PATH', 'flash');
define('FLASHNODE_DEFAULT_EXTENSIONS', 'swf flv mp3');
function flashnode_help($path, $arg) {
switch ($path) {
case 'admin/settings/flashnode':
return '<p>' . t('Flash node lets you create nodes that store a piece of Flash animation. You can use it in a basic mode, where the Flash item is always displayed at the start of the node, or you can enable the flash filter to incorporate Flash content in to other nodes.') . '</p>';
case 'admin/help#flashnode':
$flash_test = '';
if (defined('SWFTOOLS_INSTALLED')) {
$flash_test = '<p>' . theme('flashnode', array(
'filepath' => url(drupal_get_path('module', 'flashnode') . '/flashnode_test_file.swf', array(
'absolute' => TRUE,
)),
'width' => 100,
'height' => 100,
'substitution' => t('<span class="error">If you can see this text instead of an animation then JavaScript insertion failed. Check that your browser has JavaScript enabled, and if it does check your SWF Tools settings.</span>'),
)) . '</p>';
}
return t('
<p>Flash node lets you create nodes that store a piece of <a href="@flash">Flash</a> animation. You can use it in a basic mode, where the Flash item is always displayed at the start of the node, but you can choose whether to have the Flash element displayed in both the teaser and the body, just the teaser, or just the body. You can define the height and width of the Flash element, or you can let the node use the Flash content\'s original settings.</p>
<p>The module also defines a new input filter called <strong>flashnode</strong> that you can use. This lets you re-use Flash content in other nodes by using the format <strong>[flashnode|nid=<nid>]</strong> in the body of a node. You can pass optional parameters to manipulate the display of the Flash content by including them in the macro. Parameters that are used by flash node are as follows:
<ul>
<li>
<strong>width</strong> - set a specific width, in pixels
</li><li>
<strong>height</strong> - set a specific height, in pixels
</li><li>
<strong>scale</strong> - scale both width and height to a multiple of the original size
</li><li>
<strong>xscale</strong> - scale just the width to a multiple of the original size
</li><li>
<strong>yscale</strong> - scale just the height to a multiple of the original size
</li><li>
<strong>scalewidth</strong> - set a specific width, in pixels, and automatically adjust the height to maintain the aspect ratio
</li><li>
<strong>scaleheight</strong> - set a specific height, in pixels, and automatically adjust the width to maintain the aspect ratio
</li><li>
<strong>flashvars</strong> - set a Flashvars string to pass to the Flash movie
</li>
</ul>
For example, to use Flash content from node 10, scaled to 50% of its original size you would use <strong>[flashnode|nid=10|scale=0.5]</strong></p>
<p>You can include other parameters. These will not be interpreted by flash node, but will be passed on to SWF Tools which may choose to use them.</p>
<p>Flash node outputs content using HTML embedding and this allows flash node to work without installing any other modules. Using this basic method will result in the \'Click to activate and use this control\' message under Internet Explorer.</p>
<p>It is recommended to also install <a href="@swftools">SWF Tools</a> as flash node will then use that to output content instead. This lets you take advantage of JavaScript insertion methods. Installing SWF Tools also enables flash node to play back mp3 and flv files via the players that SWF Tools offers. <em>Note - at this time SWF Tools is not available for Drupal 6. Check the SWF Tools project page for the latest information.</em></p>
<p>Flash node will automatically detect SWF Tools when it is installed and content will then be inserted using the method that you specify in the SWF Tools configuration pages. If you have installed SWF Tools and can see an animation playing below then your installation is working properly and you are ready to use flash node with SWF Tools! If you can\'t see it then double check your SWF Tools settings. In particular check that you have downloaded and installed the necessary JavaScript packages. Refer to the SWF Tools documentation for more details.</p>
!flashtest
<p>For more help refer to the <a href="@documentation">flash node documentation</a> on drupal.org.', array(
'@flash' => 'http://www.adobe.com/products/flashplayer',
'@swftools' => 'http://drupal.org/project/swftools',
'@documentation' => 'http://drupal.org/node/214846',
'!flashtest' => $flash_test,
));
}
}
function flashnode_node_info() {
return array(
'flashnode' => array(
'name' => t('Flash'),
'module' => 'flashnode',
'description' => t('Allows you to easily upload and display a Flash file. You can choose whether the movie appears in the teaser, the body, or both.'),
),
);
}
function flashnode_perm() {
return array(
'administer flash node',
'create flash nodes',
'edit own flash nodes',
'edit any flash node',
'delete own flash nodes',
'delete any flash node',
'use display options',
'use basic options',
'use advanced options',
'import flash',
);
}
function flashnode_access($op, $node, $account) {
if ($op == 'create') {
return user_access('create flash nodes', $account);
}
if ($op == 'update') {
if (user_access('edit any flash node', $account) || user_access('edit own flash nodes', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
if ($op == 'delete') {
if (user_access('delete any flash node', $account) || user_access('delete own flash nodes', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
}
function flashnode_menu() {
$items = array();
$items['admin/settings/flashnode'] = array(
'title' => 'Flash node',
'description' => 'Set various flash node default options.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flashnode_admin_settings',
),
'access arguments' => array(
'administer flash node',
),
'file' => 'flashnode.admin.inc',
);
$items['admin/content/flashnode'] = array(
'title' => 'Import Flash',
'description' => 'Import and create nodes from files that have been uploaded directly to the server.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flashnode_import',
),
'access arguments' => array(
'import flash',
),
'file' => 'flashnode.import.inc',
);
return $items;
}
function flashnode_validate(&$node) {
if (!$_FILES['files']['name']['flashfile'] && !$node->flashnode['filepath']) {
form_set_error('flashfile', t('You must upload a file.'));
}
if (!empty($node->flashnode['width']) && !is_numeric($node->flashnode['width'])) {
form_set_error('flashnode][width', t('You must enter a valid width.'));
}
if (!empty($node->flashnode['height']) && !is_numeric($node->flashnode['height'])) {
form_set_error('flashnode][height', t('You must enter a valid height.'));
}
return;
}
function flashnode_form(&$node) {
global $user;
_flashnode_check_settings();
if (!isset($node->flashnode)) {
drupal_set_message('New node');
$node->flashnode = array(
'filepath' => '',
'filename' => '',
'fid' => '',
'display' => variable_get('flashnode_default_display', FLASHNODE_TEASER_AND_BODY),
'width' => '',
'height' => '',
'substitution' => '!default',
'flashvars' => '',
'base' => variable_get('flashnode_default_base', ''),
'params' => '',
);
}
$node->flashnode += array(
'_height' => null,
'_width' => null,
);
$form['#attributes'] = array(
'enctype' => 'multipart/form-data',
);
$form['flashnode']['#tree'] = TRUE;
if (isset($node->new_file)) {
$form['new_file'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
$form['flashnode']['filepath'] = array(
'#type' => 'value',
'#value' => $node->flashnode['filepath'],
);
$form['flashnode']['filename'] = array(
'#type' => 'value',
'#value' => $node->flashnode['filename'],
);
$form['flashnode']['fid'] = array(
'#type' => 'value',
'#value' => $node->flashnode['fid'],
);
$form['flashnode']['_height'] = array(
'#type' => 'value',
'#value' => $node->flashnode['_height'],
);
$form['flashnode']['_width'] = array(
'#type' => 'value',
'#value' => $node->flashnode['_width'],
);
$type = node_get_types('type', $node);
if ($type->has_title) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
}
if ($type->has_body) {
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
}
$form['flashnode']['flashfile'] = array(
'#type' => 'file',
'#title' => t('Flash file'),
'#description' => $node->flashnode['fid'] ? t('Current file is %filename. Click "Browse..." to upload a different file.', array(
'%filename' => basename($node->flashnode['filepath']),
)) : t('Click "Browse..." to select a file to upload.'),
'#tree' => FALSE,
);
$form['flashnode']['basic'] = array(
'#type' => 'fieldset',
'#title' => t('Basic flash node options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
'#access' => user_access('use basic options') || user_access('use display options') || $user->uid == 1,
);
$form['flashnode']['basic']['display'] = array(
'#type' => 'radios',
'#title' => t('Display in'),
'#default_value' => $node->flashnode['display'],
'#options' => array(
FLASHNODE_TEASER_AND_BODY => t('Teaser and body'),
FLASHNODE_TEASER_ONLY => t('Teaser only'),
FLASHNODE_BODY_ONLY => t('Body only'),
FLASHNODE_DO_NOT_DISPLAY => t('Do not display'),
),
'#parents' => array(
'flashnode',
'display',
),
'#access' => user_access('use display options') || $user->uid == 1,
);
$form['flashnode']['basic']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $node->flashnode['width'],
'#size' => 5,
'#maxlength' => 5,
'#description' => t('The width of the movie, in pixels. Leave blank to use the file\'s own settings.'),
'#parents' => array(
'flashnode',
'width',
),
'#access' => user_access('use basic options') || $user->uid == 1,
);
$form['flashnode']['basic']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $node->flashnode['height'],
'#size' => 5,
'#maxlength' => 5,
'#description' => t('The height of the movie, in pixels. Leave blank to use the file\'s own settings.'),
'#parents' => array(
'flashnode',
'height',
),
'#access' => user_access('use basic options') || $user->uid == 1,
);
$form['flashnode']['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced flash node options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
'#access' => user_access('use advanced options') || $user->uid == 1,
);
$form['flashnode']['advanced']['substitution'] = array(
'#type' => 'textarea',
'#title' => t('Substitution content'),
'#rows' => 5,
'#default_value' => $node->flashnode['substitution'],
'#parents' => array(
'flashnode',
'substitution',
),
'#description' => t('If a javascript method is used to embed flash then this is the content that users will see if they are unable to, or choose not to, display the flash content. This content uses the same input format as the body. The default content may be used by entering @default.', array(
'@default' => '!default',
)),
);
$form['flashnode']['advanced']['flashvars'] = array(
'#type' => 'textarea',
'#title' => t('Flashvars'),
'#rows' => 5,
'#default_value' => $node->flashnode['flashvars'],
'#parents' => array(
'flashnode',
'flashvars',
),
'#description' => t('Specify any flashvars that need to be passed to the movie. If the input format allows PHP code you may use PHP to create a dynamic flashvars string.'),
);
$form['flashnode']['advanced']['base'] = array(
'#type' => 'textfield',
'#title' => t('Base'),
'#default_value' => $node->flashnode['base'],
'#parents' => array(
'flashnode',
'base',
),
'#description' => t('Over-ride the default setting with a different base path here if necessary. This setting is needed for movies that use ActionScription functions such as %loadmovie with unqualified paths. Leave blank to let flash node generate a default that points to %defaultbase.', array(
'%loadmovie' => 'loadMovie()',
'%defaultbase' => file_create_url(''),
)),
);
$form['flashnode']['advanced']['params'] = array(
'#type' => 'textfield',
'#title' => t('Parameters'),
'#default_value' => $node->flashnode['params'],
'#parents' => array(
'flashnode',
'params',
),
'#description' => t('An optional list of parameters to pass to the flash player when the file is rendered. Refer to !technote for details of parameters that can be used. Note - this feature requires SWF Tools to be used to embed flash content.', array(
'!technote' => l('Adobe TechNote 12701', 'http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701'),
)),
);
return $form;
}
function flashnode_load(&$node) {
if ($node->vid) {
$result = db_query("SELECT filepath, filename, {flashnode}.* FROM {files} INNER JOIN {flashnode} ON {files}.fid = {flashnode}.fid WHERE {flashnode}.vid = %d", $node->vid);
$data = db_fetch_object($result);
if ($data === FALSE) {
$data = array();
drupal_set_message(t('Unable to load flash node data for node @node.', array(
'@node' => $node->nid,
)), 'error');
}
foreach ($data as $parameter => $value) {
$node->flashnode[$parameter] = $value;
}
if (!$node->flashnode['height']) {
$node->flashnode['height'] = null;
}
if (!$node->flashnode['width']) {
$node->flashnode['width'] = null;
}
}
}
function flashnode_insert($node) {
if (!$node->revision && !$node->flashnode['import']) {
_flashnode_file_move($node);
}
db_query("INSERT INTO {flashnode} (nid, height, width, display, substitution, flashvars, base, fid, vid, params) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, '%s')", $node->nid, $node->flashnode['height'], $node->flashnode['width'], $node->flashnode['display'], $node->flashnode['substitution'], $node->flashnode['flashvars'], $node->flashnode['base'], $node->flashnode['fid'], $node->vid, $node->flashnode['params']);
}
function _flashnode_file_move(&$node) {
$filename = str_replace(' ', '_', $node->flashnode['filename']);
$destination = variable_get('flashnode_default_path', FLASHNODE_DEFAULT_PATH) . '/' . $filename;
file_move($node->flashnode['filepath'], $destination, FILE_EXISTS_RENAME);
db_query("UPDATE {files} SET status = %d, filepath = '%s' WHERE fid = %d", FILE_STATUS_PERMANENT, $node->flashnode['filepath'], $node->flashnode['fid']);
}
function flashnode_update($node) {
if ($node->revision) {
$vid = $node->old_vid;
}
else {
$vid = $node->vid;
}
$old_fid = db_result(db_query("SELECT {flashnode}.fid FROM {flashnode} INNER JOIN {files} ON {flashnode}.fid = {files}.fid WHERE {flashnode}.vid = %d", $vid));
if ($old_fid != $node->flashnode['fid']) {
$new_file = TRUE;
_flashnode_file_move($node);
}
if ($node->revision) {
flashnode_insert($node);
}
else {
if ($new_file) {
_flashnode_delete_file_if_no_longer_needed($old_fid);
}
db_query("UPDATE {flashnode} SET nid = %d, height = %d, width = %d, display = %d, substitution = '%s', flashvars = '%s', base = '%s', fid = %d, params = '%s' WHERE vid = %d", $node->nid, $node->flashnode['height'], $node->flashnode['width'], $node->flashnode['display'], $node->flashnode['substitution'], $node->flashnode['flashvars'], $node->flashnode['base'], $node->flashnode['fid'], $node->flashnode['params'], $node->vid);
db_query("UPDATE {files} SET status = %d, filepath = '%s' WHERE fid = %d", FILE_STATUS_PERMANENT, $node->flashnode['filepath'], $node->flashnode['fid']);
}
}
function flashnode_delete($node) {
$result = db_query("SELECT DISTINCT {files}.* FROM {flashnode} INNER JOIN {files} ON {flashnode}.fid = {files}.fid WHERE {flashnode}.nid = %d", $node->nid);
while ($file = db_fetch_object($result)) {
db_query("DELETE FROM {files} WHERE fid = %d", $file->fid);
file_delete($file->filepath);
}
db_query("DELETE FROM {flashnode} WHERE nid = %d", $node->nid);
}
function flashnode_view($node, $teaser, $page = 0) {
$node = node_prepare($node, $teaser);
$node->flashnode['substitution'] = check_markup($node->flashnode['substitution'], $node->format, FALSE);
$node->flashnode['flashvars'] = _flashnode_php_flashvars($node->flashnode['flashvars'], $node->format);
$flash_content = array(
'#value' => theme('flashnode', $node->flashnode, $teaser),
'#weight' => variable_get('flashnode_weight', FLASHNODE_DEFAULT_WEIGHT),
);
if ($node->flashnode['display'] != FLASHNODE_BODY_ONLY && $node->flashnode['display'] != FLASHNODE_DO_NOT_DISPLAY && $teaser) {
$node->content['flashnode'] = $flash_content;
}
if ($node->flashnode['display'] != FLASHNODE_TEASER_ONLY && $node->flashnode['display'] != FLASHNODE_DO_NOT_DISPLAY && !$teaser) {
$node->content['flashnode'] = $flash_content;
}
return $node;
}
function flashnode_theme() {
return array(
'flashnode' => array(
'arguments' => array(
'flashnode' => NULL,
'teaser' => FALSE,
'options' => array(),
),
),
'flashnode_markup' => array(
'arguments' => array(
'flashnode' => NULL,
'options' => array(),
),
),
'flashnode_import_form' => array(
'arguments' => array(
'form' => NULL,
),
'file' => 'flashnode.import.inc',
),
);
}
function flashnode_content($args = array(), $format = FILTER_FORMAT_DEFAULT) {
if (!is_numeric($args['nid'])) {
$error = t('Incorrectly specified macro - <em>nid</em> not specified, or not numeric.');
}
else {
$node = node_load($args['nid']);
if ($node->type != 'flashnode') {
$error = t('Macro tried to load node @nid which is not a flash node.', array(
'@nid' => $args['nid'],
));
}
}
if ($error) {
watchdog('flashnode', $error, NULL, WATCHDOG_ERROR);
return;
}
$node->flashnode['flashvars'] = _flashnode_php_flashvars($node->flashnode['flashvars'], $node->format);
unset($args['nid']);
$xscale = $yscale = 1;
$options = array();
if ($args) {
foreach ($args as $parameter => $value) {
switch ($parameter) {
case 'scalewidth':
if (is_numeric($value) && $node->flashnode['width'] > 0) {
$xscale = $yscale = $value / $node->flashnode['width'];
}
break;
case 'scaleheight':
if (is_numeric($value) && $node->flashnode['height'] > 0) {
$xscale = $yscale = $value / $node->flashnode['height'];
}
break;
case 'xscale':
if (is_numeric($value)) {
$xscale = $value;
}
break;
case 'yscale':
if (is_numeric($value)) {
$yscale = $value;
}
break;
case 'scale':
if (is_numeric($value)) {
$xscale = $yscale = $value;
}
break;
case 'height':
case 'width':
if (is_numeric($value)) {
$node->flashnode[$parameter] = $value;
}
break;
case 'class':
$node->flashnode['class'] = $value;
break;
case 'flashvars':
$value = str_replace('&', '&', $value);
$node->flashnode['flashvars'] = $value;
$node->flashnode['flashvars'] = _flashnode_php_flashvars($node->flashnode['flashvars'], $format);
break;
case 'substitution':
$node->flashnode['substitution'] = $value;
break;
default:
$options[$parameter] = $value;
}
}
}
$node->flashnode['height'] = $node->flashnode['height'] * $yscale;
$node->flashnode['width'] = $node->flashnode['width'] * $xscale;
$node->flashnode['substitution'] = check_markup($node->flashnode['substitution'], $format, FALSE);
return theme('flashnode', $node->flashnode, FALSE, $options);
}
function flashnode_get_macros($text) {
$m = array();
preg_match_all('/ \\[ ([^\\[\\]]+)* \\] /x', $text, $matches);
$tag_match = (array) array_unique($matches[1]);
foreach ($tag_match as $macro) {
$current_macro = '[' . $macro . ']';
$param = array_map('trim', explode('|', $macro));
$func_name = array_shift($param);
if ($func_name == 'flashnode') {
$vars = array();
foreach ($param as $p) {
$pos = strpos($p, '=');
$varname = substr($p, 0, $pos);
$varvalue = substr($p, $pos + 1);
$vars[$varname] = $varvalue;
}
$m[$current_macro] = $vars;
}
}
return $m;
}
function flashnode_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(
0 => t('Flash node filter'),
);
case 'description':
return t('Add Flash from a flash node to your posts using a flash node macro.');
case 'process':
foreach (flashnode_get_macros($text) as $unexpanded_macro => $macro) {
$replace = flashnode_content($macro, $format);
$search = '@(<p>)?' . preg_quote($unexpanded_macro) . '(</p>)?@';
$text = preg_replace($search, $replace, $text);
}
return $text;
default:
return $text;
}
}
function flashnode_filter_tips($delta, $format, $long = FALSE) {
return t('Flash node macros can be added to this post.');
}
function _flashnode_php_flashvars($flashvars, $format = -1) {
$filters = filter_list_format($format);
foreach ($filters as $filter) {
if ($filter->module == 'php') {
$flashvars = module_invoke($filter->module, 'filter', 'process', $filter->delta, $format, $flashvars);
}
}
$flashvars = check_plain($flashvars);
$flashvars = str_replace('&', '&', $flashvars);
return $flashvars;
}
function _flashnode_check_settings() {
$flashnode_path = file_create_path(variable_get('flashnode_default_path', FLASHNODE_DEFAULT_PATH));
$flashnode_temp_path = $flashnode_path . '/temp';
file_check_directory($flashnode_path, FILE_CREATE_DIRECTORY, 'flashnode_default_path');
file_check_directory($flashnode_temp_path, FILE_CREATE_DIRECTORY);
}
function flashnode_node_form_submit($form, &$form_state) {
global $user;
$limits = _flashnode_file_limits($user);
$validators = array(
'file_validate_size' => array(
$limits['file_size'],
$limits['user_size'],
),
'file_validate_extensions' => array(
$limits['extensions'],
),
);
if ($file = file_save_upload('flashfile', $validators, file_create_path(variable_get('flashnode_default_path', FLASHNODE_DEFAULT_PATH) . '/temp'))) {
$form_state['values']['flashnode']['filepath'] = $file->filepath;
$form_state['values']['flashnode']['filename'] = $file->filename;
$form_state['values']['flashnode']['fid'] = $file->fid;
$form_state['values']['new_file'] = TRUE;
unset($form_state['values']['flashnode']['_height']);
global $user;
if (!user_access('use basic options') && $user->uid != 1) {
unset($form_state['values']['flashnode']['height']);
unset($form_state['values']['flashnode']['width']);
}
if (!preg_match('@swf$@i', $file->filename)) {
drupal_set_message(t('Remember you might have to set the movie size for flv or mp3 files as flash node cannot always automatically determine the player size!'), 'warning');
}
}
if (!$form_state['values']['flashnode']['_height']) {
$info = image_get_info($form_state['values']['flashnode']['filepath']);
$form_state['values']['flashnode']['_height'] = $info['height'];
$form_state['values']['flashnode']['_width'] = $info['width'];
}
if (empty($form_state['values']['flashnode']['width'])) {
$form_state['values']['flashnode']['width'] = $form_state['values']['flashnode']['_width'];
$form_state['rebuild'] = TRUE;
}
if (empty($form_state['values']['flashnode']['height'])) {
$form_state['values']['flashnode']['height'] = $form_state['values']['flashnode']['_height'];
$form_state['rebuild'] = TRUE;
}
}
function flashnode_nodeapi(&$node, $op, $teaser) {
switch ($op) {
case 'delete revision':
if ($node->type == 'flashnode') {
flashnode_delete_revision($node);
}
break;
case 'rss item':
if ($node->type == 'flashnode') {
$link = '<p>' . t('Click <a href="@url">here</a> to view Flash content.', array(
'@url' => url("node/{$node->nid}", array(
'absolute' => TRUE,
)),
)) . '</p>';
$node->body = $node->body . $link;
$node->teaser = $node->teaser . $link;
}
return array();
}
}
function flashnode_delete_revision($node) {
_flashnode_delete_file_if_no_longer_needed($node->flashnode['fid']);
db_query("DELETE FROM {flashnode} WHERE vid = %d", $node->vid);
}
function _flashnode_delete_file_if_no_longer_needed($fid) {
$result = db_result(db_query("SELECT COUNT(fid) FROM {flashnode} WHERE fid = %d", $fid));
if ($result == 1) {
$filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
db_query("DELETE FROM {files} WHERE fid = %d", $fid);
file_delete($filepath);
}
}
function theme_flashnode($flashnode, $teaser = FALSE, $options = array()) {
if ($teaser) {
$max_width = variable_get('flashnode_max_teaser_width', 0);
$max_height = variable_get('flashnode_max_teaser_height', 0);
$teaser_scale = variable_get('flashnode_teaser_scale', 1);
$flashnode['width'] = $flashnode['width'] * $teaser_scale;
$flashnode['height'] = $flashnode['height'] * $teaser_scale;
}
else {
$max_width = variable_get('flashnode_max_width', 0);
$max_height = variable_get('flashnode_max_height', 0);
}
if ($max_width) {
if ($flashnode['width'] > $max_width) {
$scale = $max_width / $flashnode['width'];
$flashnode['width'] = $flashnode['width'] * $scale;
$flashnode['height'] = $flashnode['height'] * $scale;
}
}
if ($max_height) {
if ($flashnode['height'] > $max_height) {
$scale = $max_height / $flashnode['height'];
$flashnode['width'] = $flashnode['width'] * $scale;
$flashnode['height'] = $flashnode['height'] * $scale;
}
}
if (!$flashnode['base']) {
$flashnode['base'] = file_create_url('');
}
$output = theme('flashnode_markup', $flashnode, $options);
return $output;
}
function theme_flashnode_markup($flashnode, $options = array()) {
if (defined('SWFTOOLS_INSTALLED')) {
if (round($flashnode['width'])) {
$params['width'] = round($flashnode['width']);
}
if (round($flashnode['height'])) {
$params['height'] = round($flashnode['height']);
}
$params['base'] = $flashnode['base'];
$params = array_merge($params, flashnode_get_params($flashnode['params']));
$preview = t($flashnode['substitution'], array(
'!default' => variable_get('flashnode_default_html_alt', FLASHNODE_DEFAULT_HTML_ALT),
));
$othervars = array_merge($options, array(
'html_alt' => $preview,
));
$options = array(
'params' => $params,
'flashvars' => $flashnode['flashvars'],
'othervars' => $othervars,
);
$file = $flashnode['filepath'];
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
$file = str_replace(' ', '%20', $file);
}
$output = swf(file_create_url($file), $options);
return $output;
}
static $markup_error_shown = false;
if (preg_match('@flv|mp3$@i', $flashnode['filepath'])) {
if (!$markup_error_shown) {
drupal_set_message(t('Flash node needs <a href="@swftools">SWF Tools</a> in order to play mp3 or flv files.', array(
'@swftools' => 'http://drupal.org/project/swftools',
)), 'warning');
$markup_error_shown = true;
}
return;
}
$filepath = file_create_url($flashnode['filepath']);
$filepath = str_replace($GLOBALS['base_root'], '', $filepath);
$basepath = str_replace($GLOBALS['base_root'], '', $flashnode['base']);
$output = t('<div class="flashnode"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="!width" height="!height" id="myMovieName"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="!filepath" /><param name="quality" value="high" /><param name="flashvars" value="!flashvars" /><param name="base" value="!base" /><embed src="!filepath" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" width="!width" height="!height" flashvars="!flashvars" name="myMovieName" align="" type="application/x-shockwave-flash" base="!base" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>', array(
'!height' => $flashnode['height'],
'!width' => $flashnode['width'],
'!filepath' => $filepath,
'!flashvars' => $flashnode['flashvars'],
'!base' => $basepath,
));
return $output;
}
function _flashnode_file_limits($user) {
$file_limit = variable_get('upload_uploadsize_default', 1);
$user_limit = variable_get('upload_usersize_default', 1);
$flashnode_default_extensions = variable_get('flashnode_default_extensions', FLASHNODE_DEFAULT_EXTENSIONS);
$all_extensions = array();
foreach ($user->roles as $rid => $name) {
$extensions = variable_get("flashnode_extensions_{$rid}", $flashnode_default_extensions);
$all_extensions = array_merge($all_extensions, explode(' ', $extensions));
$file_size = variable_get("upload_uploadsize_{$rid}", variable_get('upload_uploadsize_default', 1)) * 1024 * 1024;
$file_limit = $file_limit && $file_size ? max($file_limit, $file_size) : 0;
$user_size = variable_get("upload_usersize_{$rid}", variable_get('upload_usersize_default', 1)) * 1024 * 1024;
$user_limit = $user_limit && $user_size ? max($user_limit, $user_size) : 0;
}
$all_extensions = implode(' ', array_unique($all_extensions));
return array(
'extensions' => $all_extensions,
'file_size' => $file_limit,
'user_size' => $user_limit,
);
}
function flashnode_file_download($file) {
$file = file_create_path($file);
$result = db_query("SELECT fi.*, fl.nid FROM {files} fi INNER JOIN {flashnode} fl ON fi.fid = fl.fid WHERE filepath = '%s'", $file);
if ($file = db_fetch_object($result)) {
$node = node_load($file->nid);
if (node_access('view', $node)) {
return array(
'Content-Type: ' . $file->filemime,
'Content-Length: ' . $file->filesize,
);
}
else {
return -1;
}
}
}
function flashnode_get_params($parameters_string) {
$params = array();
if ($parameters_string != '') {
foreach (explode(' ', $parameters_string) as $kvpair) {
list($key, $value) = explode('=', $kvpair);
$params[$key] = $value;
}
}
return $params;
}
function flashnode_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'flashnode') . '/views',
);
}