OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / mos / class / html.php
1 <?php
2 /**
3  * @version             $Id: html.php 5538 2013-01-10 09:53:17Z fishbone $
4  * @package             Joomla.Framework
5  * @subpackage  HTML
6  * @copyright   Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
7  * @license             GNU/GPL, see LICENSE.php
8  * Joomla! is free software. This version may have been modified pursuant
9  * to the GNU General Public License, and as distributed it includes or
10  * is derivative of works licensed under the GNU General Public License or
11  * other free or open source software licenses.
12  * See COPYRIGHT.php for copyright notices and details.
13  */
14
15 /**
16  * Utility class for all HTML drawing classes
17  *
18  * @static
19  * @package     Joomla.Framework
20  * @subpackage  HTML
21  * @since               1.5
22  */
23 class JHTML
24 {
25         /**
26          * Class loader method
27          *
28          * Additional arguments may be supplied and are passed to the sub-class.
29          * Additional include paths are also able to be specified for third-party use
30          *
31          * @param       string  The name of helper method to load, (prefix).(class).function
32          *                  prefix and class are optional and can be used to load custom
33          *                  html helpers.
34          */
35         public static function _( $type )
36         {
37                 global $gEnvManager;
38
39                 //Initialise variables
40                 $prefix = 'JHTML';
41                 $file   = '';
42                 $func   = $type;
43
44                 // Check to see if we need to load a helper file
45                 $parts = explode('.', $type);
46
47                 switch(count($parts))
48                 {
49                         case 3 :
50                         {
51                                 $prefix         = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
52                                 $file           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
53                                 $func           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[2] );
54                         } break;
55
56                         case 2 :
57                         {
58                                 $file           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
59                                 $func           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
60                         } break;
61                 }
62
63                 $className      = $prefix.ucfirst($file);
64                 if (!class_exists( $className ))
65                 {
66                         if ($path = $gEnvManager->getJoomlaRootPath() . '/class/html/' . strtolower($file) . '.php')
67                         {
68                                 require_once $path;
69
70                                 if (!class_exists( $className ))
71                                 {
72                                         JError::raiseWarning( 0, $className.'::' .$func. ' not found in file.' );
73                                         return false;
74                                 }
75                         }
76                         else
77                         {
78                                 JError::raiseWarning( 0, $prefix.$file . ' not supported. File not found.' );
79                                 return false;
80                         }
81                 }
82
83                 if (is_callable( array( $className, $func ) ))
84                 {
85                         $args = func_get_args();
86                         array_shift( $args );
87                         return call_user_func_array( array( $className, $func ), $args );
88                 }
89                 else
90                 {
91                         JError::raiseWarning( 0, $className.'::'.$func.' not supported.' );
92                         return false;
93                 }
94         }
95
96         /**
97          * Write a <a></a> element
98          *
99          * @access      public
100          * @param       string  The relative URL to use for the href attribute
101          * @param       string  The target attribute to use
102          * @param       array   An associative array of attributes to add
103          * @since       1.5
104          */
105         public static function link($url, $text, $attribs = null)
106         {
107                 if (is_array( $attribs )) {
108                         $attribs = JArrayHelper::toString( $attribs );
109                 }
110
111                 return '<a href="'.$url.'" '.$attribs.'>'.$text.'</a>';
112         }
113
114         /**
115          * Write a <img></amg> element
116          *
117          * @access      public
118          * @param       string  The relative or absoluete URL to use for the src attribute
119          * @param       string  The target attribute to use
120          * @param       array   An associative array of attributes to add
121          * @since       1.5
122          */
123         public static function image($url, $alt, $attribs = null)
124         {
125                 if (is_array($attribs)) {
126                         $attribs = JArrayHelper::toString( $attribs );
127                 }
128
129                 if(strpos($url, 'http') !== 0) {
130                         $url =  JURI::root(true).'/'.$url;
131                 };
132
133                 return '<img src="'.$url.'" alt="'.$alt.'" '.$attribs.' />';
134         }
135
136         /**
137          * Write a <iframe></iframe> element
138          *
139          * @access      public
140          * @param       string  The relative URL to use for the src attribute
141          * @param       string  The target attribute to use
142          * @param       array   An associative array of attributes to add
143          * @param       string  The message to display if the iframe tag is not supported
144          * @since       1.5
145          */
146         public static function iframe( $url, $name, $attribs = null, $noFrames = '' )
147         {
148                 if (is_array( $attribs )) {
149                         $attribs = JArrayHelper::toString( $attribs );
150                 }
151
152                 return '<iframe src="'.$url.'" '.$attribs.' name="'.$name.'">'.$noFrames.'</iframe>';
153         }
154
155         /**
156          * Write a <script></script> element
157          *
158          * @access      public
159          * @param       string  The name of the script file
160          * * @param     string  The relative or absolute path of the script file
161          * @param       boolean If true, the mootools library will be loaded
162          * @since       1.5
163          */
164         public static function script($filename, $path = 'media/system/js/', $mootools = true)
165         {
166                 // Include mootools framework
167                 if($mootools) {
168                         JHTML::_('behavior.mootools');
169                 }
170
171                 if(strpos($path, 'http') !== 0) {
172                         $path =  JURI::root(true).'/'.$path;
173                 };
174
175                 $document = &JFactory::getDocument();
176                 $document->addScript( $path.$filename );
177                 return;
178         }
179
180         /**
181          * Write a <link rel="stylesheet" style="text/css" /> element
182          *
183          * @access      public
184          * @param       string  The relative URL to use for the href attribute
185          * @since       1.5
186          */
187         public static function stylesheet($filename, $path = 'media/system/css/', $attribs = array())
188         {
189                 if(strpos($path, 'http') !== 0) {
190                         $path =  JURI::root(true).'/'.$path;
191                 };
192
193                 $document = &JFactory::getDocument();
194                 $document->addStylesheet( $path.$filename, 'text/css', null, $attribs );
195                 return;
196         }
197
198         /**
199          * Returns formated date according to current local and adds time offset
200          *
201          * @access      public
202          * @param       string  date in an US English date format
203          * @param       string  format optional format for strftime
204          * @returns     string  formated date
205          * @see         strftime
206          * @since       1.5
207          */
208 /*      public static function date($date, $format = null, $offset = NULL)
209         {
210                 if ( ! $format ) {
211                         $format = JText::_('DATE_FORMAT_LC1');
212                 }
213                 if(is_null($offset))
214                 {
215                         $config =& JFactory::getConfig();
216                         $offset = $config->getValue('config.offset');
217                 }
218                 $instance =& JFactory::getDate($date);
219                 $instance->setOffset($offset);
220
221                 return $instance->toFormat($format);
222         }*/
223         /**
224          * Returns formated date according to a given format and time zone.
225          *
226          * @param   string   $input      String in a format accepted by date(), defaults to "now".
227          * @param   string   $format     The date format specification string (see {@link PHP_MANUAL#date})
228          * @param   mixed    $tz         Time zone to be used for the date.  Special cases: boolean true for user
229          *                               setting, boolean false for server setting.
230          * @param   boolean  $gregorian  True to use Gregorian calenar
231          *
232          * @return  string    A date translated by the given format and time zone.
233          *
234          * @see     strftime
235          * @since   11.1
236          */
237         public static function date($input = 'now', $format = null, $tz = true, $gregorian = false)
238         {
239                 // Get some system objects.
240 //              $config = JFactory::getConfig();
241 //              $user = JFactory::getUser();
242 /*
243                 // UTC date converted to user time zone.
244                 if ($tz === true)
245                 {
246                         // Get a date object based on UTC.
247                         $date = JFactory::getDate($input, 'UTC');
248
249                         // Set the correct time zone based on the user configuration.
250                         $date->setTimeZone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
251                 }
252                 // UTC date converted to server time zone.
253                 elseif ($tz === false)
254                 {
255                         // Get a date object based on UTC.
256                         $date = JFactory::getDate($input, 'UTC');
257
258                         // Set the correct time zone based on the server configuration.
259                         $date->setTimeZone(new DateTimeZone($config->get('offset')));
260                 }
261                 // No date conversion.
262                 elseif ($tz === null)
263                 {*/
264                         $date = JFactory::getDate($input);
265 /*              }
266                 // UTC date converted to given time zone.
267                 else
268                 {
269                         // Get a date object based on UTC.
270                         $date = JFactory::getDate($input, 'UTC');
271
272                         // Set the correct time zone based on the server configuration.
273                         $date->setTimeZone(new DateTimeZone($tz));
274                 }*/
275
276                 // If no format is given use the default locale based format.
277                 if (!$format)
278                 {
279                         $format = JText::_('DATE_FORMAT_LC1');
280                 }
281                 // $format is an existing language key
282                 elseif (JFactory::getLanguage()->hasKey($format))
283                 {
284                         $format = JText::_($format);
285                 }
286
287                 if ($gregorian)
288                 {
289                         return $date->format($format, true);
290                 }
291                 else
292                 {
293                         return $date->calendar($format, true);
294                 }
295         }
296
297         /**
298          * Creates a tooltip with an image as button
299          *
300          * @access      public
301          * @param       string  $tooltip The tip string
302          * @param       string  $title The title of the tooltip
303          * @param       string  $image The image for the tip, if no text is provided
304          * @param       string  $text The text for the tip
305          * @param       string  $href An URL that will be used to create the link
306          * @param       boolean depreciated
307          * @return      string
308          * @since       1.5
309          */
310         public static function tooltip($tooltip, $title='', $image='tooltip.png', $text='', $href='', $link=1)
311         {
312                 $tooltip        = addslashes(htmlspecialchars($tooltip));
313                 $title          = addslashes(htmlspecialchars($title));
314
315                 if ( !$text ) {
316                         $image  = JURI::root(true).'/includes/js/ThemeOffice/'. $image;
317                         $text   = '<img src="'. $image .'" border="0" alt="'. JText::_( 'Tooltip' ) .'"/>';
318                 } else {
319                         $text   = JText::_( $text, true );
320                 }
321
322                 if($title) {
323                         $title = $title.'::';
324                 }
325
326                 $style = 'style="text-decoration: none; color: #333;"';
327
328                 if ( $href ) {
329                         $href = JRoute::_( $href );
330                         $style = '';
331                         $tip = '<span class="editlinktip hasTip" title="'.$title.$tooltip.'" '. $style .'><a href="'. $href .'">'. $text .'</a></span>';
332                 } else {
333                         $tip = '<span class="editlinktip hasTip" title="'.$title.$tooltip.'" '. $style .'>'. $text .'</span>';
334                 }
335
336                 return $tip;
337         }
338
339         /**
340          * Displays a calendar control field
341          *
342          * @param       string  The date value
343          * @param       string  The name of the text field
344          * @param       string  The id of the text field
345          * @param       string  The date format
346          * @param       array   Additional html attributes
347          */
348         public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null)
349         {
350                 JHTML::_('behavior.calendar'); //load the calendar behavior
351
352                 if (is_array($attribs)) {
353                         $attribs = JArrayHelper::toString( $attribs );
354                 }
355                 $document =& JFactory::getDocument();
356                 $document->addScriptDeclaration('window.addEvent(\'domready\', function() {Calendar.setup({
357         inputField     :    "'.$id.'",     // id of the input field
358         ifFormat       :    "'.$format.'",      // format of the input field
359         button         :    "'.$id.'_img",  // trigger for the calendar (button ID)
360         align          :    "Tl",           // alignment (defaults to "Bl")
361         singleClick    :    true
362     });});');
363
364                 return '<input type="text" name="'.$name.'" id="'.$id.'" value="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" '.$attribs.' />'.
365                                  '<img class="calendar" src="'.JURI::root(true).'/templates/system/images/calendar.png" alt="calendar" id="'.$id.'_img" />';
366         }
367
368         /**
369          * Add a directory where JHTML should search for helpers. You may
370          * either pass a string or an array of directories.
371          *
372          * @access      public
373          * @param       string  A path to search.
374          * @return      array   An array with directory elements
375          * @since       1.5
376          */
377         public static function addIncludePath( $path='' )
378         {
379                 static $paths;
380
381                 if (!isset($paths)) {
382                         $paths = array( JPATH_LIBRARIES.DS.'joomla'.DS.'html'.DS.'html' );
383                 }
384
385                 // force path to array
386                 settype($path, 'array');
387
388                 // loop through the path directories
389 /*              foreach ($path as $dir)
390                 {
391                         if (!empty($dir) && !in_array($dir, $paths)) {
392                                 array_unshift($paths, JPath::clean( $dir ));
393                         }
394                 }*/
395
396                 return $paths;
397         }
398 }