Go to the documentation of this file.00001 <?php
00002
00007 class oxMediaUrl extends oxI18n
00008 {
00014 protected $_sClassName = 'oxmediaurls';
00015
00019 public function __construct()
00020 {
00021 parent::__construct();
00022 $this->init( 'oxmediaurls' );
00023 }
00024
00030 public function getHtml()
00031 {
00032 $sUrl = $this->oxmediaurls__oxurl->value;
00033
00034 if (strpos($sUrl, 'youtube.com')) {
00035 return $this->_getYoutubeHtml();
00036 }
00037
00038
00039 return $this->getHtmlLink();
00040 }
00041
00049 public function getHtmlLink( $blNewPage = true )
00050 {
00051 $sForceBlank = $blNewPage ? ' target="_blank"' : '';
00052 $sDesc = $this->oxmediaurls__oxdesc->value;
00053 $sUrl = $this->getLink();
00054
00055 $sHtmlLink = "<a href=\"$sUrl\"{$sForceBlank}>$sDesc</a>";
00056
00057 return $sHtmlLink;
00058 }
00059
00065 public function getLink()
00066 {
00067 if ( $this->oxmediaurls__oxisuploaded->value ) {
00068 $sUrl = $this->getConfig()->isSsl() ? $this->getConfig()->getSslShopUrl() : $this->getConfig()->getShopUrl();
00069 $sUrl .= 'out/media/';
00070 $sUrl .= basename($this->oxmediaurls__oxurl->value);
00071 } else {
00072 $sUrl = $this->oxmediaurls__oxurl->value;
00073 }
00074
00075 return $sUrl;
00076 }
00077
00085 public function delete( $sOXID = null )
00086 {
00087 $sFilePath = $this->getConfig()->getConfigParam('sShopDir') . "/out/media/" .
00088 basename($this->oxmediaurls__oxurl->value);
00089
00090 if ($this->oxmediaurls__oxisuploaded->value) {
00091 if (file_exists($sFilePath)) {
00092 unlink($sFilePath);
00093 }
00094 }
00095
00096 return parent::delete( $sOXID );
00097 }
00098
00104 protected function _getYoutubeHtml()
00105 {
00106 $sUrl = $this->oxmediaurls__oxurl->value;
00107 $sDesc = $this->oxmediaurls__oxdesc->value;
00108
00109
00110
00111
00112
00113 $sYoutubeUrl = str_replace("www.youtube.com/watch?v=", "www.youtube.com/embed/", $sUrl);
00114 $sYoutubeUrl = preg_replace('/&/', '?', $sYoutubeUrl, 1);
00115
00116 $sYoutubeTemplate = '%s<br><iframe width="425" height="344" src="%s" frameborder="0" allowfullscreen></iframe>';
00117 $sYoutubeHtml = sprintf($sYoutubeTemplate, $sDesc, $sYoutubeUrl, $sYoutubeUrl);
00118
00119 return $sYoutubeHtml;
00120 }
00121
00122 }