JOOMSUITE: how to add SEF to file downloads

I finally managed to finish my SEF-related hacks on joomsuite for joomla in order to add SEF url support to the filw downloads.
You need to edit 3 files and add url rewrite rules.
/components/com_resource/controller.php:335 (download function)

$fn = basename($res->field_value);
if (JRequest::getInt('timestamp')==1){
  $a = explode('_', $fn, 2);
  $fn = $a[1];
}
if($browser=='IE') {
  header('Content-Disposition: attachment; filename="'.$fn.'"');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
} else {
  header('Content-Disposition: attachment; filename="'.$fn.'"');
  header('Cache-Control: no-cache, must-revalidate');
  header('Pragma: no-cache');
}

./components/com_resource/controller.php:450 (download2 function, after adding above code)

$fn = basename($res->field_value);
if (JRequest::getInt('timestamp')==1){
  $a = explode('_', $fn, 2);
  $fn = $a[1];
}
if($browser=='IE') {
  header('Content-Disposition: attachment; filename="'.$fn.'"');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
} else {
  header('Content-Disposition: attachment; filename="'.$fn.'"');
  header('Cache-Control: no-cache, must-revalidate');
  header('Pragma: no-cache');
}

./components/com_resource/controllers/article.php:778 (download_attachment function)

$fn = basename($comment->attachmente);
if (JRequest::getInt('timestamp')){
  $a = explode('_', $fn, 2);
  $fn = $a[1];
}
if($browser=='IE') {
  header('Content-Disposition: attachment; filename="'.$fn.'"');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
} else {
  header('Content-Disposition: attachment; filename="'.$fn.'"');
  header('Cache-Control: no-cache, must-revalidate');
  header('Pragma: no-cache');
}

./plugins/joomsuite_content_fields/file.php:179 (onRenderFieldValue function)

if($params->get('show_name'))
{
  // Ciuly - make it SEF
  if (JROUTER_MODE_SEF)
    $download = JURI::base()."download.php/$field->id/";

  $label = basename($field->field_value);
  // Ciuly - remove timestamp from display
  if ($params->get('attach')){
    $a = explode('_', $label, 2);
    $label = $a[1];
    if (JROUTER_MODE_SEF)
      $download = $download . "1/";
    else
      $download = $download . "×tamp=1";
  } else
    if (JROUTER_MODE_SEF)
      $download = $download . "0/";
  if (JROUTER_MODE_SEF)
    $download = $download . $label;
}
else {
  $label = $field->title;
}

and finally, url rewrite:

    RewriteEngine on
    RewriteRule ^/download.php/([0-9]+)/([0-1])/.*$ /index2.php?option=com_resource&task=download&no_html=1&file=$1×tamp=$2

Related posts

Tags: ,

Leave a Reply

This blog is kept spam free by WP-SpamFree.