リビジョン | 208 (tree) |
---|---|
日時 | 2010-06-21 11:53:36 |
作者 | kmorimatsu |
1) <%img%> tag
2) core::event() method can return array of events
3) post_parse_plugin_desc event
4) media::send_media.php() method is now public
5) Quick-Menu on admin page
6) jp_SkinFiles under construction
@@ -6,7 +6,7 @@ | ||
6 | 6 | |
7 | 7 | class jp_SkinFiles extends plugin{ |
8 | 8 | static public function name(){ |
9 | - return 'Skin Files Plugin'; | |
9 | + return '_JP_SKINFILES_SKINFILES_PLUGIN'; | |
10 | 10 | } |
11 | 11 | static public function author(){ |
12 | 12 | return 'Katsumi'; |
@@ -15,7 +15,7 @@ | ||
15 | 15 | return 'http://jeanscms.sourceforge.jp/'; |
16 | 16 | } |
17 | 17 | static public function desc(){ |
18 | - return 'This is SkinFiles Plugin.'; | |
18 | + return '_JP_SKINFILES_SKINFILES_DESC'; | |
19 | 19 | } |
20 | 20 | static public function version(){ |
21 | 21 | return '0.1'; |
@@ -1,6 +1,21 @@ | ||
1 | 1 | <?php |
2 | 2 | |
3 | +define('_JP_SKINFILES_SKINFILES_PLUGIN','Skin Files plugin'); | |
4 | +define('_JP_SKINFILES_SKINFILES_DESC','This plugin is used for managing files in skin directory (skins/).'); | |
3 | 5 | define('_JP_SKINFILES_SKINFILE_MANAGEMENT','Skin File Management'); |
4 | 6 | define('_JP_SKINFILES_CURRENT_PATH','Current path'); |
5 | 7 | define('_JP_SKINFILES_DIR_NOT_FOUND','Directory not found.'); |
6 | 8 | define('_JP_SKINFILES_FILE_NOT_FOUND','File not found.'); |
9 | +define('JP_SKINFILES_NAME','Name'); | |
10 | +define('JP_SKINFILES_SIZE','Size'); | |
11 | +define('JP_SKINFILES_LAST_MODIFIED','Last Modified'); | |
12 | +define('JP_SKINFILES_ACTIONS','Actions'); | |
13 | +define('_JP_SKINFILES_SHOW_THUMBNAILS','Show Thumbnails'); | |
14 | +define('_JP_SKINFILES_DO_NOT_SHOW_THUMBNAILS','Do not Show Thumbnails'); | |
15 | +define('_JP_SKINFILES_RENAME','Rename'); | |
16 | +define('_JP_SKINFILES_DELETE','Delete'); | |
17 | +define('_JP_SKINFILES_EDIT','Edit'); | |
18 | +define('_JP_SKINFILES_SHOW','Show'); | |
19 | +define('_JP_SKINFILES_DOWNLOAD','Download'); | |
20 | +define('_JP_SKINFILES_SHOWING_VIRTUAL_PATH','Showing Virtual Path'); | |
21 | +define('_JP_SKINFILES_REAL_PATH','Real Path'); |
@@ -1,5 +1,7 @@ | ||
1 | 1 | <?php |
2 | 2 | |
3 | +define('_JP_SKINFILES_SKINFILES_PLUGIN','スキンファイル・プラグイン'); | |
4 | +define('_JP_SKINFILES_SKINFILES_DESC','スキンディレクトリ(skins/)上のファイルを管理するために使います。'); | |
3 | 5 | define('_JP_SKINFILES_SKINFILE_MANAGEMENT','スキンファイル管理'); |
4 | 6 | define('_JP_SKINFILES_CURRENT_PATH','現在のパス'); |
5 | 7 | define('_JP_SKINFILES_DIR_NOT_FOUND','ディレクトリが見つかりません。'); |
@@ -7,4 +9,13 @@ | ||
7 | 9 | define('JP_SKINFILES_NAME','名前'); |
8 | 10 | define('JP_SKINFILES_SIZE','サイズ'); |
9 | 11 | define('JP_SKINFILES_LAST_MODIFIED','最終更新日'); |
10 | -define('JP_SKINFILES_ACTION','アクション'); | |
12 | +define('JP_SKINFILES_ACTIONS','アクション'); | |
13 | +define('_JP_SKINFILES_SHOW_THUMBNAILS','サムネイルを表示'); | |
14 | +define('_JP_SKINFILES_DO_NOT_SHOW_THUMBNAILS','サムネイルを表示しない'); | |
15 | +define('_JP_SKINFILES_RENAME','名前変更'); | |
16 | +define('_JP_SKINFILES_DELETE','削除'); | |
17 | +define('_JP_SKINFILES_EDIT','編集'); | |
18 | +define('_JP_SKINFILES_SHOW','表示'); | |
19 | +define('_JP_SKINFILES_DOWNLOAD','ダウンロード'); | |
20 | +define('_JP_SKINFILES_SHOWING_VIRTUAL_PATH','ヴァーチャルパスで表示しています'); | |
21 | +define('_JP_SKINFILES_REAL_PATH','本当のパス'); |
@@ -0,0 +1,6 @@ | ||
1 | +td a:link, td a:visited { | |
2 | + text-decoration : none; | |
3 | +} | |
4 | +tr.jp_skinfiles_virtual td, tr.jp_skinfiles_virtual td a:link, tr.jp_skinfiles_virtual td a:visited { | |
5 | + color : #8080ff; | |
6 | +} |
@@ -74,13 +74,25 @@ | ||
74 | 74 | view::show_using_array($data,$array,$skin); |
75 | 75 | } |
76 | 76 | static public function tag_dir(&$data,$skin=false){ |
77 | + $image_exists=false; | |
78 | + $files=array(); | |
79 | + if (preg_match('#^[^/]+/(.*)$#',self::$dir_path,$m)) { | |
80 | + foreach(self::$extends as $parent_skin){ | |
81 | + $files=array_merge($files,self::file_list("$parent_skin/$m[1]",true)); | |
82 | + } | |
83 | + } | |
84 | + $files=array_merge($files,self::file_list(self::$real_dir_path,self::if_virtualdir())); | |
77 | 85 | $array=array(); |
78 | - $files=self::file_list(self::$real_dir_path); | |
79 | - foreach($files as $row) $array[]=$row; | |
86 | + foreach($files as $row) { | |
87 | + $array[$row['name']]=$row; | |
88 | + $image_exists |= ($row['type']=='image'); | |
89 | + } | |
90 | + $data['jp']['skinfiles']['image_exists']=$image_exists; | |
80 | 91 | view::show_using_array($data,$array,$skin); |
81 | 92 | } |
82 | 93 | static private function file_list($dir,$virtual=false){ |
83 | 94 | $files=$dirs=array(); |
95 | + if (!self::local_file_exists(_DIR_SKINS,$dir)) return array(); | |
84 | 96 | $d=dir(_DIR_SKINS.$dir); |
85 | 97 | while(($file=$d->read())!==false){ |
86 | 98 | if ($file=='.' || $file=='..') continue; |
@@ -153,6 +165,8 @@ | ||
153 | 165 | return self::p(self::$file); |
154 | 166 | case 'real_dir': |
155 | 167 | return self::p(self::$real_dir_path); |
168 | + case 'real_file': | |
169 | + return self::p(self::$real_file_path); | |
156 | 170 | } |
157 | 171 | } |
158 | 172 | static public function tag_showtext(){ |
@@ -175,4 +189,75 @@ | ||
175 | 189 | static public function if_virtualfile(){ |
176 | 190 | return self::$file_path!=self::$real_file_path; |
177 | 191 | } |
192 | + static public function if_thumbnail(){ | |
193 | + return !empty($_GET['thumbnail']); | |
194 | + } | |
195 | + static public function action_get_thumbnail(){ | |
196 | + // Check the local file. | |
197 | + $full_path=self::local_file_exists(_DIR_SKINS,self::$real_file_path); | |
198 | + if (!$full_path) error::quit('File not found'); | |
199 | + $time=filemtime(_DIR_SKINS.self::$real_file_path); | |
200 | + // Check if modified (the browser would store a cache). | |
201 | + media::check_if_changed($time); | |
202 | + // Check if the file is an image. | |
203 | + if (!preg_match('/\.([^\.]+)$/',self::$file,$m)) error::quit('Not an image.'); | |
204 | + $mime=admin_media::mime($m[1]); | |
205 | + if (substr($mime,0,6)!='image/') error::quit('Not an image.'); | |
206 | + // Get the image info | |
207 | + list($width,$height,$new_width,$new_height)=self::image_size(self::$real_file_path); | |
208 | + // Return the image to browser (use tumbnail if possible. | |
209 | + if ($width!=$new_width || $height!=$new_height) { | |
210 | + $gd=admin_media::gd($full_path,$mime); | |
211 | + if ($gd) $file=$gd[2]['file']; | |
212 | + } | |
213 | + if (!isset($file)) $file=self::local_file_contents(_DIR_SKINS,self::$real_file_path); | |
214 | + media::send_media($file,$mime,$time); | |
215 | + } | |
216 | + static public function tag_thumbnail(&$data){ | |
217 | + $file=$data['name']; | |
218 | + // Check if the file is an image. | |
219 | + if (!preg_match('/\.([^\.]+)$/',$file,$m)) error::quit('Not an image.'); | |
220 | + $mime=admin_media::mime($m[1]); | |
221 | + if (substr($mime,0,6)!='image/') error::quit('Not an image.'); | |
222 | + // Get the image info | |
223 | + list($width,$height,$new_width,$new_height)=self::image_size(self::to_realpath(self::$real_dir_path.$file)); | |
224 | + // Show the img tag | |
225 | + $html='<img src="<%url%>" width="<%width%>" height="<%height%>" alt="<%alt%>" />'; | |
226 | + $array=array( | |
227 | + 'url'=>_CONF_SELF.'?action=jp.skinfiles.class.thumbnail&dir_path='.self::$dir_path.'&file='.$file, | |
228 | + 'width'=>$new_width, | |
229 | + 'height'=>$new_height, | |
230 | + 'alt'=>$file); | |
231 | + self::echo_html($html,$array); | |
232 | + } | |
233 | + static private function image_size($file_path){ | |
234 | + $full_path=self::local_file_exists(_DIR_SKINS,$file_path); | |
235 | + if (!$full_path) return false; | |
236 | + $info=@getimagesize(_DIR_SKINS.$file_path); | |
237 | + $width=$info[0]; | |
238 | + $height=$info[1]; | |
239 | + // Decide the new size. | |
240 | + if ($width>$height && $width>_CONF_THUMBNAIL_SIZE) { | |
241 | + $new_width=intval(_CONF_THUMBNAIL_SIZE); | |
242 | + $new_height=intval($height * _CONF_THUMBNAIL_SIZE / $width); | |
243 | + } elseif ($height>$width && $height>_CONF_THUMBNAIL_SIZE) { | |
244 | + $new_width=intval($width * _CONF_THUMBNAIL_SIZE / $height); | |
245 | + $new_height=intval(_CONF_THUMBNAIL_SIZE); | |
246 | + } else { | |
247 | + $new_width=$width; | |
248 | + $new_height=$height; | |
249 | + } | |
250 | + return array($width,$height,$new_width,$new_height); | |
251 | + } | |
252 | + static public function action_get_download(){ | |
253 | + $filename=self::$file; | |
254 | + preg_match('/([^\.]*)$/',$filename,$m); | |
255 | + $mime=admin_media::mime($m[1]); | |
256 | + header("Content-Type: $mime; name=\"$filename\""); | |
257 | + header("Content-disposition: attachment; filename=$filename"); | |
258 | + $full_path=self::local_file_exists(_DIR_SKINS,self::$real_file_path); | |
259 | + header('Content-length: '.filesize($full_path)); | |
260 | + readfile($full_path); | |
261 | + exit; | |
262 | + } | |
178 | 263 | } |
\ No newline at end of file |
@@ -556,6 +556,11 @@ | ||
556 | 556 | $res=sql::query($query,$event); |
557 | 557 | while ($row=$res->fetch()) $cache[$group][$event][]=$row['plugin']; |
558 | 558 | } |
559 | + if ($arg===false) { | |
560 | + // export cache | |
561 | + return $cache[$group][$event]; | |
562 | + // Otherwise $arg must be an array. | |
563 | + } | |
559 | 564 | foreach ($cache[$group][$event] as $plugin) { |
560 | 565 | call_user_func_array(array($plugin,"event_$event"),array(&$arg)); |
561 | 566 | } |
@@ -15,4 +15,12 @@ | ||
15 | 15 | elseif (member::logged_in()) core::event('member_quick_menu',$args,'admin'); |
16 | 16 | view::show_using_array($data,$array,$skin); |
17 | 17 | } |
18 | + static public function tag_postparseplugindesc(&$data){ | |
19 | + static $cache; | |
20 | + if (!isset($cache)) $cache=core::event('post_parse_plugin_desc',false,'action'); | |
21 | + if (in_array($data['id'],$cache)) { | |
22 | + $args=array(); | |
23 | + call_user_func_array(array($data['id'],'event_post_parse_plugin_desc'),$args); | |
24 | + } | |
25 | + } | |
18 | 26 | } |
\ No newline at end of file |
@@ -76,8 +76,6 @@ | ||
76 | 76 | if (isset($events[$row['id']])) $row['events']=implode(', ',$events[$row['id']]); |
77 | 77 | // Check admin area |
78 | 78 | if (self::local_file_exists(_DIR_PLUGINS,substr(strtolower($row['id']),3).'/skin.inc')) $row['admin']=1; |
79 | - // Translate description | |
80 | - $row['desc']=self::translate($row['desc']); | |
81 | 79 | } |
82 | 80 | static public function tag_install(&$data,$skin){ |
83 | 81 | $array=array(); |
@@ -567,16 +567,22 @@ | ||
567 | 567 | static public function tag_img(&$data,$file=false,$alt=false,$width=false,$height=false){ |
568 | 568 | if (!$file) $file=$data['file']; |
569 | 569 | if (!$alt) $alt=isset($data['alt']) ? $data['alt']:$file; |
570 | - showmedia::tag_img($data,$file,$alt,$width,$height); | |
570 | + $path=view::skinfile($data,$file); | |
571 | + if (strpos($path,_CONF_URL_PLUGINS)===0) { | |
572 | + $dir=_DIR_PLUGINS; | |
573 | + $file=substr($path,strlen(_CONF_URL_PLUGINS)); | |
574 | + } else { | |
575 | + $dir=_DIR_SKINS; | |
576 | + $file=substr($path,strlen(_CONF_URL_SKINS)); | |
577 | + } | |
578 | + if (!self::local_file_exists($dir,$file)) return self::p($alt); | |
579 | + if (!$height) { | |
580 | + $size=getimagesize($dir.$file); | |
581 | + $width=$size[0]; | |
582 | + $height=$size[1]; | |
583 | + } | |
584 | + self::echo_html('<img src="<%0%>" alt="<%1%>" width="<%2%>" height="<%3%>" />',array($path,$alt,$width,$height)); | |
571 | 585 | } |
572 | - static public function tag_imgdb(&$data,$file=false,$alt=false,$width=false,$height=false){ | |
573 | - if (!$file) $file=$data['file']; | |
574 | - if (!$alt) $alt=isset($data['alt']) ? $data['alt']:$file; | |
575 | - showmedia::tag_imgdb($data,$file,$alt,$width,$height); | |
576 | - } | |
577 | - static public function tag_media(&$data,$file=false,$mode='raw',$alt=false){ | |
578 | - showmedia::tag_media($data,$file,$mode,$alt); | |
579 | - } | |
580 | 586 | static public function tag_callback(&$data,$event){ |
581 | 587 | $args=func_get_args(); |
582 | 588 | array_shift($args); //&$data |
@@ -105,7 +105,7 @@ | ||
105 | 105 | * Following method is public. |
106 | 106 | * You can use it from any class. |
107 | 107 | */ |
108 | - static private function send_media(&$image,$mime,$time=false,$name=false,$mode='view'){ | |
108 | + static public function send_media(&$image,$mime,$time=false,$name=false,$mode='view'){ | |
109 | 109 | // Prepare header |
110 | 110 | if (!$time) $time=time(); |
111 | 111 | if ($name===false) header("Content-Type: $mime"); |