File indexing completed on 2024-12-29 05:24:41

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 
0024 $helperUserRole = new Backend_View_Helper_UserRole();
0025 $userRoleName = $helperUserRole->userRole();
0026 
0027 $fileName = $this->file_name;
0028 $lastIndex = strripos($fileName, '.');
0029 $fileExt = "";
0030 if (!empty($lastIndex)) {
0031     $fileExt = substr($fileName, $lastIndex + 1);
0032 }
0033 $fileExt = strtoupper($fileExt);
0034 $isAppimage = false;
0035 if ($fileExt == 'APPIMAGE') {
0036     $isAppimage = true;
0037 }
0038 
0039 $isExternal = ($this->is_external == "true");
0040 
0041 $hasTorrent = ($this->has_torrent == "true" || $this->has_torrent == "1");
0042 
0043 $link = "";
0044 
0045 if ($isExternal) {
0046     $link = $this->external_link;
0047 }
0048 ?>
0049 <!DOCTYPE html>
0050 <html>
0051 <head>
0052     <title>Download/Install</title>
0053 
0054     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
0055     <link href="tools/spectre/spectre.css" rel="stylesheet" type="text/css"/>
0056     <link href="tools/spectre/spectre-icons.css" rel="stylesheet" type="text/css"/>
0057     <link href="tools/spectre/font-awesome.min.css" rel="stylesheet" type="text/css"/>
0058     <link rel="stylesheet" href="/theme/flatui/css/fontawsome/font-awesome.min.css" crossorigin="anonymous">
0059 
0060     <style>
0061         .btn.btn-lg {
0062             font-size: 1.6rem;
0063             height: 4rem;
0064             padding: .9rem .8rem;
0065         }
0066 
0067         .btn span.icon {
0068             background: url(/images_sys/external_link_blue.png) no-repeat;
0069             background-size: cover;
0070             float: left;
0071             width: 18px;
0072             height: 18px;
0073             margin-right: 5px;
0074         }
0075 
0076         .btn:hover span.icon {
0077             background: url(/images_sys/external_link_white.png) no-repeat;
0078             background-size: cover;
0079             float: left;
0080             width: 18px;
0081             height: 18px;
0082             margin-right: 5px;
0083         }
0084 
0085         .btn {
0086             background-color: #0088d7;
0087             color: #ffffff;
0088         }
0089 
0090         .supporter-section .user figure {
0091             width: 100%;
0092             padding: 0;
0093             margin: 0;
0094         }
0095 
0096         .supporter-section .user figure img {
0097             width: 40px;
0098             border: 1px solid #dbdbdb;
0099             -webkit-border-radius: 999px;
0100             -moz-border-radius: 999px;
0101             border-radius: 999px;
0102             -webkit-background-clip: padding-box;
0103             -moz-background-clip: padding;
0104             background-clip: padding-box;
0105         }
0106 
0107         section.empty {
0108             padding: 0;
0109             padding-top: 8rem;
0110         }
0111     </style>
0112 
0113     <script type="text/javascript">
0114         
0115         function inIframe () {
0116             try {
0117                 return window.self !== window.top;
0118             } catch (e) {
0119                 return true;
0120             }
0121         }
0122         
0123         console.log('In Frame: ' + inIframe());
0124         
0125         if(!inIframe()) {
0126             window.location.href = "<?= "/p/". $this->project_id ?>";
0127         }
0128 
0129         function viewport() {
0130             var e = window
0131                 , a = 'inner';
0132             if (!('innerWidth' in window)) {
0133                 a = 'client';
0134                 e = document.documentElement || document.body;
0135             }
0136             return {width: e[a + 'Width'], height: e[a + 'Height']}
0137         }
0138     </script>
0139 
0140     <?php if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName && $hasTorrent == true) { ?>
0141 
0142         <script src="/theme/flatui/js/lib/webtorrent.min.js"></script>
0143         <script>
0144 
0145             function startDirectDownload() {
0146                 $('#form-download-torrent').hide();
0147                 $('dl_status').hide();
0148                 $('#Form1').show();
0149                 $('#Form1').submit();
0150             }
0151 
0152             $(document).ready(function () {
0153 
0154 
0155                 var client = new WebTorrent();
0156 
0157                 client.on('error', function (err) {
0158                     console.error('ERROR: ' + err.message);
0159                     $('#form-download-torrent').hide();
0160                     $('#Form1').show();
0161                     $('#Form1').submit();
0162 
0163                 });
0164 
0165                 $('#dl_status').hide();
0166                 $('#Form1').hide();
0167 
0168                 function humanSize(bytes) {
0169                     size = (bytes / 1048576).toFixed(2);
0170                     if (size == 0.0) {
0171                         return '0.01 MB';
0172                     } else {
0173                         return size + ' MB';
0174                     }
0175                 }
0176 
0177                 $('#form-download-torrent').on('submit', function (e) {
0178                     e.preventDefault(); // Prevent page refresh
0179 
0180                     console.log('Start Torrent DL');
0181 
0182                     <?php
0183                     $config = Zend_Registry::get('config');
0184                     $torrenturl = $config->torrent->media->downloadurl . "?id=" . $this->file_id . "&lt=torrent";
0185                     ?>
0186 
0187                     var torrentUrl = '<?= $torrenturl ?>';
0188 
0189                     console.log('Url: ' + torrentUrl);
0190                     //log('Adding ' + torrentId)
0191                     var ops = {
0192                         //announce: [String],        // Torrent trackers to use (added to list in .torrent or magnet uri)
0193                         //getAnnounceOpts: Function, // Custom callback to allow sending extra parameters to the tracker
0194                         maxWebConns: 10,              // Max number of simultaneous connections per web seed [default=4]
0195                         path: '/tmp/webtorrent/'    // Folder to download files to (default=`/tmp/webtorrent/`)
0196                         //store: Function            // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API)
0197                     };
0198 
0199                     client.add(torrentUrl, ops, onTorrent);
0200                 });
0201 
0202                 function onTorrent(torrent) {
0203                     console.log('onTorrent...');
0204                     // // Print out progress every 5 seconds
0205                     var rounds = 0;
0206                     var maxRounds = 60;
0207                     var lastVal = 0;
0208 
0209                     $('#torrent_form_div').hide();
0210                     $('#dl_status').show();
0211 
0212                     console.log('Save to Path: ' + torrent.path);
0213                     console.log('Torrent Lenght: ' + torrent.length);
0214                     console.log('Torrent Created: ' + torrent.created);
0215                     console.log('Torrent Created by: ' + torrent.createdBy);
0216 
0217                     var interval = setInterval(function () {
0218                         rounds += 1;
0219 
0220                         /*
0221                         if(rounds > maxRounds && lastVal == (torrent.progress * 100)) {
0222                             clearInterval(interval);
0223                             $('#Form1').show();
0224                             $('#Form1').submit();
0225                             return false;
0226                         }
0227                         */
0228 
0229                         log('Progress: ' + (torrent.progress * 100).toFixed(1) + '%');
0230 
0231                         var $dlProgressBar = $('#data-file-download-progress');
0232                         var $dl_info_downloaded_mb = $('#dl_info_downloaded_mb');
0233                         var $dl_info_downloaded_percent = $('#dl_info_downloaded_percent');
0234                         var $dl_info_peers = $('#dl_info_peers');
0235                         var $dl_info_downloaded_speed = $('#dl_info_downloaded_speed');
0236                         var $dl_info_status = $('#dl_info_status');
0237 
0238                         var progress = (torrent.progress * 100).toFixed(1);
0239                         $dlProgressBar.attr('value', progress);
0240 
0241                         $dl_info_downloaded_mb.html(humanSize(torrent.downloaded));
0242                         $dl_info_downloaded_percent.html(progress);
0243                         $dl_info_peers.html(torrent.numPeers);
0244                         $dl_info_downloaded_speed.html(humanSize(torrent.downloadSpeed));
0245 
0246                     }, 1000);
0247 
0248                     torrent.on('ready', function () {
0249                         console.log('ready')
0250                     });
0251 
0252                     torrent.on('metadata', function () {
0253                         console.log('metadata')
0254                     });
0255 
0256                     torrent.on('infoHash', function () {
0257                         console.log('infoHash')
0258                     });
0259 
0260                     torrent.on('done', function () {
0261                         //log('Progress: 100%');
0262 
0263                         var $dlProgressBar = $('#data-file-download-progress');
0264                         var $dl_info_downloaded_mb = $('#dl_info_downloaded_mb');
0265                         var $dl_info_downloaded_percent = $('#dl_info_downloaded_percent');
0266                         var $dl_info_peers = $('#dl_info_peers');
0267                         var $dl_info_downloaded_speed = $('#dl_info_downloaded_speed');
0268                         var $dl_info_status = $('#dl_info_status');
0269 
0270                         var progress = (torrent.progress * 100).toFixed(1);
0271                         $dlProgressBar.attr('value', progress);
0272 
0273                         $dl_info_downloaded_mb.html(humanSize(torrent.downloaded));
0274                         $dl_info_downloaded_percent.html(progress);
0275                         $dl_info_peers.html(torrent.numPeers);
0276                         $dl_info_downloaded_speed.html(humanSize(torrent.downloadSpeed));
0277 
0278                         console.log('Done');
0279                         log('Progress: 100%');
0280                         clearInterval(interval);
0281                         //$('#dl_status').hide();
0282                     });
0283 
0284                     torrent.on('warning', function (err) {
0285                         console.log('Warning: ' + err)
0286                     });
0287 
0288                     torrent.on('error', function (err) {
0289                         var $dl_info_status = $('#dl_info_status');
0290                         $dl_info_status.html('Error: ' + err);
0291                     });
0292 
0293                     torrent.on('wire', function (wire, addr) {
0294                         console.log('connected to peer with address ' + addr)
0295                     });
0296 
0297                     torrent.on('noPeers', function (announceType) {
0298                         console.log('Warning: no peers found: ' + announceType)
0299                     });
0300 
0301                     torrent.on('upload', function (bytes) {
0302                         console.log('Uploading: ' + bytes)
0303                     });
0304                     /*
0305                     torrent.on('download', function (bytes) {
0306                         console.log('just downloaded: ' + bytes)
0307                         console.log('total downloaded: ' + torrent.downloaded)
0308                         console.log('download speed: ' + torrent.downloadSpeed)
0309                         console.log('progress: ' + torrent.progress)
0310                     })
0311                     */
0312 
0313                     // Render all files into to the page
0314                     torrent.files.forEach(function (file) {
0315 
0316                         console.log('Filename: ' + file.name);
0317                         console.log('Filepath: ' + file.path);
0318                         console.log('Filelength: ' + file.length);
0319 
0320                         //file.appendTo('.log')
0321                         //log('(Blob URLs only work if the file is loaded from a server. "http//localhost" works. "file://" does not.)')
0322                         file.getBlobURL(function (err, url) {
0323                             if (err) {
0324                                 $('#Form1').show();
0325                                 $('#Form1').submit();
0326                                 console.log('Error: ' + err + ', Url: ' + url);
0327                                 return log(err.message);
0328                             }
0329                             //log('File done.')
0330                             //log('<a href="' + url + '">Download full file: ' + file.name + '</a>');
0331                             //window.location.assign(url);
0332 
0333                             console.log('Fileurl: ' + url);
0334 
0335                             var a = document.createElement("a");
0336                             document.body.appendChild(a);
0337                             a.style = "display: none";
0338                             a.href = url;
0339                             a.download = file.name;
0340                             a.click();
0341                             window.URL.revokeObjectURL(url);
0342 
0343                             //parent.jQuery.fancybox.close();
0344                         })
0345                     })
0346                 }
0347 
0348 
0349                 function log(str) {
0350                     $('.log').innerHTML = str;
0351                     console.log(str);
0352                 }
0353             });
0354         </script>
0355 
0356     <?php } ?>
0357 
0358 </head>
0359 
0360 <body style="height: 450px; background-color: #f8f9fa;">
0361 <main id="ads-page">
0362 
0363     <div class="columns" style="background-color: #f8f9fa;">
0364         <div class="col-8 col-md-12 col-xs-12 col-sm-12 column">
0365             <div class="toast toast-success"
0366                  style="margin-bottom: 10px; background-color: #727e96 !important; border-color: #727e96 !important;">
0367                 <?php if ($isExternal) { ?>
0368                     Click button below to follow external link.
0369                 <?php } else {
0370                     if ($this->link_type == 'download') { ?>
0371                         Download prepared successfully, click the button below to start.
0372                     <?php } else { ?>
0373                         Installation prepared successfully, click the button below to start.
0374                     <?php }
0375                 } ?>
0376 
0377             </div>
0378             <section class="empty">
0379                 <h1 class="empty-title"><?= $this->project_title ?></h1>
0380 
0381 
0382                 <div class="empty-action" style="height: 50px;">
0383 
0384                     <?php
0385                     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
0386                         //echo '<a href="'.$this->url.'">Please click here</a>';
0387                         echo '<script>top.location.href = "' . $this->url . '"; parent.jQuery.fancybox.close();</script>';
0388 
0389                     } else {
0390                     ?>
0391 
0392 
0393 
0394                     <?php if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName && $hasTorrent == true) {
0395                         ?>
0396                         <div id="torrent_form_div">
0397                             <form id="form-download-torrent" name="form-download-torrent">
0398                                 <?php if ($this->link_type == 'download') { ?>
0399                                     <button type="submit" value="Continue Download" class="btn btn-success btn-lg"
0400                                             style="margin: 0 0 10px;">Download (<?= $this->file_size_human ?>)
0401                                     </button>
0402                                 <?php } else { ?>
0403                                     <button type="submit" value="Continue Installation" class="btn btn-success btn-lg"
0404                                             style="margin: 0 0 10px;">Install (<?= $this->file_size_human ?>)
0405                                     </button>
0406                                     <p style="margin: 0;">*Install things with <a
0407                                                 href="https://www.opendesktop.org/p/1136805/" target="_NEW"
0408                                                 style="color: #0088d7;text-decoration: underline;">ocs-url</a> or <a
0409                                                 href="https://www.opendesktop.org/p/1175480/" target="_NEW"
0410                                                 style="color: #0088d7;text-decoration: underline;">ocs-store</a>.</p>
0411                                 <?php } ?>
0412 
0413                                 <?php
0414                                 if ($isAppimage) {
0415                                     echo("<p style='margin: 0;'>For Appimages we recommend <a href='https://www.opendesktop.org/p/1228228' target='_NEW' style='color: #0088d7;text-decoration: underline;'>AppImageLauncher</a> for system integration</p>");
0416                                 }
0417                                 ?>
0418 
0419                             </form>
0420                         </div>
0421                         <div class="log" id="dl_status">
0422                             <p>Download-Progress:</p>
0423                             <progress id="data-file-download-progress" max="100" value="0"
0424                                       data-file-upload-progress=""></progress>
0425                             <span id="dl_info_status" style="color: red;"></span>
0426                             <br>
0427                             <span id="dl_info_downloaded_mb">0</span> of <?= $this->file_size_human ?> | <span
0428                                     id="dl_info_downloaded_percent">0</span>%
0429                             <br>
0430                             Peers: <span id="dl_info_peers">0</span> | <span id="dl_info_downloaded_speed">0</span>/s
0431                             <br>
0432                             <a href="#" onclick="startDirectDownload()">Start direct download</a>
0433                         </div>
0434 
0435                         <form id="Form1" name="Form1" action="" method="POST">
0436                             <button type="submit" value="Download" class="btn btn-success btn-lg"
0437                                     style="margin: 0 0 10px;">Download
0438                             </button>
0439                         </form>
0440 
0441                     <?php } else { ?>
0442                     <form id="Form1" name="Form1" action="" method="POST">
0443                         <?php if ($isExternal && $this->link_type == 'download') { ?>
0444                             <button type="submit" value="External Link" class="btn btn-success btn-lg"
0445                                     style="margin: 0 0 10px;">Follow Link (<?= $this->file_size_human ?>) <i
0446                                         class="fa fa-external-link"></i></button>
0447                         <?php } else {
0448                             if ($isExternal && $this->link_type == 'install') { ?>
0449                                 <button type="submit" value="Continue Installation" class="btn btn-success btn-lg"
0450                                         style="margin: 0 0 10px;">Install (<?= $this->file_size_human ?>)
0451                                 </button>
0452                                 <p style="margin: 0;">*Install things with <a
0453                                             href="https://www.opendesktop.org/p/1136805/" target="_NEW"
0454                                             style="color: #0088d7;text-decoration: underline;">ocs-url</a> or <a
0455                                             href="https://www.opendesktop.org/p/1175480/" target="_NEW"
0456                                             style="color: #0088d7;text-decoration: underline;">ocs-store</a>.</p>
0457                             <?php } else {
0458                                 if ($this->link_type == 'download') { ?>
0459                                     <button type="submit" value="Continue Download" class="btn btn-success btn-lg"
0460                                             style="margin: 0 0 10px;">Download (<?= $this->file_size_human ?>)
0461                                     </button>
0462                                 <?php } else { ?>
0463                                     <button type="submit" value="Continue Installation" class="btn btn-success btn-lg"
0464                                             style="margin: 0 0 10px;">Install (<?= $this->file_size_human ?>)
0465                                     </button>
0466                                     <p style="margin: 0;">*Install things with <a
0467                                                 href="https://www.opendesktop.org/p/1136805/" target="_NEW"
0468                                                 style="color: #0088d7;text-decoration: underline;">ocs-url</a> or <a
0469                                                 href="https://www.opendesktop.org/p/1175480/" target="_NEW"
0470                                                 style="color: #0088d7;text-decoration: underline;">ocs-store</a>.</p>
0471                                 <?php }
0472                             }
0473                         } ?>
0474 
0475                         <?php
0476                         if ($isExternal) {
0477                             echo("<p style='margin: 0;'>" . $link . "</p>");
0478                         }
0479                         if ($isAppimage) {
0480                             echo("<p style='margin: 0;'>For Appimages we recommend <a href='https://www.opendesktop.org/p/1228228' target='_NEW' style='color: #0088d7;text-decoration: underline;'>AppImageLauncher</a> for system integration</p>");
0481                         }
0482                         ?>
0483                         <?php } ?>
0484 
0485                         <?php
0486                         }
0487                         ?>
0488 
0489                     </form>
0490 
0491 
0492                 </div>
0493 
0494                 <div class="supporter-section"
0495                      style="<?= ($isExternal ? 'margin-top: 100px;' : 'margin-top: 70px;') ?> font-size:small">
0496                         <span>
0497                             This download is made possible by supporters like
0498                             <div class="user">
0499                                 <a target="_NEW"
0500                                    href="<?php echo $this->buildMemberUrl($this->supporter['username']); ?>"
0501                                    class="tooltipuser" data-tooltip-content="#tooltip_content"
0502                                    data-user="<?= $this->supporter['member_id'] ?>">
0503                                     <figure>
0504                                         <img width=""
0505                                              src="<?php echo $this->Image($this->supporter['profile_image_url'],
0506                                                  array('width' => '200', 'height' => '200', 'crop' => 2)); ?>"/>
0507                                     </figure>
0508                                     <p><?php echo Default_Model_HtmlPurify::purify($this->supporter['username']); ?></p>                                                   
0509                                 </a>
0510                             </div>
0511                         </span>
0512                 </div>
0513 
0514 
0515                 <div class="empty-action" style="height: 100px;">
0516 
0517                     <?php
0518                     $config = Zend_Registry::get('config')->settings->client->default;
0519                     $baseurlStore = $config->baseurl_store;
0520                     $identity = Zend_Auth::getInstance()->getIdentity();
0521                     ?>
0522                     <p style="font-size: 18px; position: absolute; bottom: 0px; width: 100%; left: 0%;">
0523                     <form action="<?= $baseurlStore ?>/support-predefined" method="POST" id="support_form_predefined"
0524                           name="support_form_predefined" target="_parent">
0525                         <input type="hidden" name="section_id" value="<?= $this->section_id ?>">
0526                         <input type="hidden" name="project_id" value="<?= $this->project_id ?>">
0527                         Become a <a onclick="support_form_predefined.submit();" target="_NEW"
0528                                     style="color: #0088d7;text-decoration: underline; cursor: pointer;">Supporter</a>.
0529                     </form>
0530 
0531                     </p>
0532                 </div>
0533             </section>
0534         </div>
0535     </div>
0536 </main>
0537 
0538 </body>
0539 <script>
0540     if (viewport()['width'] < 600 && "<?= $this->is_external ?>" === "true") {
0541         document.body.style = 'height: 500px; background-color: #f8f9fa;';
0542     }
0543 
0544 </script>
0545 </html>
0546