function Video($Source, $Attributes = array()) { static $DefaultAttributes = array('width' => 640, 'height' => 360, 'poster' => '', 'autoplay' => False, 'controls' => 'controls'); static $VideoType = array('3gp' => '3gpp', 'ogv' => 'ogg', 'mkv' => 'x-matroska', 'm4v' => 'mp4'); //static $Codecs = array('mp4' => 'avc1.42E01E, mp4a.40.2', 'webm' => 'vp8, vorbis', 'ogg' => 'theora, vorbis'); static $Codecs; $Source = SplitString($Source); $StoreDirectory = trim(GetValue('StoreDirectory', $Attributes, '', True), '/'); foreach ($Source as $Src) { if ($StoreDirectory != '') { $Src = $StoreDirectory . '/' . $Src; } $Extension = strtolower(pathinfo($Src, 4)); $Type = ArrayValue($Extension, $VideoType, $Extension); $Codec = ArrayValue($Extension, $Codecs); $Src = Asset($Src); if ($Codec != False && strpos($Type, ';') === False) { $Type = $Type . ';' . Attribute('codecs', $Codec); } $Type = PrefixString('video/', $Type); $SourceAttributes = array('src' => $Src, 'type' => $Type); $Sources[] = '<source' . Attribute($SourceAttributes) . ' />'; } $Sources = implode("\n", $Sources); $Poster = ArrayValue('poster', $Attributes); // TODO: make poster from video if ($Poster && (GetValue('SizeOfPoster', $Attributes, False, True) || !array_key_exists('width', $Attributes))) { // TODO: FIX ME (WITHOUT URL) $ImagePoster = Asset($Poster, True); list($width, $height) = GetImageSize($ImagePoster); $Attributes = array_merge($Attributes, compact('width', 'height'), array('poster' => $ImagePoster)); } $Unsupported = sprintf(T('Your browser cant play this video. You can %s instead.'), Anchor(T('download the video'), $Source[0])); $Attributes = array_merge($DefaultAttributes, compact('Unsupported'), $Attributes); $Unsupported = Wrap(GetValue('Unsupported', $Attributes, '', True), 'p'); return Wrap($Sources . $Unsupported, 'video', $Attributes); // Flash Fallback. /*$Config = new StdClass(); $Config->clip->url = $Source[0]; $Config->autoPlay = ArrayValue('autoplay', $Attributes, False); $Config->autoBuffering = ArrayValue('autobuffering', $Attributes, True); //d(json_encode($Config)); $FlashOptions = array('width' => $Attributes['width'], 'height' => $Attributes['width'], 'FlashVars' => array('config' => json_encode($Config)) ); $Flash = FlashHtml('http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf', $FlashOptions); // TODO: Image Fallback //$ImageFallback = Img($Poster, array('alt' => 'Poster', 'title' => T('No video playback capabilities.'))); */ }
function SaveTags($TagString) { if (!is_string($TagString)) { $TagString = GetValue('Tags', $TagString); } $TagString = mb_strtolower($TagString, 'utf-8'); $TagString = preg_replace('/[^ \\-0-9a-zа-я]/iu', ' ', $TagString); $TagsNames = SplitString($TagString, ' ', array('array_filter', 'array_unique')); $ExistingTagData = Gdn::SQL()->Select('TagID, Name')->From('Tag')->WhereIn('Name', $TagsNames)->Get(); $ConsolidatedTags = ConsolidateArrayValuesByKey($ExistingTagData->ResultArray(), 'Name', 'TagID'); foreach ($TagsNames as $TagName) { $TagID = GetValue($TagName, $ConsolidatedTags); if ($TagID === False) { $TagID = Gdn::SQL()->History(False, True)->Insert('Tag', array('Name' => $TagName)); } $ConsolidatedTags[$TagName] = $TagID; } return $ConsolidatedTags; }
function UploadFile($TargetFolder, $InputName, $Options = False) { /* if (is_array($InputName)) { $Options = $InputName; $InputName = $TargetFolder; }*/ $FileName = ArrayValue('name', ArrayValue($InputName, $_FILES)); if ($FileName == '') { return; } // no upload, return null // options $AllowFileExtension = ArrayValue('AllowFileExtension', $Options); // TODO: $Overwrite is not used yet $CanOverwrite = ArrayValue('Overwrite', $Options, False); $CreateTargetFolder = ArrayValue('CreateTargetFolder', $Options, True); $WebTarget = ArrayValue('WebTarget', $Options); if ($CreateTargetFolder === True) { if (!file_exists($TargetFolder)) { mkdir($TargetFolder, 0777, True); } if (!is_writable($TargetFolder)) { throw new Exception(sprintf('Directory (%s) is not writable.', $TargetFolder)); } } $Upload = new Gdn_Upload(); if ($AllowFileExtension != False) { if (!is_array($AllowFileExtension)) { $AllowFileExtension = SplitString($AllowFileExtension); } foreach ($AllowFileExtension as $Extension) { $Upload->AllowFileExtension($Extension); } } $IsMultipleUpload = is_array($FileName); $Count = $IsMultipleUpload ? count($FileName) : 1; $OriginalFiles = $_FILES; $Result = array(); for ($i = 0; $i < $Count; $i++) { if ($IsMultipleUpload != False) { $_FILES[$InputName] = array(); foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $Key) { $Value = GetValueR($InputName . '.' . $Key . '.' . $i, $OriginalFiles); SetValue($Key, $_FILES[$InputName], $Value); } } else { $FileName = array($FileName); } $TempFile = $Upload->ValidateUpload($InputName); $TargetFile = GenerateCleanTargetName($TargetFolder, $FileName[$i], '', $TempFile, $CanOverwrite); // 2.0.18 screwed Gdn_Upload::SaveAs() //$Upload->SaveAs($TempFile, $TargetFile); if (!move_uploaded_file($TempFile, $TargetFile)) { throw new Exception(sprintf(T('Failed to move uploaded file to target destination (%s).'), $TargetFile)); } if ($WebTarget != False) { $File = str_replace(DS, '/', $TargetFile); } elseif (array_key_exists('WithTargetFolder', $Options)) { $File = $TargetFile; } else { $File = pathinfo($TargetFile, PATHINFO_BASENAME); } $Result[] = $File; } $_FILES = $OriginalFiles; if ($IsMultipleUpload) { return $Result; } return $File; }
/** * Gets current language from defined locale. * Example: Locale: en-CA, returns "en". * * @return string, default "en". */ function LocaleLanguageCode() { $T = SplitString(Gdn::Locale()->Current(), '/[_-]/'); return ArrayValue(0, $T, 'en'); }