3 * mediaプラグインアップロードファイル出力用ヘルパー
7 App::import('Vendor', 'Media.Media');
9 class UpfileHelper extends MediaHelper {
10 var $helpers = array('Html', 'Media');
13 * Huck of Media::file()
14 * Resolves partial path
15 * Generates Version File if it dose not exist.
16 * Touches the Version File if it exists.
18 * $arg[1]: Data of type Attachment.0
21 function file($previewVersion)
23 if (!isset($previewVersion)) {
26 $args = func_get_args();
29 if (empty($args[1])) {
30 if (isset($args[2]['nodata']) && !empty($args[2]['nodata'])) {
34 'foreign_key' => NULL,
42 if ($args[2]['nodata'] == 'image') {
43 $data['dirname'] = 'img';
44 $data['basename'] = 'noimage.png';
45 $data['alternative'] = 'No Image';
56 $path = $previewVersion. DS. $data['dirname']. DS. $data['basename'];
58 // ファイルがある場合、ファイルパスを返す
59 $file = parent::file($path);
60 if (is_file($file) && is_readable($file)) {
64 require_once(APP.'plugins'.DS.'media'.DS.'libs'.DS.'upfile.php');
65 // $make_result = Upfile::make_version($path, $data, $args[2]);
66 $maked_version = Upfile::make_version($previewVersion, $path, $args[2]);
68 // cacheを削除して$file読み込み
69 if (!empty($maked_version)) {
71 return self::file($previewVersion, $args[1], $args[2]);
80 * Extend method of Media::embed()
81 * Generates markup to render a file inline
82 * Link to $options['linkTo'].
83 * HtmlAttributes can be userd for the link as $options['htmlAttributes'].
85 function embed($path, $options = array()) {
90 if (isset($options['linkTo']) && !empty($options['linkTo'])) {
91 unset($options['url']);
94 $out = $this->Media->embed($path, $options);
96 if (!isset($options['linkTo']) || empty($options['linkTo'])) {
100 if (!isset($options['htmlAttributes'])) {
101 $options['htmlAttributes'] = array();
103 $options['htmlAttributes'] = array_merge(array('escape' => false), $options['htmlAttributes']);
104 return $this->Html->link($out, $options['linkTo'], $options['htmlAttributes'], false);
108 // orig Versionファイルにリンクする
109 function embed_linkto_orig($file, $item, $model, $options = array()) {
110 $orig_size_filepath = self::file(
114 'model_name' => $model,
115 'mime_type' => 'original',
118 $options['linkTo'] = parent::url($orig_size_filepath, true);
120 return self::embed($file, $options);
124 * Generates file information
126 function fileInfo($file, $item)
131 $Media = Media::factory($file);
132 $size = $item['size'];
134 if (isset($number)) {
135 $size = $number->toReadableSize($size);
140 return sprintf('<div class="fileOptions"><em>%s</em> (%s/%s)</div>',
141 $item['alternative'],
142 // $url ? $html->link($item['basename'], $url) : $item['basename'],
143 strtolower($Media->name),
149 /* $attachments情報からファイルパスを取得 */
150 function get_charaimage_version_path4attachment($attachment, $options = array())
153 $options['previewVersion'],
159 /* basenameからファイルパスを取得 */
160 function get_cet_charaimage_version4basename($basename, $options = array())
163 if (!empty($basename)) {
165 if (isset($options['alternative'])) {
166 $alternative = $options['alternative'];
167 unset($options['alternative']);
171 'basename' => $basename,
172 'alternative' => $alternative,
175 return self::get_charaimage_version_path4attachment($data, $options);
178 function setting_charaimage_version_path($options = array())
180 $default_options = array(
181 'previewVersion' => 'l',
185 'model_name' => 'CharacterPicture',
186 'mime_type' => 'original',
188 'htmlAttributes' => array(),
191 return array_merge($default_options, $options);