Example #1
0
 public function index($ar_list_id)
 {
     $rows = [];
     if ($users = Lists::getInstance()->getTargetUsers($ar_list_id)) {
         foreach ($users as $user) {
             if ($attributes = $user->attributes()) {
                 unset($attributes['password']);
                 /** @var DateTime $r */
                 $attributes['created_at'] = $attributes['created_at'] instanceof DateTime ? $attributes['created_at']->format() : '';
                 $attributes['updated_at'] = $attributes['updated_at'] instanceof DateTime ? $attributes['updated_at']->format() : '';
                 if ($levels = $user->user_level) {
                     $attributes['levels'] = implode(', ', array_map(function ($level) {
                         return $level->level;
                     }, $levels));
                 }
                 if (empty($rows)) {
                     $rows[] = array_keys($attributes);
                 }
                 $rows[] = array_values($attributes);
             }
         }
         HttpResponse::getInstance()->sendDownload(sprintf('ar_download_list_%d.csv', $ar_list_id), 'text/csv');
         $out = fopen('php://output', 'w');
         foreach ($rows as $row) {
             fputcsv($out, $row);
         }
         fclose($out);
     } else {
         throw new BasicError("No matching users: List does not contain any users");
     }
 }
Example #2
0
 public function upload()
 {
     $app = App::getInstance();
     $user_id = SessionManager::getInstance()->getUserID();
     if (!empty($_FILES['file']['name'])) {
         $filename = $_FILES['file']['name'];
         $file = sprintf("%s/%s", PathUtils::getTmpDir('tmp/uploads'), $filename);
         $saved = move_uploaded_file($_FILES['file']['tmp_name'], $file);
     } elseif (!empty($_POST['file']) && !empty($_POST['data'])) {
         $filename = $_POST['file'];
         $file = sprintf("%s/%s", PathUtils::getTmpDir('tmp/uploads'), $filename);
         $data = !empty($_POST['base64']) ? base64_decode($_POST['data']) : $_POST['data'];
         $saved = file_put_contents($file, $data);
     }
     if (!empty($file) & !empty($saved)) {
         try {
             $type = PathUtils::getFileType($file);
             $event = new UploadEvent($user_id, ['file' => $file]);
             if ($app->dispatch("user_upload_{$type}", $event)) {
                 if ($upload = $event->getURL()) {
                     HttpResponse::getInstance()->display(['url' => $upload], '', true);
                 }
             }
         } finally {
             @unlink($file);
         }
     }
     HttpResponse::getInstance()->displayError("Unable to upload file");
 }
Example #3
0
 private function go($name, $thumb = false)
 {
     if ($s3conf = App::getInstance()->config->getKey(S3Utils::stockUtilsKey)) {
         $host = !empty($s3conf['cdn']) ? $s3conf['cdn'] : sprintf('%s.s3.amazonaws.com', $s3conf['bucket_name']);
         $url = sprintf('http://%s/bgtracks/fonts/%s%s.%s', $host, !empty($thumb) ? 'thumbs/' : '', $name, !empty($thumb) ? 'png' : 'swf');
         HttpResponse::getInstance()->redirect($url);
     }
 }
Example #4
0
 public function index($param1)
 {
     $config = App::getInstance()->config;
     if ($s3conf = $config->getKey(S3Utils::stockUtilsKey)) {
         $host = @(!empty($s3conf['cdn']) ? $s3conf['cdn'] : sprintf('%s.s3.amazonaws.com', $s3conf['bucket_name'] ?: 'stockutils'));
         $url = sprintf('http%s://%s/bgtracks/%s', $config->getKey('private/prefer_https') ? 's' : '', $host, $param1);
         HttpResponse::getInstance()->redirect($url);
     }
 }
Example #5
0
 public function index($project_id)
 {
     $host = App::getInstance()->getSelfHost();
     $data = ['converter_url' => sprintf('%s/static/local/swf/converter/converter.swf', $host), 'player_url' => sprintf('%s/static/local/swf/player/player.swf', $host, $project_id), 'project_url' => sprintf('%s/members/projects/data/%d', $host, $project_id)];
     if (@$_GET['html'] == '0') {
         $url = sprintf('%s?%s', $data['converter_url'], http_build_query(array_intersect_key($data, array_flip(['player_url', 'project_url']))));
         HttpResponse::getInstance()->redirect($url);
     }
     View::forgeWithoutLayout('Swf2Vid/FlashPlayer.php', $data);
 }
Example #6
0
 /**
  * @param ActiveModel $model
  * @param string $cmd
  */
 public function save($model, $cmd)
 {
     if ($cmd == 'remove') {
         $model::$deletePermission = 'admin';
         $result = $model->delete();
     } else {
         $model::$createPermission = 'admin';
         $model::$updatePermission = 'admin';
         $result = $model->save();
     }
     HttpResponse::getInstance()->display($result, empty($result) ? 'Permission denied' : '');
 }
Example #7
0
 public function upload($video)
 {
     if (!empty($video['url'])) {
         $ytWrapper = YouTubeWrapper::getInstance();
         if ($user_id = SessionManager::getInstance()->getUserID()) {
             if ($url = $ytWrapper->uploadS3URL($user_id, $video['url'], 'public', $video['title'], $video['description'], $video['category'], $video['keywords'])) {
                 App::getInstance()->dispatch(Swf2VidEvent::USER_UPLOAD_VIDEO, new UserEvent($user_id, array_merge($video, ['upload_url' => $url])));
                 HttpResponse::getInstance()->display(['url' => $url], '', true);
             }
         }
     } else {
         throw new UploadError("Video url cannot be empty");
     }
     throw new UploadError("Unable to upload at this time, sorry.");
 }
Example #8
0
 public function index($urls)
 {
     if ($files = HttpProxy::getInstance()->proxy($urls)) {
         $app = App::getInstance();
         $user_id = SessionManager::getInstance()->getUserID();
         foreach ($files as $file) {
             $event = new UploadEvent($user_id, ['file' => $file['local']]);
             if ($app->dispatch(UploadEvent::USER_UPLOAD_IMAGE, $event)) {
                 if ($upload = $event->getURL()) {
                     $results[] = ['src' => $file['remote'], 'copy' => $upload];
                 }
             }
         }
     }
     HttpResponse::getInstance()->display(!empty($results) ? $results : '');
 }
Example #9
0
 public function index($urls, $width, $height)
 {
     if ($images = HttpProxy::getInstance()->proxy($urls)) {
         $app = App::getInstance();
         $user_id = SessionManager::getInstance()->getUserID();
         foreach ($images as $image) {
             $resized = self::resize_image($image['local'], $width ?: 854, $height ?: 480);
             $event = new UploadEvent($user_id, ['file' => $resized]);
             if ($app->dispatch(UploadEvent::USER_UPLOAD_IMAGE, $event)) {
                 if ($upload = $event->getURL()) {
                     $results[] = ['src' => $image['remote'], 'copy' => $upload];
                 }
             }
         }
     }
     HttpResponse::getInstance()->display(!empty($results) ? $results : '');
 }
Example #10
0
 public function save($fn)
 {
     $app = App::getInstance();
     $content = file_get_contents('php://input');
     //$file_path = sprintf("%s/%s.wav", PathUtils::getTmpDir('tmp/recordings'), $fn);
     $wav = sprintf("E:/var/Dropbox/www/viralvideorobot/public/tmp/%s.wav", $fn);
     if (file_put_contents($wav, $content)) {
         $mp3 = preg_replace('/(\\.wav)$/', '.mp3', $wav);
         system(sprintf('ffmpeg -y -i "%s" -qscale:a 2 "%s"', $wav, $mp3));
         if (file_exists($mp3)) {
             $output = basename($mp3);
             unlink($wav);
         } else {
             $output = basename($wav);
         }
         echo json_encode(['filename' => "/tmp/{$output}"]);
         exit;
     }
     HttpResponse::getInstance()->displayError("Content not found");
 }