本文整理汇总了PHP中CStringHelper::getRandom方法的典型用法代码示例。如果您正苦于以下问题:PHP CStringHelper::getRandom方法的具体用法?PHP CStringHelper::getRandom怎么用?PHP CStringHelper::getRandom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStringHelper
的用法示例。
在下文中一共展示了CStringHelper::getRandom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runConvert
/**
*
* Cron job will run this function
* to do all the pending video conversion
*
* @since Jomsocial 1.2.0
*/
public function runConvert()
{
$config = CFactory::getConfig();
$videoFolder = $config->get('videofolder');
$deleteOriginal = $config->get('deleteoriginalvideos');
if (!$config->get('enablevideos')) {
$this->errorMsg[] = 'Video is disabled. Video conversion will not run. ';
return;
}
$zencoder = $config->get('enable_zencoder');
$model = CFactory::getModel('videos');
$videos = $model->getPendingVideos();
if (count($videos) < 1) {
$this->errorMsg[] = 'No videos pending for conversion. ';
return;
}
if (!$zencoder && !$this->hasFFmpegSupport()) {
$this->errorMsg[] = 'FFmpeg cannot be executed.';
return;
}
// First of all, lock the videos
$table = JTable::getInstance('Video', 'CTable');
foreach ($videos as $video) {
$table->load($video->id);
$table->save(array('status' => 'locked'));
$table->reset();
}
// Process each video
$videoCounter = 0;
if ($zencoder) {
$s3BucketPath = $config->get('storages3bucket');
$s3outputBaseUrl = 'http://' . $s3BucketPath . '.s3.amazonaws.com';
$videoFolder = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME;
list($outputWidth, $outputHeight) = explode('x', $config->get('videosSize'), 2);
$outputThumbSize = $config->get('videosThumbSize');
$test = false;
$path = JPATH_ROOT . '/components/com_community/libraries/zencoder.php';
if (JFile::exists($path)) {
include_once $path;
} else {
exit('Missing File' . JPATH_ROOT . '/components/com_community/libraries/zencoder.php');
}
$job = new CZencoderJob();
foreach ($videos as $video) {
$outputFilename = $videoFolder . '/' . $video->creator . '/' . CStringHelper::getRandom() . '.mp4';
$outputThumbUrl = $s3outputBaseUrl . '/' . $videoFolder . '/' . $video->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/';
//Error: "Filename should only be a file name. It should not include path information."
//zencoder restricted the filename, so we move the path from filename
$outputBaseUrl = $s3outputBaseUrl . '/' . $videoFolder . '/' . $video->creator;
$randomFilename = CStringHelper::getRandom();
$outputFilename = $randomFilename . '.mp4';
$input = JURI::root() . $video->path;
$oriPath = JPATH::clean(JPATH_ROOT . '/' . $video->path);
$videoName = explode('/', $video->path);
$outputObj = new CZencoderOutput();
$outputObj->setBaseUrl($outputBaseUrl);
$outputObj->setWidth($outputWidth);
$outputObj->setHeight($outputHeight);
$outputObj->setFilename($outputFilename);
$outputObj->setThumbnailsNumber(1);
$outputObj->setThumbnailsSize($outputThumbSize);
$outputObj->setThumbnailsBaseUrl($outputThumbUrl);
$outputObj->setThumbnailsPublic(1);
$outputObj->setPublic(1);
$outputObj->setNotifications(array(array('format' => 'xml', 'url' => CRoute::getExternalURL('index.php?option=com_community&view=videos&task=zencodercallback&videoid=' . $video->id . '&videoname=' . $videoName[count($videoName) - 1]))));
//Thumbname need to be video specific now
$outputObj->setThumbnailsPrefix($randomFilename);
// we only need 1 output file
$output = array();
$output[] = $outputObj->build();
$result = $job->create($input, $output, $test);
if ($result) {
// save into db
//$video->path = $outputFilename;
$video->path = $videoFolder . '/' . $video->creator . '/' . $outputFilename;
$video->thumb = $outputThumbUrl . $randomFilename . '_0000.png';
$video->duration = 0;
$video->storage = 's3';
$video->status = 'ready';
$storageTable = JTable::getInstance('StorageS3', 'CTable');
$storageTable->storageid = $video->path;
$storageTable->resource_path = $video->path;
$storageTable->store();
$table->reset();
$table->bind($video);
if ($table->store()) {
$this->errorMsg[] = $table->getError();
}
$this->addVideoActivity($table);
$videoCounter++;
} else {
$this->errorMsg[] = $job->getError();
}
//.........这里部分代码省略.........
示例2: runConvert
/**
*
* Cron job will run this function
* to do all the pending video conversion
*
* @since Jomsocial 1.2.0
*/
function runConvert()
{
$config = CFactory::getConfig();
$videofolder = $config->get('videofolder');
if (!$config->get('enablevideos')) {
$this->errorMsg[] = 'Video is disabled. Video conversion will not run. ';
return;
}
$zencoder = $config->get('enable_zencoder');
$model = CFactory::getModel('videos');
$videos = $model->getPendingVideos();
if (count($videos) < 1) {
$this->errorMsg[] = 'No videos pending for conversion. ';
return;
}
if (!$zencoder && !$this->hasFFmpegSupport()) {
$this->errorMsg[] = 'FFmpeg cannot be executed.';
return;
}
// First of all, lock the videos
$table = JTable::getInstance('Video', 'CTable');
foreach ($videos as $video) {
$table->load($video->id);
$table->save(array('status' => 'locked'));
$table->reset();
}
// Process each video
$videoCounter = 0;
if ($zencoder) {
$s3BucketPath = $config->get('storages3bucket');
$outputBaseUrl = 'http://' . $s3BucketPath . '.s3.amazonaws.com';
$videoFolder = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME;
list($outputWidth, $outputHeight) = explode('x', $config->get('videosSize'), 2);
$outputThumbSize = $config->get('videosThumbSize');
$test = false;
CFactory::load('helpers', 'string');
CFactory::load('libraries', 'zencoder');
$job = new CZencoderJob();
foreach ($videos as $video) {
$outputFilename = $videoFolder . '/' . $video->creator . '/' . CStringHelper::getRandom() . '.mp4';
$outputThumbUrl = $outputBaseUrl . '/' . $videoFolder . '/' . $video->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/';
//Error: "Filename should only be a file name. It should not include path information."
//zencoder restricted the filename, so we move the path from filename
$outputBaseUrl = $outputBaseUrl . '/' . $videoFolder . '/' . $video->creator;
$randomFilename = CStringHelper::getRandom();
$outputFilename = $randomFilename . '.mp4';
$input = JURI::root() . $video->path;
$outputObj = new CZencoderOutput();
$outputObj->setBaseUrl($outputBaseUrl);
$outputObj->setWidth($outputWidth);
$outputObj->setHeight($outputHeight);
$outputObj->setFilename($outputFilename);
$outputObj->setThumbnailsNumber(1);
$outputObj->setThumbnailsSize($outputThumbSize);
$outputObj->setThumbnailsBaseUrl($outputThumbUrl);
$outputObj->setThumbnailsPublic(1);
$outputObj->setPublic(1);
//Thumbname need to be video specific now
$outputObj->setThumbnailsPrefix($randomFilename);
/* HTGMOD START - DJ */
$outputObj->setWatermark(JURI::root() . 'images/originalvideos/watermark.png', '-10', '-10', '100');
/* HTGMOD END - DJ */
// we only need 1 output file
$output = array();
$output[] = $outputObj->build();
$result = $job->create($input, $output, $test);
if ($result) {
/* HTGMOD START - DJ */
$videoInfo = $this->getVideoInfo(JPATH::clean(JPATH_ROOT . DS . $video->path));
/* HTGMOD END - DJ */
// save into db
//$video->path = $outputFilename;
$video->path = $videoFolder . '/' . $video->creator . '/' . $outputFilename;
$video->thumb = $outputThumbUrl . $randomFilename . '_0000.png';
$video->duration = $videoInfo['duration']['sec'];
// HTGMOD
$video->storage = 's3';
$video->status = 'ready';
$storageTable = JTable::getInstance('StorageS3', 'CTable');
$storageTable->storageid = $video->path;
$storageTable->resource_path = $video->path;
$storageTable->store();
$table->reset();
$table->bind($video);
if ($table->store()) {
$this->errorMsg[] = $table->getError();
}
if ($table->isPublic()) {
$my = CFactory::getUser($table->creator);
$act = new stdClass();
$act->cmd = 'videos.upload';
$act->actor = $my->id;
$act->target = 0;
//.........这里部分代码省略.........