コード例 #1
0
ファイル: File.php プロジェクト: jinshana/tangocms
 /**
  * Makes the correct directory for the files to be uploaded
  * to, a category can be provided as a token to replace.
  *
  * @param string $category
  * @return string|bool
  */
 protected function makeDirectory($category = null)
 {
     $uploadDir = str_replace('{CATEGORY}', $category, $this->uploader->uploadDir);
     if ($this->uploader->subDir === true) {
         if (!$this->uploader->subDirName) {
             $this->uploader->subDirectoryName(pathinfo(zula_make_unique_dir($uploadDir), PATHINFO_BASENAME));
         }
         $uploadDir .= '/' . $this->uploader->subDirName;
     }
     return zula_make_dir($uploadDir) && is_writable($uploadDir) ? $uploadDir : false;
 }
コード例 #2
0
ファイル: add.php プロジェクト: jinshana/tangocms
 /**
  * Handles adding a media item from an external source, such as YouTube.
  *
  * @param array $fd
  * @return array
  */
 protected function handleExternal(array $fd)
 {
     try {
         parse_str(parse_url($fd['external']['youtube_url'], PHP_URL_QUERY), $queryArgs);
         if (empty($queryArgs['v'])) {
             throw new Media_Exception(t('Please provide a valid YouTube URL'));
         }
         $serviceId = $queryArgs['v'];
         $externalMedia = Externalmedia::factory($fd['external']['service'], $serviceId);
     } catch (ExternalMediaDriver_InvalidID $e) {
         throw new Media_Exception(t('Please provide a valid YouTube URL'));
     } catch (Externalmedia_Exception $e) {
         throw new Media_Exception($e->getMessage());
     }
     // Generate a random directory as the uploader would, to store thumbnail
     $uploadDir = $this->_zula->getDir('uploads') . '/media/' . $fd['cid'] . '/external';
     if ($dirname = zula_make_unique_dir($uploadDir)) {
         $uploadDir .= '/' . $dirname;
         $thumbname = $dirname . '_thumb.png';
         if (copy($externalMedia->thumbUrl, $uploadDir . '/' . $thumbname)) {
             // Resize the thumbnail image
             try {
                 $thumbnailWH = $this->_config->get('media/thumb_dimension');
                 $thumbnail = new Image($uploadDir . '/' . $thumbname);
                 $thumbnail->mime = 'image/png';
                 $thumbnail->thumbnail($thumbnailWH, $thumbnailWH);
                 $thumbnail->save();
             } catch (Image_Exception $e) {
                 $this->_event->error(t('Oops, an error occurred while processing an image'));
                 $this->_log->message($e->getMessage(), Log::L_WARNING);
             }
         } else {
             $this->_event->error(t('Unable to save thumbnail image'));
             $thumbname = null;
         }
         return array(array('title' => empty($fd['title']) ? $externalMedia->title : $fd['title'], 'desc' => empty($fd['desc']) ? $externalMedia->description : $fd['desc'], 'type' => 'external', 'file' => '', 'thumbnail' => isset($thumbname) ? $dirname . '/' . $thumbname : '', 'external' => array('service' => $fd['external']['service'], 'id' => $serviceId)));
     } else {
         throw new Media_Exception(t('Unable to create directory'));
     }
 }