Warning, file /webapps/ocs-webserver/application/modules/default/views/helpers/BuildDownloadLink.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Default_View_Helper_BuildDownloadLink extends Zend_View_Helper_Abstract 0024 { 0025 0026 0027 /** 0028 * @param $file pploadFile 0029 * data-link_type: install/download 0030 */ 0031 public function shortFilename($filename) { 0032 $returnString = $filename; 0033 0034 0035 if(strlen($filename)> 25) { 0036 $name = substr($filename,0,22); 0037 0038 $temparray = explode(".",$filename); 0039 0040 $fileExt = end($temparray); 0041 0042 if(strlen($fileExt)> 3) { 0043 $name = substr($name,0,(25-strlen($fileExt))); 0044 } 0045 $returnString = $name .'...'.$fileExt; 0046 } 0047 return $returnString; 0048 } 0049 0050 public function humanFileSize($bytes,$isExternLink=false) { 0051 if($isExternLink) return '----'; 0052 if($bytes>0) 0053 { 0054 $size = ''; 0055 $size = round(($bytes / 1048576),2); 0056 if($size == '0.00') 0057 { 0058 return '0.01 MB'; 0059 }else 0060 { 0061 return $size.' MB'; 0062 } 0063 } 0064 else 0065 { 0066 return '0.00 MB'; 0067 } 0068 } 0069 0070 public function buildDownloadLink($file,$project,$dataLinkType) 0071 { 0072 0073 $link = null; 0074 $isExternLink = false; 0075 if($file['tags']) 0076 { 0077 $tags = explode(',', $file['tags']); 0078 foreach ($tags as $t) { 0079 $tagStr = explode('##',$t); 0080 if(sizeof($tagStr)==2 && $tagStr[0]=='link') 0081 { 0082 $link = $tagStr[1]; 0083 } 0084 } 0085 } 0086 0087 0088 if($link) 0089 { 0090 $isExternLink = true; 0091 } 0092 0093 $downloadUrl = "https://".$_SERVER["SERVER_NAME"]."/p/".$project->project_id 0094 ."/startdownload?file_id=".$file['id'] 0095 ."&file_name=".$file['name'] 0096 ."&file_type=".$file['type'] 0097 ."&file_size=".$file['size']; 0098 0099 0100 $fileShortName = $this->shortFilename($file['name']); 0101 $filesize = $this->humanFileSize($file['size']); 0102 // $fileShortName = $file['name']; 0103 $downloadLink = '<a href="'.$downloadUrl.'" id="data-link-dl'.$file['id'].'" class="opendownloadfile" data-file_id="'.$file['id'] 0104 .'" data-username="'.$project->username 0105 .'" data-file_name="'.$file['name'] 0106 .'" data-file_type="'.$file['type'] 0107 .'" data-file_size="'.$file['size'] 0108 .'" data-project_id="'.$project->project_id 0109 .'" data-link_type="'.$dataLinkType 0110 .'" data-is-external-link="' 0111 .($isExternLink==1?'true':'false') 0112 .'">' 0113 .'<span id="'.$dataLinkType.'"-link-filename'.$file['id'].'" class="downloadlink '.($isExternLink?'isExternal':'').'" >' 0114 .$fileShortName 0115 .($isExternLink?' <i class="fa fa-external-link"></i>':'') 0116 .'</span><span class="downloadlink filesize">'.$filesize 0117 .'</span>' 0118 .'</a>'; 0119 return $downloadLink; 0120 0121 } 0122 }