Dotclear

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

Revision 2713, 5.8 KB checked in by Moe, 13 years ago (diff)

DL Manager 1.1.4: cleanup

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->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          if (!$core->blog->settings->dlmanager_active) {return;}
94         
95          if (!dlManager::inJail($w->root)) {return;}
96         
97          # from /dotclear/admin/media.php
98          if ($w->file_sort) {
99               $core->media->setFileSort($w->file_sort);
100          }
101          # /from /dotclear/admin/media.php
102
103          $core->media->chdir($w->root);
104          $core->media->getDir();
105         
106          $items_str = $str = '';
107
108          $block_format = $w->block;
109          if (empty($block_format)) {$block_format = '%s';}
110         
111          $item_format = $w->item;
112          if (empty($item_format)) {$item_format = '%s';}
113         
114          if ($w->display_dirs)
115          {
116               $items = $core->media->dir['dirs'];
117               
118               # define root of DL Manager
119               $page_root = $core->blog->settings->dlmanager_root;
120
121               # used to remove root from path
122               $page_root_len = strlen($page_root);
123               
124               # remove slash at the beginning of the string
125               if ($page_root_len > 0) {$page_root_len += 1;}
126               
127               $parent_dir_full_path = path::real(
128                    dirname($core->media->root.'/'.$w->root));
129               
130               foreach ($items as $item) {
131                    if (!empty($item->relname))
132                    {
133                         $item->relname = substr($item->relname,$page_root_len);
134                         
135                         # display only subdirectories
136                         if ($item->file != $parent_dir_full_path)
137                         {
138                              $items_str .= sprintf($item_format,$core->blog->url.
139                                   $core->url->getBase('media').'/'.$item->relname,
140                                   $item->basename,$item->basename,'');
141                         }
142                    }
143               }
144               
145               if (!empty($items_str))
146               {
147                    if ($w->dirs_title)
148                    {
149                         $str .= '<h3>'.html::escapeHTML($w->dirs_title).'</h3>';
150                    }
151                    $str .= sprintf($block_format,$items_str);
152               }
153          }
154         
155          if ($w->display_files)
156          {
157               $items_str = '';
158               $items = $core->media->dir['files'];
159               
160               foreach ($items as $item) {
161                    if ($item->media_type == 'image')
162                    {
163                         $icon = 'image.png';
164                    } elseif ($item->type == 'audio/mpeg3' )
165                    {
166                         $icon = 'music.png';
167                    } elseif ($item->type == 'video/x-flv'
168                         || $item->type == 'video/mp4'
169                         || $item->type == 'video/x-m4v')
170                    {
171                         $icon = 'film.png';
172                    } elseif ($item->type == 'application/zip')
173                    {
174                         $icon = 'briefcase.png';
175                    } elseif ($item->media_type == 'text')
176                    {
177                         $icon = 'page_white_text.png';
178                    } else
179                    {
180                         $icon = 'information.png';
181                    }
182                   
183                    $mediaplayer =
184                         '<a href="'.$core->blog->url.$core->url->getBase('mediaplayer').'/'.
185                         $item->media_id.'" title="'.__('Preview:').' '.$item->media_title.'">'.
186                         '<img src="'.$core->blog->getQmarkURL().
187                         'pf=dlManager/images/'.$icon.'" alt="'.__('Preview').'" />'.
188                         '</a>';
189                   
190                    $items_str .= sprintf($item_format,$core->blog->url.
191                         $core->url->getBase('download').'/'.$item->media_id,
192                         $item->media_title,$item->basename,$mediaplayer);
193               }
194               
195               if (!empty($items_str))
196               {
197                    if ($w->files_title)
198                    {
199                         $str .= '<h3>'.html::escapeHTML($w->files_title).'</h3>';
200                    }
201                    $str .= sprintf($block_format,$items_str);
202               }
203          }
204          unset($items);
205
206          # output
207          $header = (strlen($w->title) > 0)
208               ? '<h2>'.html::escapeHTML($w->title).'</h2>' : null;
209
210          $link = (strlen($w->link) > 0) ? '<p class="text"><a href="'.
211               dlManager::pageURL().'">'.html::escapeHTML($w->link).'</a></p>' : null;
212
213          return '<div class="dlmanager">'.$header.$str.$link.'</div>';
214     }
215}
216
217?>
Note: See TracBrowser for help on using the repository browser.

Sites map