oxmediaurl.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxMediaUrl extends oxI18n
00008 {
00009 
00015     protected $_sClassName = 'oxmediaurls';
00016 
00020     public function __construct()
00021     {
00022         parent::__construct();
00023         $this->init('oxmediaurls');
00024     }
00025 
00031     public function getHtml()
00032     {
00033         $sUrl = $this->oxmediaurls__oxurl->value;
00034         //youtube link
00035         if (strpos($sUrl, 'youtube.com') || strpos($sUrl, 'youtu.be')) {
00036             return $this->_getYoutubeHtml();
00037         }
00038 
00039         //simple link
00040         return $this->getHtmlLink();
00041     }
00042 
00050     public function getHtmlLink($blNewPage = true)
00051     {
00052         $sForceBlank = $blNewPage ? ' target="_blank"' : '';
00053         $sDesc = $this->oxmediaurls__oxdesc->value;
00054         $sUrl = $this->getLink();
00055 
00056         $sHtmlLink = "<a href=\"$sUrl\"{$sForceBlank}>$sDesc</a>";
00057 
00058         return $sHtmlLink;
00059     }
00060 
00066     public function getLink()
00067     {
00068         if ($this->oxmediaurls__oxisuploaded->value) {
00069             $sUrl = $this->getConfig()->isSsl() ? $this->getConfig()->getSslShopUrl() : $this->getConfig()->getShopUrl();
00070             $sUrl .= 'out/media/';
00071             $sUrl .= basename($this->oxmediaurls__oxurl->value);
00072         } else {
00073             $sUrl = $this->oxmediaurls__oxurl->value;
00074         }
00075 
00076         return $sUrl;
00077     }
00078 
00084     public function getObjectId()
00085     {
00086         return $this->oxmediaurls__oxobjectid->value;
00087     }
00088 
00096     public function delete($sOXID = null)
00097     {
00098         $sFilePath = $this->getConfig()->getConfigParam('sShopDir') . "/out/media/" .
00099                      basename($this->oxmediaurls__oxurl->value);
00100 
00101         if ($this->oxmediaurls__oxisuploaded->value) {
00102             if (file_exists($sFilePath)) {
00103                 unlink($sFilePath);
00104             }
00105         }
00106 
00107         return parent::delete($sOXID);
00108     }
00109 
00115     protected function _getYoutubeHtml()
00116     {
00117         $sUrl = $this->oxmediaurls__oxurl->value;
00118         $sDesc = $this->oxmediaurls__oxdesc->value;
00119 
00120         if (strpos($sUrl, 'youtube.com')) {
00121             $sYoutubeUrl = str_replace("www.youtube.com/watch?v=", "www.youtube.com/embed/", $sUrl);
00122             $sYoutubeUrl = preg_replace('/&amp;/', '?', $sYoutubeUrl, 1);
00123         }
00124         if (strpos($sUrl, 'youtu.be')) {
00125             $sYoutubeUrl = str_replace("youtu.be/", "www.youtube.com/embed/", $sUrl);
00126         }
00127 
00128         $sYoutubeTemplate = '%s<br><iframe width="425" height="344" src="%s" frameborder="0" allowfullscreen></iframe>';
00129         $sYoutubeHtml = sprintf($sYoutubeTemplate, $sDesc, $sYoutubeUrl, $sYoutubeUrl);
00130 
00131         return $sYoutubeHtml;
00132     }
00133 
00134 }