Download and preview from Google docs directly
Posted: 21 May 2012, 17:25
Hello,
the google docs is a very popular cloud system to managed files (big free disk space, easy use, etc). I modified a little the code in phoca download, and now I can download and preview the files from google docs.
this code find in the /components/com_phocadownload/views/category/tmpl/default_files.php
The code begin in the 24 row (between then //General and //pdtextonly):
and the preview section begin in the //pdfbuttonpreview to //pdfbuttondownload:
I'm not a programmer, possible this code not optimal, but my server is functionally. I hope, I can help for you.
USAGE:
upload a document (e.g. a pdf file to your google docs account)
change this file permission to public (e.g. only link)
click the share... button or menu
copy the share link (e.g. https://docs.google.com/open?id=.................................) to external file link and preview file name fields in the phoca download file section.
WARNING:
this code tested only my system, please make a backup your original default_files.php !!!
Best regards, crishead
the google docs is a very popular cloud system to managed files (big free disk space, easy use, etc). I modified a little the code in phoca download, and now I can download and preview the files from google docs.
this code find in the /components/com_phocadownload/views/category/tmpl/default_files.php
The code begin in the 24 row (between then //General and //pdtextonly):
Code: Select all
// General
$linkDownloadB = '';
$linkDownloadE = '';
if ((int)$v->confirm_license > 0 || $this->tmpl['display_file_view'] == 1) {
$linkDownloadB = '<a href="'. JRoute::_(PhocaDownloadHelperRoute::getFileRoute($v->id, $v->catid,$v->alias, $v->categoryalias, $v->sectionid). $this->tmpl['limitstarturl']).'" >'; // we need pagination to go back
$linkDownloadE ='</a>';
} else {
if ($v->link_external != '' && $v->directlink == 1) {
$linkDownloadB = '<a href="'.$v->link_external.'" target="'.$this->tmpl['download_external_link'].'" >';
$linkDownloadE ='</a>';
//Google docs link
$linkURL = parse_url($v->link_external);
if ($linkURL['host'] == 'docs.google.com') {
$extqueryParts = explode('&', $linkURL['query']);
$extparams = array();
foreach ($extqueryParts as $extparam) {
$extitem = explode('=', $extparam);
$extparams[$extitem[0]] = $extitem[1];
}
if ($extparams['id'] != '') {
$linkDownloadB = '<a href="https://docs.google.com/uc?export=download&id='.$extparams['id'].'">';
$linkDownloadE ='</a>';
}
}
} else {
$linkDownloadB = '<a href="'. JRoute::_(PhocaDownloadHelperRoute::getFileRoute($v->id,$this->category[0]->id,$v->alias, $this->category[0]->alias, $v->sectionid, 'download').$this->tmpl['limitstarturl']).'" >';
$linkDownloadE ='</a>';
}
}
and the preview section begin in the //pdfbuttonpreview to //pdfbuttondownload:
Code: Select all
$pdButtonPreview = '';
if (isset($v->filename_preview) && $v->filename_preview != '') {
$fileExt = PhocaDownloadHelper::getExtension($v->filename_preview);
if ($fileExt == 'pdf' || $fileExt == 'jpeg' || $fileExt == 'jpg' || $fileExt == 'png' || $fileExt == 'gif') {
$filePath = PhocaDownloadHelper::getPathSet('filepreview');
$filePath = str_replace ( '../', JURI::base(true).'/', $filePath['orig_rel_ds']);
$previewLink = $filePath . $v->filename_preview;
$pdButtonPreview .= '<div class="pd-button-preview">';
if ($this->tmpl['preview_popup_window'] == 1) {
$pdButtonPreview .= '<a href="'.$previewLink.'" onclick="'. $this->buttonpr->options.'" >'. JText::_('COM_PHOCADOWNLOAD_PREVIEW').'</a>';
} else {
if ($fileExt == 'pdf') {
// Iframe - modal
$pdButtonPreview .= '<a class="pd-modal-button" href="'.$previewLink.'" rel="'. $this->buttonpr->options.'" >'. JText::_('COM_PHOCADOWNLOAD_PREVIEW').'</a>';
} else {
// Image - modal
$pdButtonPreview .= '<a class="pd-modal-button" href="'.$previewLink.'" rel="'. $this->buttonpr->optionsimg.'" >'. JText::_('COM_PHOCADOWNLOAD_PREVIEW').'</a>';
}
}
$pdButtonPreview .= '</div>';
}
else {
if (stristr($v->filename_preview,'docs.google.com')) {
$linkURL = parse_url($v->filename_preview);
$extqueryParts = explode('&', $linkURL['query']);
$extparams = array();
foreach ($extqueryParts as $extparam) {
$extitem = explode('=', $extparam);
$extparams[$extitem[0]] = $extitem[1];
}
if ($extparams['id'] != '') {
$previewLink = "https://docs.google.com/viewer?authuser=0&srcid=".$extparams['id']."&pid=explorer&a=v&chrome=false&embedded=true";
$pdButtonPreview .= '<div class="pd-button-preview">';
// Iframe - modal
$pdButtonPreview .= '<a class="pd-modal-button" href="'.$previewLink.'" rel="'. $this->buttonpr->options.'" >'. JText::_('COM_PHOCADOWNLOAD_PREVIEW').'</a>';
$pdButtonPreview .= '</div>';
}
}
}
}
USAGE:
upload a document (e.g. a pdf file to your google docs account)
change this file permission to public (e.g. only link)
click the share... button or menu
copy the share link (e.g. https://docs.google.com/open?id=.................................) to external file link and preview file name fields in the phoca download file section.
WARNING:
this code tested only my system, please make a backup your original default_files.php !!!
Best regards, crishead