AAAAhome/academiac/www/administrator/components/com_virtuemart/helpers/parameterparser.php000060400000044203151372177330025674 0ustar00 basename($filename, '.php'), 'fileName' => $filename); } return JHTML::_('select.genericlist', $list, 'file', '', 'file', 'fileName', $preselected); } /** * Function to strip additional / or \ in a path name * @param string The path * @param boolean Add trailing slash */ function vmPathName($p_path, $p_addtrailingslash = true) { $retval = ""; $isWin = (substr(PHP_OS, 0, 3) == 'WIN'); if ($isWin) { $retval = str_replace('/', '\\', $p_path); if ($p_addtrailingslash) { if (substr($retval, -1) != '\\') { $retval .= '\\'; } } // Check if UNC path $unc = substr($retval, 0, 2) == '\\\\' ? 1 : 0; // Remove double \\ $retval = str_replace('\\\\', '\\', $retval); // If UNC path, we have to add one \ in front or everything breaks! if ($unc == 1) { $retval = '\\' . $retval; } } else { $retval = str_replace('\\', '/', $p_path); if ($p_addtrailingslash) { if (substr($retval, -1) != '/') { $retval .= '/'; } } // Check if UNC path $unc = substr($retval, 0, 2) == '//' ? 1 : 0; // Remove double // $retval = str_replace('//', '/', $retval); // If UNC path, we have to add one / in front or everything breaks! if ($unc == 1) { $retval = '/' . $retval; } } return $retval; } /** * Utility function to read the files in a directory * @param string The file system path * @param string A filter for the names * @param boolean Recurse search into sub-directories * @param boolean True if to prepend the full path to the file name */ function vmReadDirectory($path, $filter='.', $recurse=false, $fullpath=false) { $arr = array(); if (!@is_dir($path)) { return $arr; } $handle = opendir($path); while ($file = readdir($handle)) { $dir = self::vmPathName($path . '/' . $file, false); $isDir = is_dir($dir); if (($file != ".") && ($file != "..")) { if (preg_match("/$filter/", $file)) { if ($fullpath) { $arr[] = trim(self::vmPathName($path . '/' . $file, false)); } else { $arr[] = trim($file); } } if ($recurse && $isDir) { $arr2 = self::vmReadDirectory($dir, $filter, $recurse, $fullpath); $arr = array_merge($arr, $arr2); } } } closedir($handle); asort($arr); return $arr; } } if(!class_exists('JParameter')) require(JPATH_VM_LIBRARIES.DS.'joomla'.DS.'html'.DS.'parameter.php' ); class vmParameters extends JParameter { // /** @var string Path to the xml setup file */ var $_path = null; // /** @var string The type of setup file */ var $_type = null; var $_group = '_default'; /** * Constructor * * @access protected * @param string The raw parms text * @param string payment_element payment element name * @since 1.5 */ function __construct($data, $element = '', $type='component', $pluginfolder ) { $lang = JFactory::getLanguage(); $lang->load('plg_'.$pluginfolder.'_' . $element,JPATH_ADMINISTRATOR); if (JVM_VERSION === 2) { $path = JPATH_PLUGINS . DS . $pluginfolder . DS . basename($element). DS . basename($element) . '.xml'; } else { $path = JPATH_PLUGINS . DS . $pluginfolder . DS . basename($element) . '.xml'; } parent::__construct($element, $path); $this->_type = $type; if (JVM_VERSION === 2) { } else { } // $this->_raw = $data; $this->bind($data); } /** * render * * @access public * @param string The name of the control, or the default text area if a setup file is not found * @return string HTML * @author Valérie Cartan Isaksen */ function render($name = 'params', $group = '_default') { // vmdebug('render',$this); // if (JVM_VERSION === 2) { $parameters = $this->vmRender($name, $group); // } else { // $parameters = parent::render($name, $group); // } return $parameters; } /** * Render all parameters copied from Joomla 1.5 * * @access public * @param string The name of the control, or the default text area if a setup file is not found * @return array Aarray of all parameters, each as array Any array of the label, the form element and the tooltip * @since 1.5 */ function getParam(&$node, $control_name = 'params', $group = '_default') { //get the type of the parameter $type = $node->attributes('type'); //remove any occurance of a mos_ prefix $type = str_replace('mos_', '', $type); $element = $this->loadElement($type); // error happened if ($element === false) { $result = array(); $result[0] = $node->attributes('name'); $result[1] = JText::_('Element not defined for type').' = '.$type; $result[5] = $result[0]; return $result; } //get value $value = $this->get($node->attributes('name'), $node->attributes('default'), $group); return $element->render($node, $value, $control_name); } function getParamByName($name){ return $this->$name; } /** * vmRender copied from Joomla 1.5 * * @access public * @param string The name of the control, or the default text area if a setup file is not found * @return string HTML * @author Joomla 1.5 */ function vmRender($name = 'params', $group = '_default') { if (!isset($this->_xml[$group])) { return false; } $params = $this->getParams($name, $group); // vmdebug('vmRender',$params); $html = array (); $html[] = ''; if ($description = $this->_xml[$group]->attributes('description')) { // add the params description to the display $desc = JText::_($description); $html[] = ''; } foreach ($params as $param) { $html[] = ''; if ($param[0]) { $html[] = ''; $html[] = ''; } else { $html[] = ''; } $html[] = ''; } if (count($params) < 1) { $html[] = ""; } $html[] = '
'.$desc.'
'.$param[0].''.$param[1].''.$param[1].'
".JText::_('There are no Parameters for this item')."
'; return implode("\n", $html); } /** * * @author Sören, Max Milbers * @param object A param tag node * @param string The control name * @return array Any array of the label, the form element and the tooltip */ function renderParam(&$param, $control_name='params') { $result = array(); $name = $param->attributes('name'); $type = $param->attributes('type'); if ($param->attributes('label') != '') { $label = JText::_($param->attributes('label')); } else { $label = ''; } if ($param->attributes('description')) { $description = JText::_($param->attributes('description')); } else { //$description = JText::_('COM_VIRTUEMART_NO_DESCRIPTION_FOUND'); } $result[0] = $label ? $label : $name; if ($type == 'spacer' || $type == 'checkbox') { $result[0] = ' '; } else { // $result[0] = JHTML::tooltip( addslashes( $description ), addslashes( $result[0] ), '', '', $result[0], '#', 0 ); //$result[0] = $description; } if (in_array('_form_' . $type, $this->_methods)) { $control_name = ''; $value = $this->get($name); // $value = $this->get($param->attributes('name'), $param->attributes('default')); $result[1] = call_user_func(array($this, '_form_' . $type), $name, $value, $param, $control_name, $label); } else { $result[1] = _HANDLER . ' = ' . $type; } if ($description) { $result[2] = JHTML::tooltip($description, $result[0], '', $result[0]); //$result[2] = JHTML::tooltip( $description); // $result[2] = $description; } else { $result[2] = ''; } return $result; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_text($name, $value, &$node, $control_name) { $size = $node->attributes('size'); if ((int) $size == 0) { $size = 25; } return ''; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_password($name, $value, &$node, $control_name) { $size = $node->attributes('size'); if ((int) $size == 0) { $size = 25; } return ''; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_checkbox($name, $value, &$node, $control_name, $label='') { $default = $node->attributes('default'); $checked = ''; if ($value == $default) { $checked = ' checked="checked"'; } $id = uniqid($name); return ' '; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_list($name, $value, &$node, $control_name) { $size = $node->attributes('size'); $multiselect = $node->attributes('multiselect'); if ($multiselect) { $multiselect = 'multiple="multiple"'; $size = 5; $name .= ']['; // well, if it's multi-select, this must be an array, right? if (strstr($value, ',')) { $value = explode(',', $value); } } if ($size == 0) $size = 1; $options = array(); foreach ($node->_children as $option) { $val = $option->attributes('value'); $text = trim($option->data()); $options[$val] = JText::_($text); } return VmHTML::selectList($control_name . '[' . $name . ']', $value, $options, $size, $multiselect); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_radio($name, $value, &$node, $control_name) { $options = array(); foreach ($node->_children as $option) { $val = $option->attributes('value'); $text = trim($option->data()); $options[$val] = JText::_($text); } return VmHTML::radioList($control_name . '[' . $name . ']', $value, $options); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_table_data_list($name, $value, &$node, $control_name) { $db = JFactory::getDBO(); $table = $node->attributes('table'); $condition = $node->attributes('sql_condition'); $valuefield = $node->attributes('valuefield'); $textfield = $node->attributes('textfield'); $orderfield = $node->attributes('orderfield'); $sorting = strtoupper($node->attributes('sorting')) == 'DESC' ? 'DESC' : 'ASC'; $multiselect = $node->attributes('multiselect'); $query = "SELECT `" . $db->getEscaped($valuefield) . '`, `' . $db->getEscaped($textfield) . "`" . "\n FROM `" . $db->getEscaped($table) . "`"; if ($condition != '') { $query .= "\n WHERE " . $condition; } if ($orderfield) { $query .= "\n ORDER BY `" . $db->getEscaped($orderfield) . "` " . $sorting; } $db->setQuery($query); $array = $db->loadResultArray(); if ($multiselect == '1') { $multiple = 'multiple="multiple"'; $size = 5; } else { $multiple = ''; $size = 1; } $name = $control_name . '[' . $name . ']'; return VmHTML::selectList($name, $value, $array, $size, $multiple, 'class="inputbox"'); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ // function _form_vm_category( $name, $value, &$node, $control_name ) { // global $database; // // $multiselect = $node->_attributes( 'multiselect' ); // if( $multiselect == '1' ) { // $multiple = true; // $size = 5; // } else { // $multiple = false; // $size = 1; // } // require( CLASSPATH.'ps_product_category.php'); // $ps_product_category = new ps_product_category(); // // ob_start(); // $ps_product_category->list_all(''. $control_name .'['. $name .']', 0, array(), $size, true, $multiple ); // $category_dropdown = ob_get_clean(); // return $category_dropdown; // } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_filelist($name, $value, &$node, $control_name) { // path to images directory $path = JPATH_SITE . $node->attributes('directory'); $filter = $node->attributes('filter'); $files = vmReadDirectory($path, $filter); $options = array(); foreach ($files as $file) { $options[$file] = $file; } if (!$node->attributes('hide_none')) { array_unshift($options, array('-1', '- ' . 'Do Not Use' . ' -')); } if (!$node->attributes('hide_default')) { array_unshift($options, array('', '- ' . 'Use Default' . ' -')); } return VmHTML::selectList('' . $control_name . '[' . $name . ']', $value, $options, 1, '', 'class="inputbox"'); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_imagelist($name, $value, &$node, $control_name) { $node->addAttribute('filter', '\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$'); return $this->_form_filelist($name, $value, $node, $control_name); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_textarea($name, $value, &$node, $control_name) { $rows = $node->attributes('rows'); $cols = $node->attributes('cols'); // convert
tags so they are not visible when editing $value = str_replace('
', "\n", $value); return ''; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_hidden($name, $value, &$node, $control_name) { return ''; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_spacer($name, $value, &$node, $control_name) { if ($value) { return '

' . JText::_($value) . '

'; } else { return '
'; } } /** * special handling for textarea param */ function textareaHandling(&$txt) { $total = count($txt); for ($i = 0; $i < $total; $i++) { if (strstr($txt[$i], "\n")) { $txt[$i] = str_replace("\n", '
', $txt[$i]); } } $txt = implode("\n", $txt); return $txt; } /** * Element name * * @access protected * @var string */ var $_name = 'SQL'; function _form_sql($name, $value, &$node, $control_name) { $db = JFactory::getDBO(); $db->setQuery($node->attributes('query')); $key = ($node->attributes('key_field') ? $node->attributes('key_field') : 'value'); $val = ($node->attributes('value_field') ? $node->attributes('value_field') : $name); return JHTML::_('select.genericlist', $db->loadObjectList(), '' . $control_name . '[' . $name . ']', 'class="inputbox"', $key, $val, $value, $control_name . $name); } } /** * @param string * @return string */ function vmParseParams($txt) { return vmParameters::parse($txt); } // pure php no closing tag