Jelajahi Sumber

Rename Class, removing require_once

Julio Montoya 10 tahun lalu
induk
melakukan
f246e7278e

+ 2 - 2
main/inc/lib/formvalidator/Element/datepickerdate.php → main/inc/lib/formvalidator/Element/DatePickerDate.php

@@ -4,13 +4,13 @@
 /**
  * Form element to select a date and hour (with popup datepicker)
  */
-class HTML_QuickForm_datepickerdate extends HTML_QuickForm_date
+class DatePickerDate extends HTML_QuickForm_date
 {
 	/**
 	 * Constructor
      * @deprecated use class DatePicker
 	 */
-	public function HTML_QuickForm_datepickerdate($elementName = null, $elementLabel = null, $attributes = null)
+	public function DatePickerDate($elementName = null, $elementLabel = null, $attributes = null)
     {
 		global $myMinYear, $myMaxYear;
 		$js_form_name = $attributes['form_name'];

+ 2 - 2
main/inc/lib/formvalidator/Element/html_editor.php → main/inc/lib/formvalidator/Element/HtmlEditor.php

@@ -6,7 +6,7 @@ use \Chamilo\CoreBundle\Component\Editor\CkEditor\CkEditor;
 /**
  * A html editor field to use with QuickForm
  */
-class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
+class HtmlEditor extends HTML_QuickForm_textarea
 {
     /** @var \Chamilo\CoreBundle\Component\Editor\Editor */
     public $editor;
@@ -26,7 +26,7 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
      * @param array $config	Optional configuration settings for the online editor.
      * @return bool
      */
-    public function HTML_QuickForm_html_editor($name = null, $elementLabel = null, $attributes = null, $config = null)
+    public function HtmlEditor($name = null, $elementLabel = null, $attributes = null, $config = null)
     {
         if (empty($name)) {
             return false;

+ 2 - 2
main/inc/lib/formvalidator/Element/select_ajax.php → main/inc/lib/formvalidator/Element/SelectAjax.php

@@ -4,12 +4,12 @@
 /**
 * A drop down list with all languages to use with QuickForm
 */
-class HTML_QuickForm_Select_Ajax extends HTML_QuickForm_select
+class SelectAjax extends HTML_QuickForm_select
 {
     /**
      * Class constructor
      */
-    function HTML_QuickForm_Select_Ajax($elementName = null, $elementLabel = null, $options = null, $attributes = null)
+    function SelectAjax($elementName = null, $elementLabel = null, $options = null, $attributes = null)
     {
         parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes);
     }

+ 4 - 3
main/inc/lib/formvalidator/Element/select_language.php → main/inc/lib/formvalidator/Element/SelectLanguage.php

@@ -4,12 +4,13 @@
 /**
 * A dropdownlist with all languages to use with QuickForm
 */
-class HTML_QuickForm_Select_Language extends HTML_QuickForm_select
+class SelectLanguage extends HTML_QuickForm_select
 {
 	/**
 	 * Class constructor
 	 */
-	function HTML_QuickForm_Select_Language($elementName=null, $elementLabel=null, $options=null, $attributes=null){
+	function SelectLanguage($elementName=null, $elementLabel=null, $options=null, $attributes=null)
+	{
 		if (!isset($attributes['class'])) {
 			$attributes['class'] = 'chzn-select';
 		}
@@ -26,4 +27,4 @@ class HTML_QuickForm_Select_Language extends HTML_QuickForm_select
 			}
 		}
 	}
-}
+}

+ 0 - 99
main/inc/lib/formvalidator/Element/datepicker_old.php

@@ -1,99 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
- * Form element to select a date and hour (with popup datepicker)
- */
-class HTML_QuickForm_datepicker extends HTML_QuickForm_date
-{
-	/**
-	 * Constructor
-	 */
-	public function HTML_QuickForm_datepicker($elementName = null, $elementLabel = null, $attributes = null, $optionIncrement = null)
-	{
-		$js_form_name = api_get_unique_id();
-		HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
-
-		$this->_persistantFreeze = true;
-		$this->_appendName = true;
-		$this->_type = 'datepicker';
-		$popup_link = '<a href="javascript:openCalendar(\''.$js_form_name.'\',\''.$elementName.'\')">
-		<img src="'.api_get_path(WEB_IMG_PATH).'calendar_select.gif" style="vertical-align:middle;" alt="Select Date" /></a>';
-
-		$hour_minute_devider = get_lang("HourMinuteDivider");
-        $special_chars = array('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
-		foreach ($special_chars as $char) {
-			$popup_link = str_replace($char, "\\".$char, $popup_link);
-			$hour_minute_devider = str_replace($char, "\\".$char, $hour_minute_devider);
-		}
-		$lang_code = api_get_language_isocode();
-		// If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
-		if (!array_key_exists($lang_code,$this->_locale)) {
-			$this->_locale[$lang_code]['months_long'] = api_get_months_long();
-		}
-		$this->_options['format'] = 'dFY '.$popup_link.'   H '.$hour_minute_devider.' i';
-		$this->_options['minYear'] = date('Y')-5;
-		$this->_options['maxYear'] = date('Y')+10;
-		$this->_options['language'] = $lang_code;
-		if (isset($optionIncrement)) {
-            $this->_options['optionIncrement']['i'] = intval($optionIncrement);
-        }
-	}
-
-	/**
-	 * HTML code to display this datepicker
-	 */
-	public function toHtml()
-	{
-		$js = $this->getElementJS();
-		return $js.parent :: toHtml();
-	}
-
-	/**
-	 * Get the necessary javascript for this datepicker
-	 */
-	function getElementJS()
-	{
-		$js = '';
-		if (!defined('DATEPICKER_JAVASCRIPT_INCLUDED')) {
-			define('DATEPICKER_JAVASCRIPT_INCLUDED', 1);
-			$js = "\n";
-			$js .= '<script src="';
-			$js .= api_get_path(WEB_CODE_PATH).'inc/lib/formvalidator/Element/';
-			$js .= 'tbl_change.js.php" type="text/javascript"></script>';
-			$js .= "\n";
-		}
-		return $js;
-	}
-
-	/**
-	 * Export the date value in MySQL format
-     * @param array
-     * @param bool
-	 * @return string YYYY-MM-DD HH:II:SS
-	 */
-	function exportValue(&$submitValues, $assoc = false)
-	{
-		$values = parent::getValue();
-		$y = $values['Y'][0];
-		$m = $values['F'][0];
-		$d = $values['d'][0];
-		$h = $values['H'][0];
-		$i = $values['i'][0];
-		$m = $m < 10 ? '0'.$m : $m;
-		$d = $d < 10 ? '0'.$d : $d;
-		$h = $h < 10 ? '0'.$h : $h;
-		$i = $i < 10 ? '0'.$i : $i;
-		$datetime = $y.'-'.$m.'-'.$d.' '.$h.':'.$i.':00';
-		$result[$this->getName()]= $datetime;
-		return $result;
-	}
-
-    /**
-	 * Sets an option to a value
-	 */
-	function setLocalOption($name,$value)
-	{
-		$this->_options[$name] = $value;
-	}
-}

+ 3 - 2
main/inc/lib/formvalidator/Element/style_button.php

@@ -30,7 +30,7 @@
  * @author      Hans De Bisschop <hans.de.bisschop@ehb.be>
  * @abstract
  */
-class HTML_QuickForm_stylebutton extends HTML_QuickForm_element
+class HTML_QuickForm_style_button extends HTML_QuickForm_element
 {
     // {{{ constructor
     /**
@@ -43,7 +43,8 @@ class HTML_QuickForm_stylebutton extends HTML_QuickForm_element
      * @access    public
      * @return    void
      */
-    function HTML_QuickForm_stylebutton($elementName=null, $elementLabel=null, $attributes=null) {
+    function HTML_QuickForm_style_button($elementName=null, $elementLabel=null, $attributes=null)
+    {
         $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
 
     } //end constructor

+ 2 - 2
main/inc/lib/formvalidator/Element/style_reset_button.php

@@ -32,7 +32,7 @@
  * @version     Release: 3.2.10
  * @since       1.0
  */
-class HTML_QuickForm_styleresetbutton extends HTML_QuickForm_stylebutton
+class HTML_QuickForm_styleresetbutton extends HTML_QuickForm_style_button
 {
     // {{{ constructor
 
@@ -48,7 +48,7 @@ class HTML_QuickForm_styleresetbutton extends HTML_QuickForm_stylebutton
      */
     function HTML_QuickForm_styleresetbutton($elementName=null, $value=null, $attributes=null)
     {
-        HTML_QuickForm_stylebutton::HTML_QuickForm_stylebutton($elementName, null, $attributes, $value);
+        HTML_QuickForm_style_button::HTML_QuickForm_style_button($elementName, null, $attributes, $value);
         $this->setValue($value);
         $this->setType('reset');
     } //end constructor

+ 6 - 6
main/inc/lib/formvalidator/Element/style_submit_button.php

@@ -32,7 +32,7 @@
  * @version     Release: 3.2.10
  * @since       1.0
  */
-class HTML_QuickForm_stylesubmitbutton extends HTML_QuickForm_stylebutton
+class HTML_QuickForm_style_submit_button extends HTML_QuickForm_style_button
 {
     // {{{ constructor
 
@@ -46,17 +46,17 @@ class HTML_QuickForm_stylesubmitbutton extends HTML_QuickForm_stylebutton
      * @access    public
      * @return    void
      */
-    function HTML_QuickForm_stylesubmitbutton($elementName = null, $value = null, $attributes = null, $img = null) {
+    function HTML_QuickForm_style_submit_button($elementName = null, $value = null, $attributes = null, $img = null) {
         if (empty($attributes)) {
             $attributes = array();
         }
-        
+
         if (!isset($attributes['class'])) {
             if (is_array($attributes)) {
                 $attributes['class'] = 'btn';
-            }            
+            }
         }
-        HTML_QuickForm_stylebutton::HTML_QuickForm_stylebutton($elementName, null, $attributes, $value, $img);
+        HTML_QuickForm_style_button::HTML_QuickForm_style_button($elementName, null, $attributes, $value, $img);
         $this->setValue($value);
         $this->setType('submit');
     } //end constructor
@@ -82,4 +82,4 @@ class HTML_QuickForm_stylesubmitbutton extends HTML_QuickForm_stylebutton
         return $this->_prepareValue($this->_findValue($submitValues), $assoc);
     }
     // }}}
-} //end class HTML_QuickForm_submit
+} //end class HTML_QuickForm_submit

+ 12 - 53
main/inc/lib/pear/HTML/QuickForm.php

@@ -23,45 +23,6 @@
  * @link        http://pear.php.net/package/HTML_QuickForm
  */
 
-/**
- * PEAR and PEAR_Error classes, for error handling
- */
-require_once 'PEAR.php';
-
-/**
- * Element types known to HTML_QuickForm
- * @see HTML_QuickForm::registerElementType(), HTML_QuickForm::getRegisteredTypes(),
- *      HTML_QuickForm::isTypeRegistered()
- * @global array $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
- */
-$GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
-    'group'             => array('HTML/QuickForm/group.php','HTML_QuickForm_group'),
-    'hidden'            => array('HTML/QuickForm/hidden.php','HTML_QuickForm_hidden'),
-    'reset'             => array('HTML/QuickForm/reset.php','HTML_QuickForm_reset'),
-    'checkbox'          => array('HTML/QuickForm/checkbox.php','HTML_QuickForm_checkbox'),
-    'file'              => array('HTML/QuickForm/file.php','HTML_QuickForm_file'),
-    'image'             => array('HTML/QuickForm/image.php','HTML_QuickForm_image'),
-    'password'          => array('HTML/QuickForm/password.php','HTML_QuickForm_password'),
-    'radio'             => array('HTML/QuickForm/radio.php','HTML_QuickForm_radio'),
-    'button'            => array('HTML/QuickForm/button.php','HTML_QuickForm_button'),
-    'submit'            => array('HTML/QuickForm/submit.php','HTML_QuickForm_submit'),
-    'select'            => array('HTML/QuickForm/select.php','HTML_QuickForm_select'),
-    'hiddenselect'      => array('HTML/QuickForm/hiddenselect.php','HTML_QuickForm_hiddenselect'),
-    'text'              => array('HTML/QuickForm/text.php','HTML_QuickForm_text'),
-    'textarea'          => array('HTML/QuickForm/textarea.php','HTML_QuickForm_textarea'),
-    'link'              => array('HTML/QuickForm/link.php','HTML_QuickForm_link'),
-    'advcheckbox'       => array('HTML/QuickForm/advcheckbox.php','HTML_QuickForm_advcheckbox'),
-    'date'              => array('HTML/QuickForm/date.php','HTML_QuickForm_date'),
-    'static'            => array('HTML/QuickForm/static.php','HTML_QuickForm_static'),
-    'header'            => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'),
-    'html'              => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'),
-    'hierselect'        => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'),
-    'autocomplete'      => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'),
-    'xbutton'           => array('HTML/QuickForm/xbutton.php','HTML_QuickForm_xbutton'),
-    'advanced_settings' => array('HTML/QuickForm/advanced_settings.php','HTML_QuickForm_advanced_settings'),
-    'label'             => array('HTML/QuickForm/label.php','HTML_QuickForm_label'),
-    'email'             => array('HTML/QuickForm/email.php','HTML_QuickForm_email')
-);
 
 /**
  * Validation rules known to HTML_QuickForm
@@ -394,9 +355,8 @@ class HTML_QuickForm extends HTML_Common
      * @access    public
      * @return    void
      */
-    function registerRule($ruleName, $type, $data1, $data2 = null)
+    public static function registerRule($ruleName, $type, $data1, $data2 = null)
     {
-        include_once('HTML/QuickForm/RuleRegistry.php');
         $registry =& HTML_QuickForm_RuleRegistry::singleton();
         $registry->registerRule($ruleName, $type, $data1, $data2);
     } // end func registerRule
@@ -601,19 +561,18 @@ class HTML_QuickForm extends HTML_Common
      * @return    HTML_QuickForm_Element
      * @throws    HTML_QuickForm_Error
      */
-    function &_loadElement($event, $type, $args)
+    public function &_loadElement($event, $type, $args)
     {
-        $type = strtolower($type);
-        if (!HTML_QuickForm::isTypeRegistered($type)) {
-            $error = PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, "Element '$type' does not exist in HTML_QuickForm::_loadElement()", 'HTML_QuickForm_Error', true);
-            return $error;
+        $lowerType = strtolower($type);
+        $className = 'HTML_QuickForm_'.$lowerType;
+        // Try classic class name HTML_QuickForm_
+        if (!class_exists($className)) {
+            // Try new class name CamelCase
+            $className = underScoreToCamelCase($type);
+            if (!class_exists($className)) {
+                throw new \Exception("Class '$className' does not exist. ");
+            }
         }
-        $className = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][1];
-        $includeFile = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][0];
-
-        include_once $includeFile;
-        // Modified by Ivan Tcholakov, 16-MAR-2010. Suppressing a deprecation warning on PHP 5.3
-        //$elementObject =& new $className();
         $elementObject = new $className();
 
         for ($i = 0; $i < 5; $i++) {
@@ -626,7 +585,7 @@ class HTML_QuickForm extends HTML_Common
             return $err;
         }
         return $elementObject;
-    } // end func _loadElement
+    }
 
     // }}}
     // {{{ addElement()

+ 0 - 11
main/inc/lib/pear/HTML/QuickForm/CAPTCHA/Equation.php

@@ -74,14 +74,3 @@ class HTML_QuickForm_CAPTCHA_Equation extends HTML_QuickForm_CAPTCHA
      */
     var $_CAPTCHA_driver = 'Equation';
 }
-
-/**
- * Registers the class with QuickForm
- */
-if (class_exists('HTML_QuickForm')) {
-    HTML_QuickForm::registerElementType('CAPTCHA_Equation',
-            'HTML/QuickForm/CAPTCHA/Equation.php',
-            'HTML_QuickForm_CAPTCHA_Equation');
-}
-
-?>

+ 0 - 11
main/inc/lib/pear/HTML/QuickForm/CAPTCHA/Figlet.php

@@ -107,14 +107,3 @@ class HTML_QuickForm_CAPTCHA_Figlet extends HTML_QuickForm_CAPTCHA
         return $html;
     }
 }
-
-/**
- * Registers the class with QuickForm
- */
-if (class_exists('HTML_QuickForm')) {
-    HTML_QuickForm::registerElementType('CAPTCHA_Figlet',
-            'HTML/QuickForm/CAPTCHA/Figlet.php',
-            'HTML_QuickForm_CAPTCHA_Figlet');
-}
-
-?>

+ 0 - 10
main/inc/lib/pear/HTML/QuickForm/CAPTCHA/Word.php

@@ -72,13 +72,3 @@ class HTML_QuickForm_CAPTCHA_Word extends HTML_QuickForm_CAPTCHA
      */
     var $_CAPTCHA_driver = 'Word';
 }
-
-/**
- * Registers the class with QuickForm
- */
-if (class_exists('HTML_QuickForm')) {
-    HTML_QuickForm::registerElementType('CAPTCHA_Word',
-            'HTML/QuickForm/CAPTCHA/Word.php', 'HTML_QuickForm_CAPTCHA_Word');
-}
-
-?>

+ 6 - 11
main/inc/lib/pear/HTML/QuickForm/advmultiselect.php

@@ -1015,21 +1015,21 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
     {
         $js = '@data_dir@' . DIRECTORY_SEPARATOR
             . '@package_name@' . DIRECTORY_SEPARATOR;
-        
-        $js = api_get_path(LIBRARY_PATH).'javascript'.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR; 
-		
+
+        $js = api_get_path(LIBRARY_PATH).'javascript'.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR;
+
         if ($min) {
             $js .= 'qfamsHandler-min.js';
         } else {
             $js .= 'qfamsHandler.js';
         }
 
-        if (file_exists($js)) {        	
-            $js = file_get_contents($js);            
+        if (file_exists($js)) {
+            $js = file_get_contents($js);
         } else {
             $js = '';
         }
-		
+
         if ($raw !== true) {
             $js = '<script type="text/javascript">'
                 . PHP_EOL . '//<![CDATA['
@@ -1175,8 +1175,3 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
         return $options;
     }
 }
-
-// @todo this fires an PHP notice, needed in order to parse the advmultiselect test it in main/group/group_edit.php
-if (class_exists('HTML_QuickForm')) {    
-    @HTML_QuickForm::registerElementType('advmultiselect','HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect');
-}

+ 16 - 0
main/inc/lib/text.lib.php

@@ -786,3 +786,19 @@ function bracketsToArray($array)
 {
     return preg_split('/[\[\]]+/', $array, -1, PREG_SPLIT_NO_EMPTY);
 }
+
+/**
+ * @param string $string
+ * @param bool $capitalizeFirstCharacter
+ * @return mixed
+ */
+function underScoreToCamelCase($string, $capitalizeFirstCharacter = true)
+{
+    $str = str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
+
+    if (!$capitalizeFirstCharacter) {
+        $str[0] = strtolower($str[0]);
+    }
+
+    return $str;
+}