oxmediaurl.php

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         //youtube link
00034         if (strpos($sUrl, 'youtube.com')) {
00035             return $this->_getYoutubeHtml();
00036         }
00037 
00038         //simple link
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         //http://www.youtube.com/watch?v=J0oE3X4cgIc&feature=related
00110         //to
00111         //<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/J0oE3X4cgIc&hl=en"></param><embed src="http://www.youtube.com/v/Fx--jNQYNgA&hl=en" type="application/x-shockwave-flash" width="425" height="344"></embed></object>
00112 
00113         $sYoutubeUrl = str_replace("www.youtube.com/watch?v=", "www.youtube.com/v/", $sUrl);
00114 
00115         $sYoutubeTemplate = '%s<br><object type="application/x-shockwave-flash" data="%s" width="425" height="344"><param name="movie" value="%s"></object>';
00116         $sYoutubeHtml = sprintf($sYoutubeTemplate, $sDesc, $sYoutubeUrl, $sYoutubeUrl);
00117 
00118         return $sYoutubeHtml;
00119     }
00120 
00121 }