Dotclear

source: plugins/dlManager/trunk/_widget.php @ 3316

Revision 3316, 5.9 KB checked in by Moe, 9 years ago (diff)

Prise en compte des *nouveaux* paramètres et suppression des ?>

Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of DL Manager, a plugin for Dotclear 2
5# Copyright (C) 2008,2010 Moe (http://gniark.net/) and Tomtom (http://blog.zenstyle.fr)
6#
7# DL Manager is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License v2.0
9# as published by the Free Software Foundation.
10#
11# DL Manager is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software Foundation,
18# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19#
20# Images are from Silk Icons : http://www.famfamfam.com/lab/icons/silk/
21#
22# ***** END LICENSE BLOCK *****
23
24if (!defined('DC_RC_PATH')) {return;}
25
26$core->addBehavior('initWidgets',array('dlManagerWidget','initWidgets'));
27
28/**
29@ingroup Download manager
30@brief Widget
31*/
32class dlManagerWidget
33{
34     /**
35     widget
36     @param    w    <b>object</b>  Widget
37     */
38     public static function initWidgets($w)
39     {
40          # set timezone
41          global $core;
42          $tz = $core->blog->settings->system->blog_timezone;
43
44          $w->create('dlManager',__('Download manager'),
45               array('dlManagerWidget','show'));
46
47          $w->dlManager->setting('title',__('Title:').' ('.__('optional').')',
48               __('Download manager'),'text');
49
50          $w->dlManager->setting('file_sort',__('Sort files:'),'','combo',
51               dlManager::getSortValues(true));
52
53          $w->dlManager->setting('root',__('root directory:'),'','combo',
54               dlManager::listDirs(true,false));
55         
56          $w->dlManager->setting('display_dirs',__('Display subdirectories'),
57               true,'check');
58         
59          $w->dlManager->setting('dirs_title',__('Subdirectories title:').
60               ' ('.__('optional').')',__('Directories'),'text');
61         
62          $w->dlManager->setting('display_files',__('Display files'),
63               true,'check');
64         
65          $w->dlManager->setting('files_title',__('Files title:').
66               ' ('.__('optional').')',__('Files'),'text');
67
68          $w->dlManager->setting('block',__('Block display:'),'<ul>%s</ul>','text');
69
70          $w->dlManager->setting('item',__('Item display:'),
71               '<li><a href="%1$s" title="%3$s">%2$s</a> %4$s</li>','textarea');
72
73          $w->dlManager->setting('link',
74               sprintf(__('Add a link to %s in the widget:'),__('Download manager')).
75               ' ('.__('optional').')',__('Download manager'),'text');
76
77          $w->dlManager->setting('homeonly',__('Home page only'),false,'check');
78     }
79     
80     /**
81     show widget
82     @param    w    <b>object</b>  Widget
83     @return   <b>string</b> XHTML
84     */
85     public static function show(&$w)
86     {
87          global $core;
88
89          if ($w->homeonly && $core->url->type != 'default') {
90               return;
91          }
92
93          $core->blog->settings->addNamespace('dlManager');
94         
95          if (!$core->blog->settings->dlManager->dlmanager_active) {return;}
96         
97          if (!dlManager::inJail($w->root)) {return;}
98         
99          # from /dotclear/admin/media.php
100          if ($w->file_sort) {
101               $core->media->setFileSort($w->file_sort);
102          }
103          # /from /dotclear/admin/media.php
104
105          $core->media->chdir($w->root);
106          $core->media->getDir();
107         
108          $items_str = $str = '';
109
110          $block_format = $w->block;
111          if (empty($block_format)) {$block_format = '%s';}
112         
113          $item_format = $w->item;
114          if (empty($item_format)) {$item_format = '%s';}
115         
116          if ($w->display_dirs)
117          {
118               $items = $core->media->dir['dirs'];
119               
120               # define root of DL Manager
121               $page_root = $core->blog->settings->dlManager->dlmanager_root;
122
123               # used to remove root from path
124               $page_root_len = strlen($page_root);
125               
126               # remove slash at the beginning of the string
127               if ($page_root_len > 0) {$page_root_len += 1;}
128               
129               $parent_dir_full_path = path::real(
130                    dirname($core->media->root.'/'.$w->root));
131               
132               foreach ($items as $item) {
133                    if (!empty($item->relname))
134                    {
135                         $item->relname = substr($item->relname,$page_root_len);
136                         
137                         # display only subdirectories
138                         if ($item->file != $parent_dir_full_path)
139                         {
140                              $items_str .= sprintf($item_format,$core->blog->url.
141                                   $core->url->getBase('media').'/'.$item->relname,
142                                   $item->basename,$item->basename,'');
143                         }
144                    }
145               }
146               
147               if (!empty($items_str))
148               {
149                    if ($w->dirs_title)
150                    {
151                         $str .= '<h3>'.html::escapeHTML($w->dirs_title).'</h3>';
152                    }
153                    $str .= sprintf($block_format,$items_str);
154               }
155          }
156         
157          if ($w->display_files)
158          {
159               $items_str = '';
160               $items = $core->media->dir['files'];
161               
162               foreach ($items as $item) {
163                    if ($item->media_type == 'image')
164                    {
165                         $icon = 'image.png';
166                    } elseif ($item->type == 'audio/mpeg3' )
167                    {
168                         $icon = 'music.png';
169                    } elseif ($item->type == 'video/x-flv'
170                         || $item->type == 'video/mp4'
171                         || $item->type == 'video/x-m4v')
172                    {
173                         $icon = 'film.png';
174                    } elseif ($item->type == 'application/zip')
175                    {
176                         $icon = 'briefcase.png';
177                    } elseif ($item->media_type == 'text')
178                    {
179                         $icon = 'page_white_text.png';
180                    } else
181                    {
182                         $icon = 'information.png';
183                    }
184                   
185                    $mediaplayer =
186                         '<a href="'.$core->blog->url.$core->url->getBase('mediaplayer').'/'.
187                         $item->media_id.'" title="'.__('Preview:').' '.$item->media_title.'">'.
188                         '<img src="'.$core->blog->getQmarkURL().
189                         'pf=dlManager/images/'.$icon.'" alt="'.__('Preview').'" />'.
190                         '</a>';
191                   
192                    $items_str .= sprintf($item_format,$core->blog->url.
193                         $core->url->getBase('download').'/'.$item->media_id,
194                         $item->media_title,$item->basename,$mediaplayer);
195               }
196               
197               if (!empty($items_str))
198               {
199                    if ($w->files_title)
200                    {
201                         $str .= '<h3>'.html::escapeHTML($w->files_title).'</h3>';
202                    }
203                    $str .= sprintf($block_format,$items_str);
204               }
205          }
206          unset($items);
207
208          # output
209          $header = (strlen($w->title) > 0)
210               ? '<h2>'.html::escapeHTML($w->title).'</h2>' : null;
211
212          $link = (strlen($w->link) > 0) ? '<p class="text"><a href="'.
213               dlManager::pageURL().'">'.html::escapeHTML($w->link).'</a></p>' : null;
214
215          return '<div class="dlmanager">'.$header.$str.$link.'</div>';
216     }
217}
Note: See TracBrowser for help on using the repository browser.

Sites map