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' ) || strpos( $sUrl, 'youtu.be' ) ) {
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
00083 public function getObjectId()
00084 {
00085 return $this->oxmediaurls__oxobjectid->value;
00086 }
00087
00095 public function delete( $sOXID = null )
00096 {
00097 $sFilePath = $this->getConfig()->getConfigParam('sShopDir') . "/out/media/" .
00098 basename($this->oxmediaurls__oxurl->value);
00099
00100 if ($this->oxmediaurls__oxisuploaded->value) {
00101 if (file_exists($sFilePath)) {
00102 unlink($sFilePath);
00103 }
00104 }
00105
00106 return parent::delete( $sOXID );
00107 }
00108
00114 protected function _getYoutubeHtml()
00115 {
00116 $sUrl = $this->oxmediaurls__oxurl->value;
00117 $sDesc = $this->oxmediaurls__oxdesc->value;
00118
00119 if ( strpos( $sUrl, 'youtube.com' ) ) {
00120 $sYoutubeUrl = str_replace( "www.youtube.com/watch?v=", "www.youtube.com/embed/", $sUrl );
00121 $sYoutubeUrl = preg_replace( '/&/', '?', $sYoutubeUrl, 1 );
00122 }
00123 if ( strpos( $sUrl, 'youtu.be' ) ) {
00124 $sYoutubeUrl = str_replace( "youtu.be/", "www.youtube.com/embed/", $sUrl );
00125 }
00126
00127 $sYoutubeTemplate = '%s<br><iframe width="425" height="344" src="%s" frameborder="0" allowfullscreen></iframe>';
00128 $sYoutubeHtml = sprintf( $sYoutubeTemplate, $sDesc, $sYoutubeUrl, $sYoutubeUrl );
00129
00130 return $sYoutubeHtml;
00131 }
00132
00133
00134 }