PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Vendor/phpvideotoolkit/adapters/ffmpeg-php/php-reader/src/ID3/Frame/COMR.php

https://github.com/Wargo/reddevil
PHP | 356 lines | 120 code | 39 blank | 197 comment | 7 complexity | 6803ccde8731938440d75977208c31d5 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * PHP Reader Library
  4. *
  5. * Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * - Neither the name of the project workgroup nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * @package php-reader
  32. * @subpackage ID3
  33. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  34. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  35. * @version $Id: COMR.php 75 2008-04-14 23:57:21Z svollbehr $
  36. */
  37. /**#@+ @ignore */
  38. require_once("ID3/Frame.php");
  39. require_once("ID3/Encoding.php");
  40. /**#@-*/
  41. /**
  42. * The <i>Commercial frame</i> enables several competing offers in the same tag
  43. * by bundling all needed information. That makes this frame rather complex but
  44. * it's an easier solution than if one tries to achieve the same result with
  45. * several frames.
  46. *
  47. * There may be more than one commercial frame in a tag, but no two may be
  48. * identical.
  49. *
  50. * @package php-reader
  51. * @subpackage ID3
  52. * @author Sven Vollbehr <svollbehr@gmail.com>
  53. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  54. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  55. * @version $Rev: 75 $
  56. */
  57. final class ID3_Frame_COMR extends ID3_Frame
  58. implements ID3_Encoding
  59. {
  60. /**
  61. * The delivery types.
  62. *
  63. * @var Array
  64. */
  65. public static $types = array
  66. ("Other", "Standard CD album with other songs", "Compressed audio on CD",
  67. "File over the Internet", "Stream over the Internet", "As note sheets",
  68. "As note sheets in a book with other sheets", "Music on other media",
  69. "Non-musical merchandise");
  70. /** @var integer */
  71. private $_encoding = ID3_Encoding::UTF8;
  72. /** @var string */
  73. private $_currency = "EUR";
  74. /** @var string */
  75. private $_price;
  76. /** @var string */
  77. private $_date;
  78. /** @var string */
  79. private $_contact;
  80. /** @var integer */
  81. private $_delivery = 0;
  82. /** @var string */
  83. private $_seller;
  84. /** @var string */
  85. private $_description;
  86. /** @var string */
  87. private $_mimeType = false;
  88. /** @var string */
  89. private $_imageData;
  90. /**
  91. * Constructs the class with given parameters and parses object related data.
  92. *
  93. * @param Reader $reader The reader object.
  94. * @param Array $options The options array.
  95. */
  96. public function __construct($reader = null, &$options = array())
  97. {
  98. parent::__construct($reader, $options);
  99. if ($reader === null)
  100. return;
  101. $this->_encoding = Transform::fromInt8($this->_data[0]);
  102. list($pricing, $this->_data) =
  103. preg_split("/\\x00/", substr($this->_data, 1), 2);
  104. $this->_currency = substr($pricing, 0, 3);
  105. $this->_price = substr($pricing, 3);
  106. $this->_date = substr($this->_data, 0, 8);
  107. list($this->_contact, $this->_data) =
  108. preg_split("/\\x00/", substr($this->_data, 8), 2);
  109. $this->_delivery = Transform::fromInt8($this->_data[0]);
  110. $this->_data = substr($this->_data, 1);
  111. switch ($this->_encoding) {
  112. case self::UTF16:
  113. list ($this->_seller, $this->_description, $this->_data) =
  114. preg_split("/\\x00\\x00/", $this->_data, 3);
  115. $this->_seller = Transform::fromString16($this->_seller);
  116. $this->_description = Transform::fromString16($this->_description);
  117. break;
  118. case self::UTF16BE:
  119. list ($this->_seller, $this->_description, $this->_data) =
  120. preg_split("/\\x00\\x00/", $this->_data, 3);
  121. $this->_seller = Transform::fromString16BE($this->_seller);
  122. $this->_description = Transform::fromString16BE($this->_description);
  123. break;
  124. default:
  125. list ($this->_seller, $this->_description, $this->_data) =
  126. preg_split("/\\x00/", $this->_data, 3);
  127. $this->_seller = Transform::fromString8($this->_seller);
  128. $this->_description = Transform::fromString8($this->_description);
  129. }
  130. if (strlen($this->_data) == 0)
  131. return;
  132. list($this->_mimeType, $this->_imageData) =
  133. preg_split("/\\x00/", $this->_imageData, 2);
  134. }
  135. /**
  136. * Returns the text encoding.
  137. *
  138. * @return integer
  139. */
  140. public function getEncoding() { return $this->_encoding; }
  141. /**
  142. * Sets the text encoding.
  143. *
  144. * @see ID3_Encoding
  145. * @param integer $encoding The text encoding.
  146. */
  147. public function setEncoding($encoding) { $this->_encoding = $encoding; }
  148. /**
  149. * Returns the currency code, encoded according to
  150. * {@link http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/currency_codes/currency_codes_list-1.htm
  151. * ISO 4217} alphabetic currency code.
  152. *
  153. * @return string
  154. */
  155. public function getCurrency() { return $this->_currency; }
  156. /**
  157. * Sets the currency used in transaction, encoded according to
  158. * {@link http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/currency_codes/currency_codes_list-1.htm
  159. * ISO 4217} alphabetic currency code.
  160. *
  161. * @param string $currency The currency code.
  162. */
  163. public function setCurrency($currency) { $this->_currency = $currency; }
  164. /**
  165. * Returns the price as a numerical string using "." as the decimal separator.
  166. *
  167. * In the price string several prices may be concatenated, separated by a "/"
  168. * character, but there may only be one currency of each type.
  169. *
  170. * @return string
  171. */
  172. public function getPrice() { return $this->_price; }
  173. /**
  174. * Sets the price. The price must use "." as the decimal separator and have
  175. * multiple values be separated by a "/" character.
  176. *
  177. * @param string $price The price.
  178. */
  179. public function setPrice($price)
  180. {
  181. $this->_price = $price;
  182. }
  183. /**
  184. * Returns the date as an 8 character date string (YYYYMMDD), describing for
  185. * how long the price is valid.
  186. *
  187. * @return string
  188. */
  189. public function getDate() { return $this->_price; }
  190. /**
  191. * Sets the date describing for how long the price is valid for. The date must
  192. * be an 8 character date string (YYYYMMDD).
  193. *
  194. * @param string $date The date string.
  195. */
  196. public function setDate($date) { $this->_date = $date; }
  197. /**
  198. * Returns the contact URL, with which the user can contact the seller.
  199. *
  200. * @return string
  201. */
  202. public function getContact() { return $this->_contact; }
  203. /**
  204. * Sets the contact URL, with which the user can contact the seller.
  205. *
  206. * @param string $contact The contact URL.
  207. */
  208. public function setContact($contact) { $this->_contact = $contact; }
  209. /**
  210. * Returns the delivery type with whitch the audio was delivered when bought.
  211. *
  212. * @return integer
  213. */
  214. public function getDelivery() { return $this->_delivery; }
  215. /**
  216. * Sets the delivery type with whitch the audio was delivered when bought.
  217. *
  218. * @param integer $delivery The delivery type code.
  219. */
  220. public function setDelivery($delivery) { $this->_delivery = $delivery; }
  221. /**
  222. * Returns the name of the seller.
  223. *
  224. * @return string
  225. */
  226. public function getSeller() { return $this->_seller; }
  227. /**
  228. * Sets the name of the seller using given encoding. The seller text encoding
  229. * must be that of the description text.
  230. *
  231. * @param string $seller The name of the seller.
  232. * @param integer $encoding The text encoding.
  233. */
  234. public function setSeller($seller, $encoding = false)
  235. {
  236. $this->_seller = $seller;
  237. if ($encoding !== false)
  238. $this->_encoding = $encoding;
  239. }
  240. /**
  241. * Returns the short description of the product.
  242. *
  243. * @return string
  244. */
  245. public function getDescription() { return $this->_description; }
  246. /**
  247. * Sets the content description text using given encoding. The description
  248. * encoding must be that of the seller text.
  249. *
  250. * @param string $description The content description text.
  251. * @param integer $encoding The text encoding.
  252. */
  253. public function setDescription($description, $encoding = false)
  254. {
  255. $this->_description = $description;
  256. if ($encoding !== false)
  257. $this->_encoding = $encoding;
  258. }
  259. /**
  260. * Returns the MIME type of the seller's company logo, if attached, or
  261. * <var>false</var> otherwise. Currently only "image/png" and "image/jpeg"
  262. * are allowed.
  263. *
  264. * @return string
  265. */
  266. public function getMimeType() { return $this->_mimeType; }
  267. /**
  268. * Sets the MIME type. Currently only "image/png" and "image/jpeg" are
  269. * allowed. The MIME type is always ISO-8859-1 encoded.
  270. *
  271. * @param string $mimeType The MIME type.
  272. */
  273. public function setMimeType($mimeType) { $this->_mimeType = $mimeType; }
  274. /**
  275. * Returns the embedded image binary data.
  276. *
  277. * @return string
  278. */
  279. public function getData() { return $this->_imageData; }
  280. /**
  281. * Sets the embedded image data.
  282. *
  283. * @param string $imageData The image data.
  284. */
  285. public function setData($imageData) { $this->_imageData = $imageData; }
  286. /**
  287. * Returns the frame raw data.
  288. *
  289. * @return string
  290. */
  291. public function __toString()
  292. {
  293. $data = Transform::toInt8($this->_encoding) . $this->_price . "\0" .
  294. $this->_date . $this->_contact . "\0" .
  295. Transform::toInt8($this->_delivery);
  296. switch ($this->_encoding) {
  297. case self::UTF16:
  298. $data .= Transform::toString16($this->_seller) . "\0\0" .
  299. Transform::toString16($this->_description) . "\0\0";
  300. break;
  301. case self::UTF16BE:
  302. $data .= Transform::toString16BE($this->_seller) . "\0\0";
  303. Transform::toString16($this->_description) . "\0\0";
  304. break;
  305. case self::UTF16LE:
  306. $data .= Transform::toString16LE($this->_seller) . "\0\0";
  307. Transform::toString16($this->_description) . "\0\0";
  308. break;
  309. default:
  310. $data .= $this->_seller . "\0" . $this->_description . "\0";
  311. }
  312. parent::setData
  313. ($data . ($this->_mimeType ?
  314. $this->_mimeType . "\0" . $this->_imageData : 0));
  315. return parent::__toString();
  316. }
  317. }