Ejemplo n.º 1
0
 public function typeBtnJson()
 {
     $value = Ajde::app()->getRequest()->getPostParam('type');
     $id = Ajde::app()->getRequest()->getPostParam('id', false);
     $model = new MediaModel();
     if (!is_array($id)) {
         $id = [$id];
     }
     foreach ($id as $elm) {
         $model->loadByPK($elm);
         $model->set('mediatype', $value);
         $model->save();
     }
     return ['success' => true, 'message' => Ajde_Component_String::makePlural(count($id), 'media') . ' changed'];
 }
Ejemplo n.º 2
0
 /**
  * Create and display a thumbnail of an uploaded file.
  *
  * @param UtilityController $Sender
  * @param array $Args
  */
 public function utilityController_thumbnail_create($Sender, $Args = array())
 {
     $MediaID = array_shift($Args);
     if (!is_numeric($MediaID)) {
         array_unshift($Args, $MediaID);
     }
     $SubPath = implode('/', $Args);
     // Fix mauling of protocol:// URLs.
     $SubPath = preg_replace('/:\\/{1}/', '://', $SubPath);
     $Name = $SubPath;
     $Parsed = Gdn_Upload::parse($Name);
     // Get actual path to the file.
     $upload = new Gdn_UploadImage();
     $Path = $upload->copyLocal($SubPath);
     if (!file_exists($Path)) {
         throw NotFoundException('File');
     }
     // Figure out the dimensions of the upload.
     $ImageSize = getimagesize($Path);
     $SHeight = $ImageSize[1];
     $SWidth = $ImageSize[0];
     if (!in_array($ImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         if (is_numeric($MediaID)) {
             // Fix the thumbnail information so this isn't requested again and again.
             $Model = new MediaModel();
             $Media = array('MediaID' => $MediaID, 'ImageWidth' => 0, 'ImageHeight' => 0, 'ThumbPath' => null);
             $Model->save($Media);
         }
         $Url = Asset('/plugins/FileUpload/images/file.png');
         Redirect($Url, 301);
     }
     $Options = array();
     $ThumbHeight = MediaModel::thumbnailHeight();
     $ThumbWidth = MediaModel::thumbnailWidth();
     if (!$ThumbHeight || $SHeight < $ThumbHeight) {
         $Height = $SHeight;
         $Width = $SWidth;
     } else {
         $Height = $ThumbHeight;
         $Width = round($Height * $SWidth / $SHeight);
     }
     if ($ThumbWidth && $Width > $ThumbWidth) {
         $Width = $ThumbWidth;
         if (!$ThumbHeight) {
             $Height = round($Width * $SHeight / $SWidth);
         } else {
             $Options['Crop'] = true;
         }
     }
     $TargetPath = "thumbnails/{$Parsed['Name']}";
     $ThumbParsed = Gdn_UploadImage::saveImageAs($Path, $TargetPath, $Height, $Width, $Options);
     // Cleanup if we're using a scratch copy
     if ($ThumbParsed['Type'] != '' || $Path != MediaModel::pathUploads() . '/' . $SubPath) {
         @unlink($Path);
     }
     if (is_numeric($MediaID)) {
         // Save the thumbnail information.
         $Model = new MediaModel();
         $Media = array('MediaID' => $MediaID, 'ThumbWidth' => $ThumbParsed['Width'], 'ThumbHeight' => $ThumbParsed['Height'], 'ThumbPath' => $ThumbParsed['SaveName']);
         $Model->save($Media);
     }
     $Url = $ThumbParsed['Url'];
     redirect($Url, 301);
 }
Ejemplo n.º 3
0
 /**
  * 更新 video 数据
  */
 function edit_video()
 {
     $medias = new MediaModel();
     if (!!($data = $medias->create())) {
         //如果有传ID过来
         if (!empty($data['id'])) {
             if ($medias->save()) {
                 $this->assign('jumpUrl', __URL__ . '/index');
                 $this->success('音频更新成功');
             } else {
                 $this->assign('jumpUrl', __URL__ . '/index');
                 $this->error('音频更新失败,请联系管理员' . $medias->getDbError());
             }
         } else {
             $this->assign('jumpUrl', __URL__ . '/index');
             $this->error('请选择音频');
         }
     } else {
         $this->assign('jumpUrl', __URL__ . '/index');
         $this->error('音频更新失败' . $medias->getError());
     }
 }