Example #1
0
 /**
  * Generates HTML contents Video.
  *
  * @param object $oData
  * @param string $sMedia Type of the media ('preview' or 'movie'). Default value is 'movie'.
  * @param integer $iWidth Default 600
  * @param integer $iHeight Default 400
  * @return void
  */
 public static function generate($oData, $sMedia = 'movie', $iWidth = 600, $iHeight = 400)
 {
     $sDurationTag = '<div class="video_duration">' . Various::secToTime($oData->duration) . '</div>';
     if ((new VideoCore())->isApi($oData->file)) {
         $oVideo = (new Api())->getMeta($oData->file, $sMedia, $iWidth, $iHeight);
         if ($sMedia == 'preview') {
             echo $sDurationTag, '<a href="', $oData->file, '" title="', $oData->title, '" data-popup="frame-video"><img src="', $oVideo, '" alt="', $oData->title, '" title="', $oData->title, '" /></a>';
         } else {
             echo $oVideo;
         }
     } else {
         $sDir = 'video/file/' . $oData->username . PH7_SH . $oData->albumId . PH7_SH;
         $sVidPath1 = $sDir . $oData->file . '.webm';
         $sVidPath2 = $sDir . $oData->file . '.mp4';
         // If the video is not found on the server, we show a video that shows an appropriate message.
         if (!(is_file(PH7_PATH_PUBLIC_DATA_SYS_MOD . $sVidPath1) && is_file(PH7_PATH_PUBLIC_DATA_SYS_MOD . $sVidPath2))) {
             $sVidPath1 = PH7_URL_DATA_SYS_MOD . 'video/not_found.webm';
             $sVidPath2 = PH7_URL_DATA_SYS_MOD . 'video/not_found.mp4';
         }
         if (is_file(PH7_PATH_PUBLIC_DATA_SYS_MOD . $sDir . $oData->thumb)) {
             $oFile = new File();
             $sThumbName = $oFile->getFileWithoutExt($oData->thumb);
             $sThumbExt = $oFile->getFileExt($oData->thumb);
             unset($oFile);
             $aThumb = ['', '-1', '-2', '-3', '-4'];
             shuffle($aThumb);
             $sThumbUrl = PH7_URL_DATA_SYS_MOD . $sDir . $sThumbName . $aThumb[0] . PH7_DOT . $sThumbExt;
         } else {
             $sThumbUrl = PH7_URL_TPL . PH7_TPL_NAME . PH7_SH . PH7_IMG . 'icon/none.jpg';
         }
         $sParam = $sMedia == 'movie' && DbConfig::getSetting('autoplayVideo') ? 'autoplay="autoplay"' : '';
         $sVideoTag = '
         <video poster="' . $sThumbUrl . '" width="' . $iWidth . '" height="' . $iHeight . '" controls="controls" ' . $sParam . '>
             <source src="' . PH7_URL_DATA_SYS_MOD . $sVidPath1 . '" type="video/webm" />
             <source src="' . PH7_URL_DATA_SYS_MOD . $sVidPath2 . '" type="video/mp4" />
             ' . t('Your browser is obsolete. Please use a browser that supports HTML5.') . '
         </video>
         <div class="center">
             <button class="bold" onclick="Video.playPause()">' . t('Play/Pause') . '</button>
             <button onclick="Video.bigSize()">' . t('Big') . '</button>
             <button onclick="Video.normalSize()">' . t('Normal') . '</button>
             <button onclick="Video.smallSize()">' . t('Small') . '</button>
         </div>';
         if ($sMedia == 'preview') {
             echo $sDurationTag, '<a href="#watch', $oData->videoId, '" title="', $oData->title, '" data-popup="video"><img src="', $sThumbUrl, '" alt="', $oData->title, '" title="', $oData->title, '" /></a>
             <div class="hidden"><div id="watch', $oData->videoId, '">', $sVideoTag, '</div></div>';
         } else {
             echo $sVideoTag;
         }
     }
 }
 /**
  * Delete the avatar (image) and track database.
  *
  * @param integer $iProfileId
  * @param string $sUsername
  * @return void
  */
 public function deleteAvatar($iProfileId, $sUsername)
 {
     // We start to delete the file before the data in the database if we could not delete the file since we would have lost the link to the file found in the database.
     $sGetAvatar = (new UserCoreModel())->getAvatar($iProfileId, null);
     $sFile = $sGetAvatar->pic;
     $oFile = new File();
     $sExt = PH7_DOT . $oFile->getFileExt($sFile);
     $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'user/avatar/img/' . $sUsername . PH7_SH;
     /** Array to the new format (>= PHP5.4) **/
     $aFiles = [$sPath . $sFile, $sPath . str_replace($sExt, '-32' . $sExt, $sFile), $sPath . str_replace($sExt, '-64' . $sExt, $sFile), $sPath . str_replace($sExt, '-100' . $sExt, $sFile), $sPath . str_replace($sExt, '-150' . $sExt, $sFile), $sPath . str_replace($sExt, '-200' . $sExt, $sFile), $sPath . str_replace($sExt, '-400' . $sExt, $sFile)];
     $oFile->deleteFile($aFiles);
     unset($oFile);
     (new UserCoreModel())->deleteAvatar($iProfileId);
     /* Clean User Avatar Cache */
     (new Framework\Cache\Cache())->start(Framework\Layout\Html\Design::CACHE_AVATAR_GROUP . $sUsername, null, null)->clear()->start(UserCoreModel::CACHE_GROUP, 'avatar' . $iProfileId, null)->clear();
 }