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