OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxmediaurl.php
Go to the documentation of this file.
1 <?php
2 
7 class oxMediaUrl extends oxI18n
8 {
14  protected $_sClassName = 'oxmediaurls';
15 
19  public function __construct()
20  {
22  $this->init( 'oxmediaurls' );
23  }
24 
30  public function getHtml()
31  {
32  $sUrl = $this->oxmediaurls__oxurl->value;
33  //youtube link
34  if ( strpos( $sUrl, 'youtube.com' ) || strpos( $sUrl, 'youtu.be' ) ) {
35  return $this->_getYoutubeHtml();
36  }
37 
38  //simple link
39  return $this->getHtmlLink();
40  }
41 
49  public function getHtmlLink( $blNewPage = true )
50  {
51  $sForceBlank = $blNewPage ? ' target="_blank"' : '';
52  $sDesc = $this->oxmediaurls__oxdesc->value;
53  $sUrl = $this->getLink();
54 
55  $sHtmlLink = "<a href=\"$sUrl\"{$sForceBlank}>$sDesc</a>";
56 
57  return $sHtmlLink;
58  }
59 
65  public function getLink()
66  {
67  if ( $this->oxmediaurls__oxisuploaded->value ) {
68  $sUrl = $this->getConfig()->isSsl() ? $this->getConfig()->getSslShopUrl() : $this->getConfig()->getShopUrl();
69  $sUrl .= 'out/media/';
70  $sUrl .= basename($this->oxmediaurls__oxurl->value);
71  } else {
72  $sUrl = $this->oxmediaurls__oxurl->value;
73  }
74 
75  return $sUrl;
76  }
77 
83  public function getObjectId()
84  {
85  return $this->oxmediaurls__oxobjectid->value;
86  }
87 
95  public function delete( $sOXID = null )
96  {
97  $sFilePath = $this->getConfig()->getConfigParam('sShopDir') . "/out/media/" .
98  basename($this->oxmediaurls__oxurl->value);
99 
100  if ($this->oxmediaurls__oxisuploaded->value) {
101  if (file_exists($sFilePath)) {
102  unlink($sFilePath);
103  }
104  }
105 
106  return parent::delete( $sOXID );
107  }
108 
114  protected function _getYoutubeHtml()
115  {
116  $sUrl = $this->oxmediaurls__oxurl->value;
117  $sDesc = $this->oxmediaurls__oxdesc->value;
118 
119  if ( strpos( $sUrl, 'youtube.com' ) ) {
120  $sYoutubeUrl = str_replace( "www.youtube.com/watch?v=", "www.youtube.com/embed/", $sUrl );
121  $sYoutubeUrl = preg_replace( '/&amp;/', '?', $sYoutubeUrl, 1 );
122  }
123  if ( strpos( $sUrl, 'youtu.be' ) ) {
124  $sYoutubeUrl = str_replace( "youtu.be/", "www.youtube.com/embed/", $sUrl );
125  }
126 
127  $sYoutubeTemplate = '%s<br><iframe width="425" height="344" src="%s" frameborder="0" allowfullscreen></iframe>';
128  $sYoutubeHtml = sprintf( $sYoutubeTemplate, $sDesc, $sYoutubeUrl, $sYoutubeUrl );
129 
130  return $sYoutubeHtml;
131  }
132 
133 
134 }