File indexing completed on 2025-02-09 07:14:35
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_Model_DbTable_Video extends Zend_Db_Table_Abstract 0024 { 0025 protected $_name = "ppload.ppload_file_preview"; 0026 protected $_key = 'id'; 0027 0028 0029 0030 public static $VIDE_FILE_TYPES = array('video/3gpp','video/3gpp2','video/mpeg','video/quicktime','video/x-flv','video/webm','application/ogg','video/x-ms-asf','video/x-matroska'); 0031 0032 /** 0033 * Configuration for HTTP-Client 0034 * 0035 * @var array 0036 */ 0037 protected $_config = array( 0038 'maxredirects' => 0, 0039 'timeout' => 21600 0040 ); 0041 0042 protected $_allowed = array( 0043 'video/3gpp' => '.3gp', 0044 'video/3gpp2' => '.3g2', 0045 'video/mpeg' => '.mpeg', 0046 'video/quicktime' => '.mov', 0047 'video/x-flv' => '.flv', 0048 'video/webm' => '.webm', 0049 'application/ogg' => '.ogv', 0050 'video/x-matroska' => '.mkv', 0051 'video/mp4' => '.mp4' 0052 ); 0053 protected $_allowedFileExtension = array( 0054 '3gp', 0055 '3g2', 0056 'mpeg', 0057 'mov', 0058 'flv', 0059 'webm', 0060 'ogv', 0061 'mkv', 0062 'mp4' 0063 ); 0064 protected $_errorMsg = null; 0065 0066 /** 0067 * @param string $url 0068 * @param string $authCode 0069 * 0070 * @return bool 0071 * @throws Zend_Exception 0072 * @throws Zend_Http_Client_Exception 0073 * @throws Zend_Uri_Exception 0074 */ 0075 public function storeExternalVideo($collectionId, $fileType, $url) 0076 { 0077 if (true == empty($url)) { 0078 return false; 0079 } 0080 0081 $httpClient = $this->getHttpClient(); 0082 0083 $config = Zend_Registry::get('config'); 0084 $skipConvert = false; 0085 if($fileType == 'video/mp4') { 0086 $skipConvert = true; 0087 } 0088 $videourl = $config->videos->media->upload . "?url=".urlencode($url)."&collection_id=".$collectionId."&skip_convert=".$skipConvert; 0089 0090 $uri = $this->generateUri($videourl); 0091 0092 $httpClient->setUri($uri); 0093 $response = $this->retrieveBody($httpClient); 0094 if (false === $response) { 0095 Zend_Registry::get('logger')->err(__METHOD__ . " - Error while converting Video: " . $uri 0096 . ".\n Server replay was: " . $httpClient->getLastResponse()->getStatus() . ". " . $httpClient->getLastResponse() 0097 ->getMessage() 0098 . PHP_EOL) 0099 ; 0100 0101 return false; 0102 } 0103 0104 Zend_Registry::get('logger')->debug(__METHOD__ . ' Result: ' . print_r($response, true)); 0105 0106 return $response; 0107 } 0108 0109 /** 0110 * @return Zend_Http_Client 0111 * @throws Zend_Http_Client_Exception 0112 */ 0113 public function getHttpClient() 0114 { 0115 $httpClient = new Zend_Http_Client(); 0116 $httpClient->setConfig($this->_config); 0117 0118 return $httpClient; 0119 } 0120 0121 /** 0122 * @param $url 0123 * 0124 * @return Zend_Uri 0125 * @throws Zend_Uri_Exception 0126 */ 0127 protected function generateUri($url) 0128 { 0129 $uri = Zend_Uri::factory($url); 0130 0131 return $uri; 0132 } 0133 0134 /** 0135 * @param Zend_Http_Client $httpClient 0136 * 0137 * @return bool 0138 * @throws Zend_Http_Client_Exception 0139 */ 0140 public function retrieveBody($httpClient) 0141 { 0142 $response = $httpClient->request(); 0143 0144 if ($response->isError()) { 0145 return false; 0146 } else { 0147 return $response->getBody(); 0148 } 0149 } 0150 0151 public function getNewId() 0152 { 0153 $result = $this->getAdapter()->query('SELECT UUID_SHORT()')->fetch(); 0154 0155 return $result['UUID_SHORT()']; 0156 } 0157 0158 }