| 1 |
<?php |
<?php |
| 2 |
// $Id: attachment.module,v 1.20 2007/08/02 17:38:57 cscsteve Exp $ |
// $Id: attachment.module,v 1.21 2007/11/30 23:07:00 cscsteve Exp $ |
| 3 |
|
|
| 4 |
define(ATTACHMENT_EXTENSION_WHITELIST, variable_get('attachment_text_rename_whitelist', 'jpg jpeg gif png tiff txt html doc xls pdf ppt pps odt mp3 ogg wav wmv mpg')); |
define(ATTACHMENT_EXTENSION_WHITELIST, variable_get('attachment_text_rename_whitelist', 'jpg jpeg gif png tiff txt html doc xls pdf ppt pps odt mp3 ogg wav wmv mpg')); |
| 5 |
|
|
| 58 |
$form['attachments'][$key]['hidden'] = array('#type'=>'checkbox', '#return_value'=>1, '#default_value'=>$attachment['hidden']); |
$form['attachments'][$key]['hidden'] = array('#type'=>'checkbox', '#return_value'=>1, '#default_value'=>$attachment['hidden']); |
| 59 |
$form['attachments'][$key]['title'] = array('#type'=>'textfield', '#size'=>30, '#maxlength'=>255, '#default_value'=>$attachment['title']); |
$form['attachments'][$key]['title'] = array('#type'=>'textfield', '#size'=>30, '#maxlength'=>255, '#default_value'=>$attachment['title']); |
| 60 |
$form['attachments'][$key]['description'] = array('#type'=>'textfield', '#size'=>100, '#maxlength'=>255, '#default_value'=>$attachment['description']); |
$form['attachments'][$key]['description'] = array('#type'=>'textfield', '#size'=>100, '#maxlength'=>255, '#default_value'=>$attachment['description']); |
| 61 |
|
$form['attachments'][$key]['weight'] = array('#type'=>'weight','#default_value'=>$attachment['weight']); |
| 62 |
$form['attachments'][$key]['display'] = array('#type'=>'markup', '#value'=> '<strong>Filename:</strong>'. $attachment['filename'] .'<br /><strong>URL:</strong><span class="attachment-url">'. module_invoke('filemanager', 'url', $attachment['fid'], FALSE, TRUE) .'<br /><strong>Size:</strong>' . format_size($attachment['size']) . '</span>'); |
$form['attachments'][$key]['display'] = array('#type'=>'markup', '#value'=> '<strong>Filename:</strong>'. $attachment['filename'] .'<br /><strong>URL:</strong><span class="attachment-url">'. module_invoke('filemanager', 'url', $attachment['fid'], FALSE, TRUE) .'<br /><strong>Size:</strong>' . format_size($attachment['size']) . '</span>'); |
| 63 |
} |
} |
| 64 |
|
|
| 127 |
if (!$attachment['deleted']) { |
if (!$attachment['deleted']) { |
| 128 |
module_invoke('filemanager', 'promote_working', $attachment['fid']); |
module_invoke('filemanager', 'promote_working', $attachment['fid']); |
| 129 |
if ($attachment['aid']) { |
if ($attachment['aid']) { |
| 130 |
db_query("UPDATE {attachment} SET title='%s', description = '%s', size=%d, hidden='%s' WHERE aid=%d", $attachment['title'], $attachment['description'], $attachment['size'], $attachment['hidden'], $attachment['aid']); |
db_query("UPDATE {attachment} SET title='%s', description = '%s', size=%d, hidden='%s', weight='%d' WHERE aid=%d", $attachment['title'], $attachment['description'], $attachment['size'], $attachment['hidden'], $attachment['weight'], $attachment['aid']); |
| 131 |
} |
} |
| 132 |
else { |
else { |
| 133 |
$aid = db_next_id('{attachment}_aid'); |
$aid = db_next_id('{attachment}_aid'); |
| 134 |
db_query("INSERT INTO {attachment} (aid,title,description,nid,fid,filename,size,hidden) VALUES (%d,'%s','%s',%d,%d,'%s',%d,'%s')", $aid, $attachment['title'],$attachment['description'],$node->nid, $attachment['fid'], $attachment['filename'], $attachment['size'], $attachment['hidden']); |
db_query("INSERT INTO {attachment} (aid,title,description,nid,fid,filename,size,hidden,weight) VALUES (%d,'%s','%s',%d,%d,'%s',%d,'%s',%d)", $aid, $attachment['title'],$attachment['description'],$node->nid, $attachment['fid'], $attachment['filename'], $attachment['size'], $attachment['hidden'], $attachment['weight']); |
| 135 |
} |
} |
| 136 |
} |
} |
| 137 |
else { |
else { |
| 270 |
* Theme the attachment form |
* Theme the attachment form |
| 271 |
*/ |
*/ |
| 272 |
function theme_attachment_form($form) { |
function theme_attachment_form($form) { |
| 273 |
|
_attachments_enable_dragdrop(); |
| 274 |
$output = ''; |
$output = ''; |
| 275 |
$header = array( |
$header = array( |
| 276 |
t('Delete'), |
t('Delete'), |
| 277 |
t('Hidden'), |
t('Hidden'), |
| 278 |
|
t('Weight'), |
| 279 |
t('Title'), |
t('Title'), |
| 280 |
t('Description'), |
t('Description'), |
| 281 |
); |
); |
| 282 |
|
|
| 283 |
$rows = array(); |
$rows = array(); |
| 284 |
|
|
| 285 |
|
$output .= "<ul class='attachment-container'>"; |
| 286 |
foreach (element_children($form) as $key) { |
foreach (element_children($form) as $key) { |
| 287 |
if ($key{0} != 'c') { |
if ($key{0} != 'c') { |
|
$row = array(); |
|
|
$row[0]['data'] = drupal_render($form[$key]['display']); |
|
|
$row[0]['colspan'] = '4'; |
|
|
$rows[] = $row; |
|
| 288 |
$row = array( |
$row = array( |
| 289 |
drupal_render($form[$key]['deleted']), |
drupal_render($form[$key]['deleted']), |
| 290 |
drupal_render($form[$key]['hidden']), |
drupal_render($form[$key]['hidden']), |
| 291 |
|
drupal_render($form[$key]['weight']), |
| 292 |
drupal_render($form[$key]['title']), |
drupal_render($form[$key]['title']), |
| 293 |
drupal_render($form[$key]['description']), |
drupal_render($form[$key]['description']), |
| 294 |
); |
); |
| 295 |
$rows[] = $row; |
$output .= '<li class="attachment-item" id="' . $key . '">' |
| 296 |
|
. '<div class="attachment-display">' |
| 297 |
|
. drupal_render($form[$key]['display']) . "</div>" |
| 298 |
|
. theme('table', $header, array($row)) |
| 299 |
|
. '</li>'; |
| 300 |
} |
} |
| 301 |
} |
} |
| 302 |
|
|
| 303 |
if (count($rows) > 0) { |
$output .= "</ul><div style='clear:both'></div>"; |
|
$output .= theme('table', $header, $rows); |
|
|
} |
|
| 304 |
|
|
| 305 |
$output .= drupal_render($form); |
$output .= drupal_render($form); |
| 306 |
|
|
| 386 |
* Load the attachments for the given node |
* Load the attachments for the given node |
| 387 |
*/ |
*/ |
| 388 |
function attachment_load($node) { |
function attachment_load($node) { |
| 389 |
$result = db_query("SELECT aid, title, description, fid, filename, size, hidden FROM {attachment} WHERE nid = %d", $node->nid); |
$result = db_query("SELECT aid, title, description, fid, filename, size, hidden,weight FROM {attachment} WHERE nid = %d ORDER BY weight ASC,title", $node->nid); |
| 390 |
while ($attachment = db_fetch_array($result)) { |
while ($attachment = db_fetch_array($result)) { |
| 391 |
$attachment['deleted'] = FALSE; |
$attachment['deleted'] = FALSE; |
| 392 |
$attachment['working'] = FALSE; |
$attachment['working'] = FALSE; |
| 456 |
* @} end of addtogroup themeable |
* @} end of addtogroup themeable |
| 457 |
*/ |
*/ |
| 458 |
|
|
| 459 |
|
/** |
| 460 |
|
* includes javascript to enable drag and drop of attachment list to |
| 461 |
|
* rearrange the order of the attachments. requires jquery interface |
| 462 |
|
* module which if absent will fall back on letting user reorder list |
| 463 |
|
* via the weights. |
| 464 |
|
*/ |
| 465 |
|
function _attachments_enable_dragdrop() { |
| 466 |
|
if(module_exists('jquery_interface')) { |
| 467 |
|
jquery_interface_add(); |
| 468 |
|
drupal_add_js( <<<EOT |
| 469 |
|
$(document).ready( |
| 470 |
|
function () { |
| 471 |
|
$('ul.attachment-container').Sortable ( |
| 472 |
|
{ |
| 473 |
|
accept: 'attachment-item', |
| 474 |
|
axis: 'vertically', |
| 475 |
|
opacity: 0.8, |
| 476 |
|
onStop: function() { |
| 477 |
|
//go through list of items and weight them |
| 478 |
|
//by order. |
| 479 |
|
var wt = -10; |
| 480 |
|
$(this).parent().children('li').each( function(){ |
| 481 |
|
var id = $(this).attr('id'); |
| 482 |
|
$('select#edit-attachments-' + id + '-weight').val(wt); |
| 483 |
|
wt++; |
| 484 |
|
}); |
| 485 |
|
} |
| 486 |
|
}); |
| 487 |
|
}); |
| 488 |
|
EOT |
| 489 |
|
, 'inline'); |
| 490 |
|
} |
| 491 |
|
} |